diff --git a/src/main/java/server/inuappcenter/kr/controller/GroupController.java b/src/main/java/server/inuappcenter/kr/controller/GroupController.java index 4810d71..2e3ed64 100644 --- a/src/main/java/server/inuappcenter/kr/controller/GroupController.java +++ b/src/main/java/server/inuappcenter/kr/controller/GroupController.java @@ -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; @@ -72,4 +74,23 @@ public ResponseEntity> searchByMemberName(final @PathVari return ResponseEntity.status(HttpStatus.OK).body(groupService.searchByMemberName(name)); } + @Operation(summary = "전체 기수 목록 가져오기", description = "서버에 등록된 기수 목록을 가져옵니다.") + @GetMapping("/all-groups-years") + public ResponseEntity findAllYears() { + return ResponseEntity.status(HttpStatus.OK).body(groupService.findAllYears()); + } + + @Operation(summary = "기수별 그룹 목록 가져오기", description = "기수와 파트 이름을 통해 기수별 그룹 목록을 가져옵니다.") + @GetMapping("/groups-by-year") + public ResponseEntity> 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 findAllParts() { + return ResponseEntity.status(HttpStatus.OK).body(groupService.findAllParts()); + } + } diff --git a/src/main/java/server/inuappcenter/kr/data/dto/request/GroupRequestDto.java b/src/main/java/server/inuappcenter/kr/data/dto/request/GroupRequestDto.java index 2ce5e0b..92b7322 100644 --- a/src/main/java/server/inuappcenter/kr/data/dto/request/GroupRequestDto.java +++ b/src/main/java/server/inuappcenter/kr/data/dto/request/GroupRequestDto.java @@ -15,7 +15,7 @@ public class GroupRequestDto { @Schema( - example = "서버", + example = "Server", description = "서버, 안드로이드, iOS등... 파트 중 하나" ) @NotBlank(message = "파트가 비어있을 수 없습니다.") diff --git a/src/main/java/server/inuappcenter/kr/data/dto/response/GroupPartListResponseDto.java b/src/main/java/server/inuappcenter/kr/data/dto/response/GroupPartListResponseDto.java new file mode 100644 index 0000000..0c15889 --- /dev/null +++ b/src/main/java/server/inuappcenter/kr/data/dto/response/GroupPartListResponseDto.java @@ -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 parts; + + public GroupPartListResponseDto(List parts) { + this.parts = parts; + } +} diff --git a/src/main/java/server/inuappcenter/kr/data/dto/response/GroupYearListResponseDto.java b/src/main/java/server/inuappcenter/kr/data/dto/response/GroupYearListResponseDto.java new file mode 100644 index 0000000..b5d2fc3 --- /dev/null +++ b/src/main/java/server/inuappcenter/kr/data/dto/response/GroupYearListResponseDto.java @@ -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 yearList; + + public GroupYearListResponseDto(List yearList) { + this.yearList = yearList; + } +} diff --git a/src/main/java/server/inuappcenter/kr/data/repository/GroupRepository.java b/src/main/java/server/inuappcenter/kr/data/repository/GroupRepository.java index b2523f7..579a116 100644 --- a/src/main/java/server/inuappcenter/kr/data/repository/GroupRepository.java +++ b/src/main/java/server/inuappcenter/kr/data/repository/GroupRepository.java @@ -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; @@ -16,4 +17,12 @@ public interface GroupRepository extends JpaRepository { List findAllByMember_Name(String name); + @Query("SELECT DISTINCT e.year FROM Group e") + List findAllYears(); + + List findAllByYearAndPart(Double year, String Part); + + @Query("SELECT DISTINCT e.part FROM Group e") + List findAllParts(); + } diff --git a/src/main/java/server/inuappcenter/kr/service/GroupService.java b/src/main/java/server/inuappcenter/kr/service/GroupService.java index 55eb1a5..0fc6a0f 100644 --- a/src/main/java/server/inuappcenter/kr/service/GroupService.java +++ b/src/main/java/server/inuappcenter/kr/service/GroupService.java @@ -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; @@ -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 id) { groupRepository.deleteAllByIdInBatch(id); return new CommonResponseDto("id: " + id + " have been successfully deleted."); } + @Transactional(readOnly = true) public List searchByMemberName(String name) { List foundGroups = groupRepository.findAllByMember_Name(name); return foundGroups.stream() .map(data -> data.toGroupResponseDto(data)) .collect(Collectors.toList()); } + + @Transactional(readOnly = true) + public GroupYearListResponseDto findAllYears() { + List foundYears = groupRepository.findAllYears(); + return new GroupYearListResponseDto(foundYears); + } + + @Transactional(readOnly = true) + public List findAllByYearAndPart(Double year, String part) { + List foundGroups = groupRepository.findAllByYearAndPart(year, part); + return foundGroups.stream() + .map(data -> data.toGroupResponseDto(data)) + .collect(Collectors.toList()); + } + + @Transactional(readOnly = true) + public GroupPartListResponseDto findAllParts() { + List foundParts = groupRepository.findAllParts(); + return new GroupPartListResponseDto(foundParts); + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 277b314..cd4b16a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -9,7 +9,7 @@ spring: password: test1234 jpa: hibernate: - ddl-auto: create + ddl-auto: none show-sql: true open-in-view: false properties: