Conversation
WalkthroughA new API endpoint for retrieving detailed information about a matching participant has been implemented. This includes the addition of a Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Controller
participant Service
participant Repository
Client->>Controller: GET /v1/festivals/{festivalId}/matchings/{matchingId}
Controller->>Service: getMatchingDetail(userId, festivalId, matchingId)
Service->>Repository: findByMatchingId(matchingId)
Repository-->>Service: Matching
Service->>Service: Validate festival/participant
Service->>Controller: MatchingDetailInfo
Controller-->>Client: ApiResponse<MatchingDetailInfo>
Assessment against linked issues
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Test Results41 tests 41 ✅ 1s ⏱️ Results for commit 8ac5fb3. ♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
src/main/java/org/festimate/team/api/matching/MatchingController.java(2 hunks)src/main/java/org/festimate/team/api/matching/dto/MatchingDetailInfo.java(1 hunks)src/main/java/org/festimate/team/domain/matching/repository/MatchingRepository.java(1 hunks)src/main/java/org/festimate/team/domain/matching/service/MatchingService.java(2 hunks)src/main/java/org/festimate/team/domain/matching/service/impl/MatchingServiceImpl.java(3 hunks)src/test/java/org/festimate/team/domain/matching/service/impl/MatchingServiceImplTest.java(3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/main/java/org/festimate/team/api/matching/MatchingController.java (1)
src/main/java/org/festimate/team/global/response/ResponseBuilder.java (1)
ResponseBuilder(5-19)
🔇 Additional comments (3)
src/main/java/org/festimate/team/domain/matching/service/MatchingService.java (1)
15-15: LGTM: Service interface method is well-definedThe method signature includes all necessary parameters and has an appropriate return type.
src/main/java/org/festimate/team/api/matching/MatchingController.java (1)
43-53: LGTM: Controller endpoint is properly implementedThe endpoint follows the RESTful convention and is consistent with other endpoints in this controller. It correctly extracts the user ID from the access token and uses the service method to handle the business logic.
src/test/java/org/festimate/team/domain/matching/service/impl/MatchingServiceImplTest.java (1)
246-272: Test case for validating festival matching association looks good.The test correctly verifies that attempting to access a matching from a festival that doesn't own it results in a FORBIDDEN_RESOURCE exception. This is an important security check that prevents unauthorized access to matching data.
I notice the test creates a mismatch by associating the matching with
otherFestivalwhile the user's request specifiesrequestedFestival. This thoroughly tests the authorization logic in the service implementation.
src/main/java/org/festimate/team/domain/matching/repository/MatchingRepository.java
Outdated
Show resolved
Hide resolved
| @Transactional(readOnly = true) | ||
| @Override | ||
| public MatchingDetailInfo getMatchingDetail(Long userId, Long festivalId, Long matchingId) { | ||
| Festival festival = festivalService.getFestivalByIdOrThrow(festivalId); | ||
| participantService.getParticipantOrThrow(userService.getUserByIdOrThrow(userId), festival); | ||
| Matching matching = matchingRepository.findByMatchingId(matchingId); | ||
| if (!matching.getFestival().getFestivalId().equals(festivalId)) { | ||
| throw new FestimateException(ResponseError.FORBIDDEN_RESOURCE); | ||
| } | ||
| return MatchingDetailInfo.from(matching); | ||
| } |
There was a problem hiding this comment.
Add null checking and enhance authorization
There are two issues with the current implementation:
- No null check for the matching object, which could lead to NullPointerException
- The authorization check only verifies the user is a participant in the festival, but doesn't verify they're involved in the matching
@Transactional(readOnly = true)
@Override
public MatchingDetailInfo getMatchingDetail(Long userId, Long festivalId, Long matchingId) {
Festival festival = festivalService.getFestivalByIdOrThrow(festivalId);
- participantService.getParticipantOrThrow(userService.getUserByIdOrThrow(userId), festival);
+ Participant participant = participantService.getParticipantOrThrow(userService.getUserByIdOrThrow(userId), festival);
Matching matching = matchingRepository.findByMatchingId(matchingId);
+ if (matching == null) {
+ throw new FestimateException(ResponseError.NOT_FOUND_RESOURCE);
+ }
if (!matching.getFestival().getFestivalId().equals(festivalId)) {
throw new FestimateException(ResponseError.FORBIDDEN_RESOURCE);
}
+ // Check if user is involved in this matching
+ if (!matching.getApplicantParticipant().getParticipantId().equals(participant.getParticipantId()) &&
+ (matching.getTargetParticipant() == null ||
+ !matching.getTargetParticipant().getParticipantId().equals(participant.getParticipantId()))) {
+ throw new FestimateException(ResponseError.FORBIDDEN_RESOURCE);
+ }
return MatchingDetailInfo.from(matching);
}When implementing the repository change to return Optional<Matching>, this method would also need to be updated:
@Transactional(readOnly = true)
@Override
public MatchingDetailInfo getMatchingDetail(Long userId, Long festivalId, Long matchingId) {
Festival festival = festivalService.getFestivalByIdOrThrow(festivalId);
Participant participant = participantService.getParticipantOrThrow(userService.getUserByIdOrThrow(userId), festival);
- Matching matching = matchingRepository.findByMatchingId(matchingId);
- if (matching == null) {
+ Matching matching = matchingRepository.findByMatchingId(matchingId)
+ .orElseThrow(() -> new FestimateException(ResponseError.NOT_FOUND_RESOURCE));
- throw new FestimateException(ResponseError.NOT_FOUND_RESOURCE);
- }
// Rest of the method...
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| @Transactional(readOnly = true) | |
| @Override | |
| public MatchingDetailInfo getMatchingDetail(Long userId, Long festivalId, Long matchingId) { | |
| Festival festival = festivalService.getFestivalByIdOrThrow(festivalId); | |
| participantService.getParticipantOrThrow(userService.getUserByIdOrThrow(userId), festival); | |
| Matching matching = matchingRepository.findByMatchingId(matchingId); | |
| if (!matching.getFestival().getFestivalId().equals(festivalId)) { | |
| throw new FestimateException(ResponseError.FORBIDDEN_RESOURCE); | |
| } | |
| return MatchingDetailInfo.from(matching); | |
| } | |
| @Transactional(readOnly = true) | |
| @Override | |
| public MatchingDetailInfo getMatchingDetail(Long userId, Long festivalId, Long matchingId) { | |
| Festival festival = festivalService.getFestivalByIdOrThrow(festivalId); | |
| Participant participant = participantService.getParticipantOrThrow( | |
| userService.getUserByIdOrThrow(userId), | |
| festival | |
| ); | |
| Matching matching = matchingRepository.findByMatchingId(matchingId); | |
| if (matching == null) { | |
| throw new FestimateException(ResponseError.NOT_FOUND_RESOURCE); | |
| } | |
| if (!matching.getFestival().getFestivalId().equals(festivalId)) { | |
| throw new FestimateException(ResponseError.FORBIDDEN_RESOURCE); | |
| } | |
| // Check if user is involved in this matching | |
| if (!matching.getApplicantParticipant().getParticipantId().equals(participant.getParticipantId()) | |
| && (matching.getTargetParticipant() == null | |
| || !matching.getTargetParticipant().getParticipantId().equals(participant.getParticipantId()))) { | |
| throw new FestimateException(ResponseError.FORBIDDEN_RESOURCE); | |
| } | |
| return MatchingDetailInfo.from(matching); | |
| } |
| public record MatchingDetailInfo( | ||
| String nickname, | ||
| Gender gender, | ||
| Integer birthYear, | ||
| Mbti mbti, | ||
| AppearanceType appearance, | ||
| String introduction, | ||
| String message, | ||
| TypeResult typeResult | ||
| ) { | ||
| public static MatchingDetailInfo from(Matching matching) { | ||
| Participant participant = matching.getTargetParticipant(); | ||
| return new MatchingDetailInfo( | ||
| participant.getUser().getNickname(), | ||
| participant.getUser().getGender(), | ||
| participant.getUser().getBirthYear(), | ||
| participant.getUser().getMbti(), | ||
| participant.getUser().getAppearanceType(), | ||
| participant.getIntroduction(), | ||
| participant.getMessage(), | ||
| participant.getTypeResult() | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
Add null check to prevent potential NullPointerException.
The from method doesn't handle the case when matching.getTargetParticipant() is null, which could happen for PENDING matchings as seen in the test file where some matchings have null target participants.
Consider adding a null check before accessing the participant's properties:
public static MatchingDetailInfo from(Matching matching) {
Participant participant = matching.getTargetParticipant();
+ if (participant == null) {
+ return new MatchingDetailInfo(
+ null, null, null, null, null, null, null, null
+ );
+ }
return new MatchingDetailInfo(
participant.getUser().getNickname(),
participant.getUser().getGender(),
participant.getUser().getBirthYear(),
participant.getUser().getMbti(),
participant.getUser().getAppearanceType(),
participant.getIntroduction(),
participant.getMessage(),
participant.getTypeResult()
);
}Alternatively, you might want to create a separate DTO for pending matchings or throw an appropriate exception if this method should only be called for completed matchings.
📌 PR 제목
[feat] #110 매칭 상세조회 API 기능 구현
📌 PR 내용
🛠 작업 내용
🔍 관련 이슈
Closes #110
📸 스크린샷 (Optional)
가능하다면 작업한 내용을 보여주는 스크린샷을 첨부해주세요.
📚 레퍼런스 (Optional)
추가로 공유할 정보가 있다면 여기에 작성해주세요.
Summary by CodeRabbit
New Features
Bug Fixes
Tests