From c388a7f1b8e5b25bd1f9242b280947d1988eb964 Mon Sep 17 00:00:00 2001 From: Sion Shin Date: Sun, 23 Jun 2024 00:05:09 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B7=B8=EB=A3=B9=20=EA=B2=80=EC=83=89?= =?UTF-8?q?=20=EC=8B=9C=20=EA=B0=80=EC=9E=85=ED=95=9C=20=EA=B7=B8=EB=A3=B9?= =?UTF-8?q?=20=EC=A0=9C=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../savemyreceipt/smr/controller/GroupController.java | 2 +- .../smr/infrastructure/GroupRepository.java | 9 +++------ .../java/com/savemyreceipt/smr/service/GroupService.java | 5 +++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/savemyreceipt/smr/controller/GroupController.java b/src/main/java/com/savemyreceipt/smr/controller/GroupController.java index a496f48..50b5a4a 100644 --- a/src/main/java/com/savemyreceipt/smr/controller/GroupController.java +++ b/src/main/java/com/savemyreceipt/smr/controller/GroupController.java @@ -50,7 +50,7 @@ public ApiResponseDto getGroup(@AuthenticationPrincipal User u @GetMapping("/search") public ApiResponseDto searchGroup(@AuthenticationPrincipal User user, @RequestParam String keyword, @RequestParam(defaultValue = "0") int page) { - return ApiResponseDto.success(SuccessStatus.SEARCH_GROUP_SUCCESS, groupService.searchGroup(keyword, page)); + return ApiResponseDto.success(SuccessStatus.SEARCH_GROUP_SUCCESS, groupService.searchGroup(user.getUsername(), keyword, page)); } @Operation(summary = "그룹 생성", description = "그룹을 생성합니다. 생성한 사람이 회계가 됩니다.") diff --git a/src/main/java/com/savemyreceipt/smr/infrastructure/GroupRepository.java b/src/main/java/com/savemyreceipt/smr/infrastructure/GroupRepository.java index e5e30f4..33ff105 100644 --- a/src/main/java/com/savemyreceipt/smr/infrastructure/GroupRepository.java +++ b/src/main/java/com/savemyreceipt/smr/infrastructure/GroupRepository.java @@ -22,18 +22,15 @@ public interface GroupRepository extends JpaRepository { Page findByNameContaining(String keyword, Pageable pageable); @Query("SELECT g FROM Group g LEFT JOIN GroupMember gm ON g.id = gm.group.id " + - "WHERE g.name LIKE %:keyword% " + + "WHERE g.name LIKE %:keyword% AND " + + "g.id NOT IN (SELECT gm.group.id FROM GroupMember gm WHERE gm.member.id = :member_id) " + "GROUP BY g.id " + "ORDER BY COUNT(gm.id) DESC") - Page findByNameContainingOrderByMemberCountDesc(@Param("keyword") String keyword, Pageable pageable); + Page findByNameContainingOrderByMemberCountDesc(@Param("keyword") String keyword, @Param("member_id") Long memberId, Pageable pageable); default Group getGroupById(Long id) { return findById(id).orElseThrow( () -> new CustomException(ErrorStatus.GROUP_NOT_FOUND, ErrorStatus.GROUP_NOT_FOUND.getMessage()) ); } - - - - } diff --git a/src/main/java/com/savemyreceipt/smr/service/GroupService.java b/src/main/java/com/savemyreceipt/smr/service/GroupService.java index 4e341fe..1df712d 100644 --- a/src/main/java/com/savemyreceipt/smr/service/GroupService.java +++ b/src/main/java/com/savemyreceipt/smr/service/GroupService.java @@ -77,10 +77,11 @@ public GroupResponseDto getGroup(String email, Long groupId) { } @Transactional(readOnly = true) - public GroupListResponseDto searchGroup(String keyword, int page) { + public GroupListResponseDto searchGroup(String email, String keyword, int page) { + Member member = memberRepository.getMemberByEmail(email); Pageable pageable = PageRequest.of(page, 12); // Page groups = groupRepository.findByNameContaining(keyword, pageable); - Page groups = groupRepository.findByNameContainingOrderByMemberCountDesc(keyword, pageable); + Page groups = groupRepository.findByNameContainingOrderByMemberCountDesc(keyword, member.getId(), pageable); Page groupResponseDtos = groups.map(group -> GroupResponseDto.builder() .id(group.getId())