20260404 #623 거래 완료 후 후기 작성 api#634
Conversation
…20260404_#623_거래_완료_후_후기_작성_API
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (2)
Walkthrough거래 완료 후 후기 작성 기능이 추가되었습니다: 평점·태그 열거형, TradeReview 엔티티·리포지토리, 후기 저장 로직을 가진 서비스, 컨트롤러 엔드포인트 및 관련 에러 코드와 DB 마이그레이션이 도입되었습니다. Changes
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (10)
RomRom-Common/src/main/java/com/romrom/common/constant/TradeReviewRating.javaRomRom-Common/src/main/java/com/romrom/common/constant/TradeReviewTag.javaRomRom-Common/src/main/java/com/romrom/common/exception/ErrorCode.javaRomRom-Domain-Item/src/main/java/com/romrom/item/dto/TradeRequest.javaRomRom-Domain-Item/src/main/java/com/romrom/item/dto/TradeResponse.javaRomRom-Domain-Item/src/main/java/com/romrom/item/entity/postgres/TradeReview.javaRomRom-Domain-Item/src/main/java/com/romrom/item/repository/postgres/TradeReviewRepository.javaRomRom-Domain-Item/src/main/java/com/romrom/item/service/TradeReviewService.javaRomRom-Web/src/main/java/com/romrom/web/controller/api/TradeController.javaRomRom-Web/src/main/java/com/romrom/web/controller/api/TradeControllerDocs.java
#623
Summary by CodeRabbit
New Features
Behavior / Validation