Skip to content

Commit

Permalink
[Merge] main <- wonjeong#49-add-additional-group-api-function
Browse files Browse the repository at this point in the history
[Feat] 기수별 조회 기능과 전체 기수 목록 조회 기능, 전체 파트 조회기능을 추가합니다.
  • Loading branch information
NARUBROWN authored Feb 10, 2024
2 parents f375fdc + dd5c444 commit f265275
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import org.springframework.web.bind.annotation.*;
import server.inuappcenter.kr.common.data.dto.CommonResponseDto;
import server.inuappcenter.kr.data.dto.request.GroupRequestDto;
import server.inuappcenter.kr.data.dto.response.GroupPartListResponseDto;
import server.inuappcenter.kr.data.dto.response.GroupResponseDto;
import server.inuappcenter.kr.data.dto.response.GroupYearListResponseDto;
import server.inuappcenter.kr.service.GroupService;

import javax.validation.Valid;
Expand Down Expand Up @@ -72,4 +74,23 @@ public ResponseEntity<List<GroupResponseDto>> searchByMemberName(final @PathVari
return ResponseEntity.status(HttpStatus.OK).body(groupService.searchByMemberName(name));
}

@Operation(summary = "전체 기수 목록 가져오기", description = "서버에 등록된 기수 목록을 가져옵니다.")
@GetMapping("/all-groups-years")
public ResponseEntity<GroupYearListResponseDto> findAllYears() {
return ResponseEntity.status(HttpStatus.OK).body(groupService.findAllYears());
}

@Operation(summary = "기수별 그룹 목록 가져오기", description = "기수와 파트 이름을 통해 기수별 그룹 목록을 가져옵니다.")
@GetMapping("/groups-by-year")
public ResponseEntity<List<GroupResponseDto>> findAllByYear(final @Parameter Double year,
final @Parameter String part) {
return ResponseEntity.status(HttpStatus.OK).body(groupService.findAllByYearAndPart(year, part));
}

@Operation(summary = "전체 파트 목록 가져오기", description = "서버에 등록된 파트 목록을 가져옵니다.")
@GetMapping("/all-parts")
public ResponseEntity<GroupPartListResponseDto> findAllParts() {
return ResponseEntity.status(HttpStatus.OK).body(groupService.findAllParts());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class GroupRequestDto {

@Schema(
example = "서버",
example = "Server",
description = "서버, 안드로이드, iOS등... 파트 중 하나"
)
@NotBlank(message = "파트가 비어있을 수 없습니다.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package server.inuappcenter.kr.data.dto.response;

import lombok.Getter;

import java.util.List;

@Getter
public class GroupPartListResponseDto {
private final List<String> parts;

public GroupPartListResponseDto(List<String> parts) {
this.parts = parts;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package server.inuappcenter.kr.data.dto.response;


import lombok.Getter;

import java.util.List;

@Getter
public class GroupYearListResponseDto {
private final List<Double> yearList;

public GroupYearListResponseDto(List<Double> yearList) {
this.yearList = yearList;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server.inuappcenter.kr.data.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import server.inuappcenter.kr.data.domain.Group;
import server.inuappcenter.kr.data.domain.Member;
Expand All @@ -16,4 +17,12 @@ public interface GroupRepository extends JpaRepository<Group, Long> {

List<Group> findAllByMember_Name(String name);

@Query("SELECT DISTINCT e.year FROM Group e")
List<Double> findAllYears();

List<Group> findAllByYearAndPart(Double year, String Part);

@Query("SELECT DISTINCT e.part FROM Group e")
List<String> findAllParts();

}
26 changes: 25 additions & 1 deletion src/main/java/server/inuappcenter/kr/service/GroupService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import server.inuappcenter.kr.data.domain.Member;
import server.inuappcenter.kr.data.domain.Role;
import server.inuappcenter.kr.data.dto.request.GroupRequestDto;
import server.inuappcenter.kr.data.dto.response.GroupPartListResponseDto;
import server.inuappcenter.kr.data.dto.response.GroupResponseDto;
import server.inuappcenter.kr.data.dto.response.GroupYearListResponseDto;
import server.inuappcenter.kr.data.repository.GroupRepository;
import server.inuappcenter.kr.data.repository.MemberRepository;
import server.inuappcenter.kr.data.repository.RoleRepository;
Expand Down Expand Up @@ -57,21 +59,43 @@ public GroupResponseDto updateGroup(GroupRequestDto groupRequestDto, Long id) {
return GroupResponseDto.entityToDto(savedGroup);
}


@Transactional
public CommonResponseDto deleteGroup(Long id) {
groupRepository.deleteById(id);
return new CommonResponseDto("id: " + id + " has been successfully deleted.");
}

@Transactional
public CommonResponseDto deleteMultipleGroups(List<Long> id) {
groupRepository.deleteAllByIdInBatch(id);
return new CommonResponseDto("id: " + id + " have been successfully deleted.");
}

@Transactional(readOnly = true)
public List<GroupResponseDto> searchByMemberName(String name) {
List<Group> foundGroups = groupRepository.findAllByMember_Name(name);
return foundGroups.stream()
.map(data -> data.toGroupResponseDto(data))
.collect(Collectors.toList());
}

@Transactional(readOnly = true)
public GroupYearListResponseDto findAllYears() {
List<Double> foundYears = groupRepository.findAllYears();
return new GroupYearListResponseDto(foundYears);
}

@Transactional(readOnly = true)
public List<GroupResponseDto> findAllByYearAndPart(Double year, String part) {
List<Group> foundGroups = groupRepository.findAllByYearAndPart(year, part);
return foundGroups.stream()
.map(data -> data.toGroupResponseDto(data))
.collect(Collectors.toList());
}

@Transactional(readOnly = true)
public GroupPartListResponseDto findAllParts() {
List<String> foundParts = groupRepository.findAllParts();
return new GroupPartListResponseDto(foundParts);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spring:
password: test1234
jpa:
hibernate:
ddl-auto: create
ddl-auto: none
show-sql: true
open-in-view: false
properties:
Expand Down

0 comments on commit f265275

Please sign in to comment.