-
Notifications
You must be signed in to change notification settings - Fork 3
[feature]추천 동아리를 보여주는 API 개발 #656
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -65,6 +65,40 @@ public List<ClubSearchResult> searchClubsByKeyword(String keyword, String recrui | |||||||||||||||||||||||||||||||
| return results.getMappedResults(); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| public List<ClubSearchResult> searchRecommendClubs(String category, String excludeClubId) { | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| List<AggregationOperation> operations = new ArrayList<>(); | ||||||||||||||||||||||||||||||||
| // 모집 상태 & 같은 category & 제외할 club _id 필터 | ||||||||||||||||||||||||||||||||
| operations.add(Aggregation.match( | ||||||||||||||||||||||||||||||||
| new Criteria() | ||||||||||||||||||||||||||||||||
| .and("state").is(ClubState.AVAILABLE.getName()) | ||||||||||||||||||||||||||||||||
| .and("category").is(category) | ||||||||||||||||||||||||||||||||
| .and("_id").ne(excludeClubId) | ||||||||||||||||||||||||||||||||
| .and("recruitmentInformation.clubRecruitmentStatus") | ||||||||||||||||||||||||||||||||
| .in( | ||||||||||||||||||||||||||||||||
| ClubRecruitmentStatus.ALWAYS.toString(), | ||||||||||||||||||||||||||||||||
| ClubRecruitmentStatus.OPEN.toString(), | ||||||||||||||||||||||||||||||||
| ClubRecruitmentStatus.UPCOMING.toString() | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||||||||
| // 랜덤 추출 (5개) | ||||||||||||||||||||||||||||||||
| operations.add(Aggregation.sample(5L)); | ||||||||||||||||||||||||||||||||
| // 필요한 필드만 매핑 | ||||||||||||||||||||||||||||||||
| operations.add( | ||||||||||||||||||||||||||||||||
| Aggregation.project("name", "state", "category", "division") | ||||||||||||||||||||||||||||||||
| .and("recruitmentInformation.introduction").as("introduction") | ||||||||||||||||||||||||||||||||
| .and("recruitmentInformation.clubRecruitmentStatus").as("recruitmentStatus") | ||||||||||||||||||||||||||||||||
| .and(ConditionalOperators.ifNull("$recruitmentInformation.logo").then("")).as("logo") | ||||||||||||||||||||||||||||||||
| .and(ConditionalOperators.ifNull("$recruitmentInformation.tags").then("")).as("tags") | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
|
Comment on lines
+87
to
+93
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain_id(id) 필드 노출 필요 여부 확인 및 추가 제안 추천 목록을 클릭해 상세로 이동해야 한다면 다음과 같이 - Aggregation.project("name", "state", "category", "division")
+ Aggregation.project("name", "state", "category", "division")
+ .and("_id").as("id")ClubSearchResult에 🏁 Script executed: #!/bin/bash
# ClubSearchResult의 필드 정의 확인
rg -n -C2 --type=java 'record\s+ClubSearchResult|class\s+ClubSearchResult' backend/src/main/javaLength of output: 536 Aggregation 프로젝션에 파일: operations.add(
- Aggregation.project("name", "state", "category", "division")
+ Aggregation.project("name", "state", "category", "division")
+ .and("_id").as("id")
.and("recruitmentInformation.introduction").as("introduction")
.and("recruitmentInformation.clubRecruitmentStatus").as("recruitmentStatus")
.and(ConditionalOperators.ifNull("$recruitmentInformation.logo").then("")).as("logo")
📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Aggregation aggregation = Aggregation.newAggregation(operations); | ||||||||||||||||||||||||||||||||
| AggregationResults<ClubSearchResult> results = mongoTemplate.aggregate(aggregation, "clubs", | ||||||||||||||||||||||||||||||||
| ClubSearchResult.class); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return results.getMappedResults(); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| private Criteria getMatchedCriteria(String recruitmentStatus, String division, | ||||||||||||||||||||||||||||||||
| String category) { | ||||||||||||||||||||||||||||||||
| List<Criteria> criteriaList = new ArrayList<>(); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,10 +3,12 @@ | |
| import lombok.AllArgsConstructor; | ||
| import moadong.club.entity.Club; | ||
| import moadong.club.payload.dto.ClubDetailedResult; | ||
| import moadong.club.payload.dto.ClubSearchResult; | ||
| import moadong.club.payload.request.ClubInfoRequest; | ||
| import moadong.club.payload.request.ClubRecruitmentInfoUpdateRequest; | ||
| import moadong.club.payload.response.ClubDetailedResponse; | ||
| import moadong.club.repository.ClubRepository; | ||
| import moadong.club.repository.ClubSearchRepository; | ||
| import moadong.club.util.RecruitmentStateCalculator; | ||
| import moadong.global.exception.ErrorCode; | ||
| import moadong.global.exception.RestApiException; | ||
|
|
@@ -15,11 +17,14 @@ | |
| import org.bson.types.ObjectId; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Service | ||
| @AllArgsConstructor | ||
| public class ClubProfileService { | ||
|
|
||
| private final ClubRepository clubRepository; | ||
| private final ClubSearchRepository clubSearchRepository; | ||
|
|
||
| public void updateClubInfo(ClubInfoRequest request, CustomUserDetails user) { | ||
| Club club = clubRepository.findClubByUserId(user.getId()) | ||
|
|
@@ -47,8 +52,10 @@ public ClubDetailedResponse getClubDetail(String clubId) { | |
| Club club = clubRepository.findClubById(objectId) | ||
| .orElseThrow(() -> new RestApiException(ErrorCode.CLUB_NOT_FOUND)); | ||
|
|
||
| List<ClubSearchResult> clubSearchResults = clubSearchRepository.searchRecommendClubs(club.getCategory(), clubId); | ||
|
|
||
| ClubDetailedResult clubDetailedResult = ClubDetailedResult.of( | ||
| club | ||
| club,clubSearchResults | ||
| ); | ||
|
Comment on lines
+55
to
59
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain자기 자신 제외 필터가 동작하지 않을 가능성(ObjectId 타입 불일치)
변경 후, 동일 클럽이 추천 결과에 포함되지 않는지 꼭 수동/자동 테스트로 검증해 주세요. 🏁 Script executed: #!/bin/bash
set -e
# searchRecommendClubs 메서드 선언 및 구현 위치 확인
rg -nC3 'searchRecommendClubs' -g '*.java'Length of output: 1708 🏁 Script executed: #!/bin/bash
# searchRecommendClubs 구현부 전체 확인
sed -n '1,150p' backend/src/main/java/moadong/club/repository/ClubSearchRepository.javaLength of output: 6099 🏁 Script executed: #!/bin/bash
# ClubProfileService 근처 코드 확인
sed -n '1,100p' backend/src/main/java/moadong/club/service/ClubProfileService.javaLength of output: 2535 ObjectId 타입 불일치로 자기 자신 제외 필터 미동작 가능성 확인 및 수정 필요
🤖 Prompt for AI Agents |
||
| return new ClubDetailedResponse(clubDetailedResult); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
자기 자신 제외 필터가 작동하지 않을 수 있음(String vs ObjectId 비교)
and("_id").ne(excludeClubId)는_id:ObjectId와String의 타입 불일치로 매치되지 않을 수 있습니다.ObjectId로 변환해 비교해야 합니다.다음 패치를 제안합니다:
또는 메서드 시그니처를
ObjectId excludeClubId로 변경하고 서비스에서objectId를 직접 전달하는 것도 좋습니다.📝 Committable suggestion
🤖 Prompt for AI Agents