Skip to content

20260404 #623 거래 완료 후 후기 작성 api#634

Open
nayoung04 wants to merge 3 commits intomainfrom
20260404_#623_거래_완료_후_후기_작성_API

Hidden character warning

The head ref may contain hidden characters: "20260404_#623_\uac70\ub798_\uc644\ub8cc_\ud6c4_\ud6c4\uae30_\uc791\uc131_API"
Open

20260404 #623 거래 완료 후 후기 작성 api#634
nayoung04 wants to merge 3 commits intomainfrom
20260404_#623_거래_완료_후_후기_작성_API

Conversation

@nayoung04
Copy link
Copy Markdown
Collaborator

@nayoung04 nayoung04 commented Apr 6, 2026

#623

Summary by CodeRabbit

  • New Features

    • 거래 완료 후 후기 작성 기능 추가 (레이팅, 태그, 코멘트 최대 200자)
    • 후기 전송용 API 엔드포인트 추가
  • Behavior / Validation

    • 거래 미완료 시 후기 작성 불가 알림
    • 중복 후기 등록 차단(이미 작성한 경우 안내)
    • 거래 당사자만 후기 작성 가능 안내

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8f653979-f120-4352-9803-4f16950833e8

📥 Commits

Reviewing files that changed from the base of the PR and between d339df3 and 7258f0a.

📒 Files selected for processing (4)
  • RomRom-Domain-Item/src/main/java/com/romrom/item/dto/TradeResponse.java
  • RomRom-Domain-Item/src/main/java/com/romrom/item/service/TradeReviewService.java
  • RomRom-Web/src/main/java/com/romrom/web/controller/api/TradeControllerDocs.java
  • RomRom-Web/src/main/resources/db/migration/V1_4_58__add_trade_review_constraints.sql
✅ Files skipped from review due to trivial changes (2)
  • RomRom-Domain-Item/src/main/java/com/romrom/item/dto/TradeResponse.java
  • RomRom-Domain-Item/src/main/java/com/romrom/item/service/TradeReviewService.java

Walkthrough

거래 완료 후 후기 작성 기능이 추가되었습니다: 평점·태그 열거형, TradeReview 엔티티·리포지토리, 후기 저장 로직을 가진 서비스, 컨트롤러 엔드포인트 및 관련 에러 코드와 DB 마이그레이션이 도입되었습니다.

Changes

Cohort / File(s) Summary
Constants & Enums
RomRom-Common/src/main/java/com/romrom/common/constant/TradeReviewRating.java, RomRom-Common/src/main/java/com/romrom/common/constant/TradeReviewTag.java
거래 후기 평점(BAD, GOOD, GREAT)과 태그(FAST_RESPONSE, GOOD_ITEM_CONDITION, MATCHES_PHOTO, PUNCTUAL, KIND) 열거형 추가
Error Handling
RomRom-Common/src/main/java/com/romrom/common/exception/ErrorCode.java
거래 후기 관련 에러 코드 3개 추가: TRADE_NOT_COMPLETED, TRADE_REVIEW_ALREADY_EXISTS, TRADE_REVIEW_ACCESS_FORBIDDEN
DTOs
RomRom-Domain-Item/src/main/java/com/romrom/item/dto/TradeRequest.java, RomRom-Domain-Item/src/main/java/com/romrom/item/dto/TradeResponse.java
TradeRequest에 평점(TradeReviewRating), 태그(List<TradeReviewTag>), 댓글(reviewComment) 필드 추가; TradeResponse는 Lombok import 정리(기능/시그니처 변경 없음)
Entity & Repository
RomRom-Domain-Item/src/main/java/com/romrom/item/entity/postgres/TradeReview.java, RomRom-Domain-Item/src/main/java/com/romrom/item/repository/postgres/TradeReviewRepository.java
TradeReview JPA 엔티티 추가(평점, 태그 목록, 댓글, 관계 매핑 포함) 및 (tradeRequestHistory, reviewerMember)에 대한 중복 검사 메서드 추가
Service Layer
RomRom-Domain-Item/src/main/java/com/romrom/item/service/TradeReviewService.java
거래 완료 상태 확인, 작성자 권한 검증, 중복 후기 방지, 후기 생성·저장 로직을 포함한 트랜잭셔널 서비스 추가
API Controller & Docs
RomRom-Web/src/main/java/com/romrom/web/controller/api/TradeController.java, RomRom-Web/src/main/java/com/romrom/web/controller/api/TradeControllerDocs.java
POST /api/trade/review/post 엔드포인트 및 OpenAPI 문서(요청 필드·응답·에러 코드) 추가; 컨트롤러에 서비스 의존성 주입
DB Migration
RomRom-Web/src/main/resources/db/migration/V1_4_58__add_trade_review_constraints.sql
조건부로 NOT NULL 제약 및 (trade_request_history, reviewer_member) 유니크 제약 추가하는 PostgreSQL 마이그레이션 스크립트 추가

Sequence Diagram

sequenceDiagram
    participant Client as Client
    participant Controller as TradeController
    participant Service as TradeReviewService
    participant TRHRepo as TradeRequestHistoryRepository
    participant TRRepo as TradeReviewRepository
    participant DB as Database

    Client->>Controller: POST /api/trade/review/post\n(form-data: tradeRequestHistoryId, rating, tags, comment)
    Controller->>Service: postTradeReview(request)
    Service->>TRHRepo: findById(tradeRequestHistoryId)
    TRHRepo->>DB: SELECT TradeRequestHistory
    DB-->>TRHRepo: TradeRequestHistory
    TRHRepo-->>Service: TradeRequestHistory

    Note over Service: 검증: rating 존재, 상태 == TRADED\n작성자 참가자 여부 확인

    Service->>TRRepo: existsByTradeRequestHistoryAndReviewerMember(...)
    TRRepo->>DB: SELECT COUNT(...)
    DB-->>TRRepo: count
    TRRepo-->>Service: false/true

    Note over Service: reviewedMember 결정(상대 참가자)

    Service->>TRRepo: save(TradeReview)
    TRRepo->>DB: INSERT TradeReview
    DB-->>TRRepo: TradeReview
    TRRepo-->>Service: TradeReview

    Service-->>Controller: void
    Controller-->>Client: 200 OK
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

Possibly related PRs

  • Test #202: 동일한 ErrorCode 파일과 중복 영역(에러 코드 추가/수정)을 다루고 있어 코드 레벨 연관성이 큽니다.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목은 거래 완료 후 후기 작성 API 추가라는 변경 사항의 핵심을 명확하게 요약하고 있으며, 모든 파일 변경(enum, entity, repository, service, controller, migration)이 이 목표와 일치합니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 20260404_#623_거래_완료_후_후기_작성_API

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 8

🧹 Nitpick comments (1)
RomRom-Domain-Item/src/main/java/com/romrom/item/service/TradeReviewService.java (1)

55-76: 중복 후기 동시 요청 시 예외 매핑을 보강해주세요.

현재 exists 조회 후 save까지의 구간은 경쟁 조건이 있어, 동시 요청 시 DB 제약 위반이 500으로 노출될 수 있습니다. 저장 시점의 무결성 예외를 TRADE_REVIEW_ALREADY_EXISTS로 매핑해두는 게 안전합니다.

보강 예시
+import org.springframework.dao.DataIntegrityViolationException;
...
-  tradeReviewRepository.save(tradeReview);
+  try {
+    tradeReviewRepository.save(tradeReview);
+  } catch (DataIntegrityViolationException e) {
+    throw new CustomException(ErrorCode.TRADE_REVIEW_ALREADY_EXISTS);
+  }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@RomRom-Domain-Item/src/main/java/com/romrom/item/service/TradeReviewService.java`
around lines 55 - 76, The existsByTradeRequestHistoryAndReviewerMember check in
TradeReviewService is racy—wrap the tradeReviewRepository.save(tradeReview) call
in a try-catch to catch DB integrity exceptions (e.g.,
DataIntegrityViolationException or a broader DataAccessException) and translate
them into a CustomException with ErrorCode.TRADE_REVIEW_ALREADY_EXISTS; keep the
pre-check (existsByTradeRequestHistoryAndReviewerMember) but ensure save(...)
failure due to unique constraint is handled and rethrown as the same domain
error.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@RomRom-Domain-Item/src/main/java/com/romrom/item/dto/TradeRequest.java`:
- Around line 68-69: The reviewComment field in TradeRequest lacks enforcement
of the documented 200-char limit; add validation and fail fast so inputs >200
chars return BAD_REQUEST. Annotate TradeRequest.reviewComment with a validation
constraint (e.g., `@Size`(max=200)) and ensure the controller accepts `@Valid`
TradeRequest (or that TradeRequest is validated before service call), or
alternatively add an explicit length check in the entry-point (e.g., in the
controller or TradeService method) that throws a BadRequestException when
reviewComment.length() > 200; reference class TradeRequest and field
reviewComment and the controller/service method that receives TradeRequest to
locate where to add the constraint and error handling.

In `@RomRom-Domain-Item/src/main/java/com/romrom/item/dto/TradeResponse.java`:
- Around line 27-28: You added a TradeReview field to the shared DTO
TradeResponse which unintentionally expands the response schema for all
endpoints (e.g., /check, /get); revert that change by removing the tradeReview
field from TradeResponse and introduce a dedicated DTO (e.g.,
TradeWithReviewResponse or TradeReviewResponse) containing the original
TradeResponse fields plus the TradeReview field; update only the
endpoints/controllers/services that legitimately need review data to return the
new DTO (leaving methods that return TradeResponse unchanged) and adjust any
mapping code or constructors that populated TradeResponse.tradeReview to instead
construct the new dedicated response type.

In
`@RomRom-Domain-Item/src/main/java/com/romrom/item/entity/postgres/TradeReview.java`:
- Around line 15-37: The TradeReview entity lacks DB-level integrity: make the
FK fields non-nullable by adding nullable = false to the columns for
tradeRequestHistory, reviewerMember and reviewedMember (e.g., annotate the
corresponding mappings so the DB columns are NOT NULL), add a unique constraint
on the pair (tradeRequestHistory, reviewerMember) via a `@Table`(uniqueConstraints
= ...) on the TradeReview entity to prevent duplicate reviews, and annotate the
tradeReviewTags collection with `@Enumerated`(EnumType.STRING) alongside
`@ElementCollection` so enum values are stored as strings.
- Around line 43-44: The List of enum values tradeReviewTags in TradeReview is
stored without an explicit enumeration type, causing JPA to default to ORDINAL;
update the field annotated with `@ElementCollection` (TradeReview.tradeReviewTags)
to include `@Enumerated`(EnumType.STRING) so the enum values are persisted as
strings (consistent with ItemReport/MemberReport patterns) and avoid future
ordinal-related breakage.

In
`@RomRom-Domain-Item/src/main/java/com/romrom/item/repository/postgres/TradeReviewRepository.java`:
- Around line 11-13: Add a DB-level unique constraint on the composite key
(tradeRequestHistory, reviewerMember) in the TradeReview entity to prevent
race-condition duplicates, and remove reliance on
existsByTradeRequestHistoryAndReviewerMember as the sole guard; additionally,
catch the database integrity violation (e.g., DataIntegrityViolationException or
vendor-specific unique constraint exception) where TradeReview is saved and
translate that exception into the TRADE_REVIEW_ALREADY_EXISTS application error.
Update the TradeReview entity to declare the unique constraint and update the
service/adapter that calls TradeReviewRepository.save(...) to map the DB
uniqueness violation to the TRADE_REVIEW_ALREADY_EXISTS error.

In
`@RomRom-Domain-Item/src/main/java/com/romrom/item/service/TradeReviewService.java`:
- Around line 27-35: Validate required inputs at the start of postTradeReview:
check that the incoming TradeRequest (request) is not null, request.getMember()
(Member) is not null, and request.getTradeRequestHistoryId() is not null before
calling findTradeRequestHistoryById or accessing reviewerMember; if any are null
throw new CustomException(ErrorCode.INVALID_REQUEST). Do these checks at the top
of the method (before invoking findTradeRequestHistoryById or
request.getTradeReviewRating()) so NPEs are avoided and invalid inputs
consistently return INVALID_REQUEST.

In
`@RomRom-Web/src/main/java/com/romrom/web/controller/api/TradeControllerDocs.java`:
- Around line 1353-1356: The API docs list for tradeReviewTags is out of sync
with the implementation: the documentation currently includes CLEAN_PACKAGING
and TRUSTWORTHY but omits MATCHES_PHOTO while the implemented enum is
TradeReviewTag; update the docs in TradeControllerDocs.java so the
tradeReviewTags allowed-values exactly match the TradeReviewTag enum (replace
CLEAN_PACKAGING and TRUSTWORTHY with MATCHES_PHOTO or otherwise mirror the
enum), ensuring the field name tradeReviewTags and the enum symbol
TradeReviewTag are referenced consistently.
- Around line 1343-1345: Update the `@ApiChangeLog` annotation under the
ApiChangeLogs block (the `@ApiChangeLog` entry with date "2026.04.06" and author
Author.KIMNAYOUNG) to use the correct issue number instead of 0; change
issueNumber = 0 to issueNumber = 623 so the change log references the actual
PR/issue ID.

---

Nitpick comments:
In
`@RomRom-Domain-Item/src/main/java/com/romrom/item/service/TradeReviewService.java`:
- Around line 55-76: The existsByTradeRequestHistoryAndReviewerMember check in
TradeReviewService is racy—wrap the tradeReviewRepository.save(tradeReview) call
in a try-catch to catch DB integrity exceptions (e.g.,
DataIntegrityViolationException or a broader DataAccessException) and translate
them into a CustomException with ErrorCode.TRADE_REVIEW_ALREADY_EXISTS; keep the
pre-check (existsByTradeRequestHistoryAndReviewerMember) but ensure save(...)
failure due to unique constraint is handled and rethrown as the same domain
error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d1086f3b-cc24-4e37-bf25-e1f6a2f02d0b

📥 Commits

Reviewing files that changed from the base of the PR and between fadc674 and d339df3.

📒 Files selected for processing (10)
  • RomRom-Common/src/main/java/com/romrom/common/constant/TradeReviewRating.java
  • RomRom-Common/src/main/java/com/romrom/common/constant/TradeReviewTag.java
  • RomRom-Common/src/main/java/com/romrom/common/exception/ErrorCode.java
  • RomRom-Domain-Item/src/main/java/com/romrom/item/dto/TradeRequest.java
  • RomRom-Domain-Item/src/main/java/com/romrom/item/dto/TradeResponse.java
  • RomRom-Domain-Item/src/main/java/com/romrom/item/entity/postgres/TradeReview.java
  • RomRom-Domain-Item/src/main/java/com/romrom/item/repository/postgres/TradeReviewRepository.java
  • RomRom-Domain-Item/src/main/java/com/romrom/item/service/TradeReviewService.java
  • RomRom-Web/src/main/java/com/romrom/web/controller/api/TradeController.java
  • RomRom-Web/src/main/java/com/romrom/web/controller/api/TradeControllerDocs.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant