From ee1d49de6c9710a7f21fe476dc9a1a99efaaf0b9 Mon Sep 17 00:00:00 2001 From: Wonjeong Kim Date: Wed, 14 Feb 2024 14:05:01 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20Group=20=EC=A0=95=EB=A0=AC=20=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inuappcenter/kr/data/repository/GroupRepository.java | 8 +++++--- .../java/server/inuappcenter/kr/service/GroupService.java | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) 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 1cbf36f..58bcf93 100644 --- a/src/main/java/server/inuappcenter/kr/data/repository/GroupRepository.java +++ b/src/main/java/server/inuappcenter/kr/data/repository/GroupRepository.java @@ -20,11 +20,13 @@ public interface GroupRepository extends JpaRepository { @Query("SELECT DISTINCT e.year FROM Group e ORDER BY e.year") List findAllYears(); - List findAllByYearAndPart(Double year, String part); + @Query("SELECT e FROM Group e WHERE e.year = :year AND e.part = :part ORDER BY CASE WHEN e.role.roleName = '파트장' THEN 0 ELSE 1 END, e.member.name") + List findAllByYearAndPartOrderByYear(Double year, String part); - List findAllByYear(Double year); + @Query("SELECT e FROM Group e WHERE e.year = :year ORDER BY CASE WHEN e.role.roleName = '파트장'THEN 0 ELSE 1 END, e.part") + List findAllByYearOrderByPart(Double year); - List findAllByPart(String part); + List findAllByPartOrderByYearDesc(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 382c14c..fd3436d 100644 --- a/src/main/java/server/inuappcenter/kr/service/GroupService.java +++ b/src/main/java/server/inuappcenter/kr/service/GroupService.java @@ -35,17 +35,17 @@ public GroupResponseDto getGroup(Long id) { @Transactional(readOnly = true) public List findAllGroup(Double year, String part) { if (year != null && part != null) { - List foundGroups = groupRepository.findAllByYearAndPart(year, part); + List foundGroups = groupRepository.findAllByYearAndPartOrderByYear(year, part); return foundGroups.stream() .map(data -> data.toGroupResponseDto(data)) .collect(Collectors.toList()); } else if (year != null) { - List foundGroups = groupRepository.findAllByYear(year); + List foundGroups = groupRepository.findAllByYearOrderByPart(year); return foundGroups.stream() .map(data -> data.toGroupResponseDto(data)) .collect(Collectors.toList()); } else if (part != null) { - List foundGroups = groupRepository.findAllByPart(part); + List foundGroups = groupRepository.findAllByPartOrderByYearDesc(part); return foundGroups.stream() .map(data -> data.toGroupResponseDto(data)) .collect(Collectors.toList());