Skip to content

Commit

Permalink
feat: 그룹 검색 시 가입한 그룹 제외
Browse files Browse the repository at this point in the history
  • Loading branch information
Sion99 committed Jun 22, 2024
1 parent e5cba9d commit c388a7f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ApiResponseDto<GroupResponseDto> getGroup(@AuthenticationPrincipal User u
@GetMapping("/search")
public ApiResponseDto<GroupListResponseDto> 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 = "그룹을 생성합니다. 생성한 사람이 회계가 됩니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@ public interface GroupRepository extends JpaRepository<Group, Long> {
Page<Group> 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<Group> findByNameContainingOrderByMemberCountDesc(@Param("keyword") String keyword, Pageable pageable);
Page<Group> 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())
);
}




}
5 changes: 3 additions & 2 deletions src/main/java/com/savemyreceipt/smr/service/GroupService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Group> groups = groupRepository.findByNameContaining(keyword, pageable);
Page<Group> groups = groupRepository.findByNameContainingOrderByMemberCountDesc(keyword, pageable);
Page<Group> groups = groupRepository.findByNameContainingOrderByMemberCountDesc(keyword, member.getId(), pageable);

Page<GroupResponseDto> groupResponseDtos = groups.map(group -> GroupResponseDto.builder()
.id(group.getId())
Expand Down

0 comments on commit c388a7f

Please sign in to comment.