Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 그룹 검색 시 가입한 그룹 제외 #9

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading