Skip to content

Commit

Permalink
feat: 소속을 keyword로 검색하는 api를 추가한다.
Browse files Browse the repository at this point in the history
  • Loading branch information
rlarltj committed Nov 10, 2024
1 parent 4157965 commit c22b4e1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public SearchAgencyResponse getAgencyList(
return agencyService.getAgencyList(user.getId(), pageable);
}

@Operation(summary = "소속 목록 검색")
@GetMapping("/search")
public List<AgencyResponse> searchAgencyList(@RequestParam("keyword") String keyword, @AuthenticationPrincipal JwtAuthentication user) {
return agencyService.search(user.getId(), keyword);
}

@Operation(summary = "소속 내 멤버 목록 조회")
@GetMapping("/{agencyId}/agency-users")
public AgencyUserResponses getAgencyUserList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;

public interface AgencyRepositoryCustom {
Page<Agency> findByUniversityNameByPaging(String universityName, Pageable pageable);

Page<Agency> findByUniversityNameAndAgencyTypeByPaging(String universityName, AgencyType type, Pageable pageable);

List<Agency> findByKeyword(String university, String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.function.Supplier;

import static com.moneymong.domain.agency.entity.QAgency.agency;
import static com.moneymong.domain.agency.entity.enums.AgencyType.GENERAL;

@Repository
@RequiredArgsConstructor
Expand Down Expand Up @@ -51,6 +52,23 @@ public Page<Agency> findByUniversityNameAndAgencyTypeByPaging(String universityN

}

@Override
public List<Agency> findByKeyword(String university, String keyword) {
return queryFactory
.selectFrom(agency)
.distinct()
.where(
agency.agencyType.eq(GENERAL)
.and(agency.agencyName.containsIgnoreCase(keyword))
.or(
eqUniversityName(university)
.and(agency.agencyName.containsIgnoreCase(keyword))
)
)
.fetch();
}


private JPAQuery<Agency> getCountQuery(String universityName) {
return queryFactory.selectFrom(agency)
.where(eqUniversityName(universityName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ public CreateAgencyResponse create(Long userId, CreateAgencyRequest request) {
return new CreateAgencyResponse(agency.getId());
}

@Transactional
public List<AgencyResponse> search(Long userId, String keyword) {
String university = getUniversityName(userId);
List<Agency> agencies = agencyRepository.findByKeyword(university, keyword);

return agencies.stream()
.map(AgencyResponse::from)
.toList();
}

private String getUniversityName(Long userId) {
return userUniversityRepository.findByUserId(userId)
.map(UserUniversity::getUniversityName)
Expand Down

0 comments on commit c22b4e1

Please sign in to comment.