Skip to content

[feat] #110 매칭 상세조회 API 기능 구현#111

Merged
2hyunjinn merged 6 commits intomainfrom
feat/#110
May 6, 2025
Merged

[feat] #110 매칭 상세조회 API 기능 구현#111
2hyunjinn merged 6 commits intomainfrom
feat/#110

Conversation

@2hyunjinn
Copy link
Copy Markdown
Member

@2hyunjinn 2hyunjinn commented May 5, 2025

📌 PR 제목

[feat] #110 매칭 상세조회 API 기능 구현

📌 PR 내용

  • 사용자가 본인의 매칭 내역 중 특정 매칭의 상세 정보를 조회할 수 있는 기능을 구현했습니다.
  • 요청한 페스티벌 ID와 매칭이 실제로 속한 페스티벌이 일치하는지 검증하여 권한을 제한합니다.

🛠 작업 내용

  • 매칭 상세조회 API 엔드포인트 구현 (GET /v1/festivals/{festivalId}/matchings/{matchingId})
  • MatchingService에 getMatchingDetail() 메서드 추가 및 권한 검증 로직 구현
  • 매칭-페스티벌 불일치 시 예외 처리 (FORBIDDEN_RESOURCE)
  • MatchingDetailInfo 응답 DTO 구성
  • 관련 단위 테스트 작성

🔍 관련 이슈

Closes #110

📸 스크린샷 (Optional)

가능하다면 작업한 내용을 보여주는 스크린샷을 첨부해주세요.

📚 레퍼런스 (Optional)

추가로 공유할 정보가 있다면 여기에 작성해주세요.

Summary by CodeRabbit

  • New Features

    • Added a new API endpoint to retrieve detailed information about a specific matching participant for a given festival.
    • Users can now view participant details such as nickname, gender, birth year, MBTI, appearance, introduction, message, and type result via the new endpoint.
  • Bug Fixes

    • Improved error handling to prevent access to matching details if the matching does not belong to the requested festival.
  • Tests

    • Added a test to ensure proper error handling when attempting to access a matching from an incorrect festival.

@2hyunjinn 2hyunjinn added the feat Extra attention is needed label May 5, 2025
@2hyunjinn 2hyunjinn self-assigned this May 5, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented May 5, 2025

Walkthrough

A new API endpoint for retrieving detailed information about a matching participant has been implemented. This includes the addition of a MatchingDetailInfo DTO, a controller method to expose the endpoint, a repository method for fetching a matching by its ID, and corresponding service interface and implementation methods for business logic and validation. A unit test has also been added to verify that the service throws an exception when the matching does not belong to the specified festival.

Changes

File(s) Change Summary
src/main/java/org/festimate/team/api/matching/MatchingController.java Added GET endpoint /v1/festivals/{festivalId}/matchings/{matchingId} for matching detail retrieval.
src/main/java/org/festimate/team/api/matching/dto/MatchingDetailInfo.java Introduced MatchingDetailInfo DTO record and factory method for constructing from Matching.
src/main/java/org/festimate/team/domain/matching/repository/MatchingRepository.java Added method to find a Matching by its ID.
src/main/java/org/festimate/team/domain/matching/service/MatchingService.java Added getMatchingDetail method to the service interface.
src/main/java/org/festimate/team/domain/matching/service/impl/MatchingServiceImpl.java Implemented getMatchingDetail with validation and DTO conversion.
src/test/java/org/festimate/team/domain/matching/service/impl/MatchingServiceImplTest.java Added test for invalid festival scenario in getMatchingDetail.

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>
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement API to retrieve matching detail, returning required fields and enforcing festival/matching validation (#110)

Poem

In the warren of code, a new path appears,
Matching details now fetched without any fears.
From user to festival, the journey is clear,
With DTOs hopping, the data draws near.
If the festival’s wrong, an exception will shout—
This bunny’s new endpoint leaves no room for doubt!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 366a97a and 8ac5fb3.

📒 Files selected for processing (1)
  • src/test/java/org/festimate/team/domain/matching/service/impl/MatchingServiceImplTest.java (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/java/org/festimate/team/domain/matching/service/impl/MatchingServiceImplTest.java
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Copy Markdown

github-actions bot commented May 5, 2025

Test Results

41 tests   41 ✅  1s ⏱️
10 suites   0 💤
10 files     0 ❌

Results for commit 8ac5fb3.

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 28eea30 and 89cb531.

📒 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-defined

The 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 implemented

The 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 otherFestival while the user's request specifies requestedFestival. This thoroughly tests the authorization logic in the service implementation.

Comment on lines +72 to +82
@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);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add null checking and enhance authorization

There are two issues with the current implementation:

  1. No null check for the matching object, which could lead to NullPointerException
  2. 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.

Suggested change
@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);
}

Comment on lines +10 to +33
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()
);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

@2hyunjinn 2hyunjinn merged commit a5b2e32 into main May 6, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat] 매칭 상세조회 API 기능 구현

1 participant