-
Notifications
You must be signed in to change notification settings - Fork 1
[feat] 유저 장소 저장 API 구현 #37
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
Conversation
|
""" Walkthrough사용자 장소 저장 기능이 새롭게 도입되었습니다. UserPlaceController와 UserPlaceService가 추가되어, 사용자의 장소를 저장하는 REST API 엔드포인트와 그 비즈니스 로직이 구현되었습니다. 관련 DTO, 엔티티 관계, 리포지토리, 오류 처리, 중복 검사 등이 함께 반영되었습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant UserPlaceController
participant UserPlaceService
participant UserRepository
participant WaybleZoneRepository
participant UserPlaceRepository
participant MappingRepository
Client->>UserPlaceController: POST /api/v1/users/{userId}/places (UserPlaceRequestDto)
UserPlaceController->>UserPlaceService: saveUserPlace(request)
UserPlaceService->>UserRepository: findById(userId)
UserRepository-->>UserPlaceService: User or Exception
UserPlaceService->>WaybleZoneRepository: findById(waybleZoneId)
WaybleZoneRepository-->>UserPlaceService: WaybleZone or Exception
UserPlaceService->>MappingRepository: existsByUserPlace_User_IdAndWaybleZone_Id(userId, waybleZoneId)
MappingRepository-->>UserPlaceService: Boolean (중복 여부)
alt 중복 아님
UserPlaceService->>UserPlaceRepository: save(UserPlace)
UserPlaceService->>MappingRepository: save(UserPlaceWaybleZoneMapping)
else 중복
UserPlaceService-->>UserPlaceController: PLACE_ALREADY_SAVED Exception
end
UserPlaceService-->>UserPlaceController: 완료 메시지
UserPlaceController-->>Client: 성공 응답 반환
Possibly related issues
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches
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. 🪧 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 (
|
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.
Actionable comments posted: 5
🧹 Nitpick comments (2)
src/main/java/com/wayble/server/user/service/UserPlaceService.java (1)
37-37: 중복 체크 쿼리 메서드명이 복잡하고 가독성이 떨어집니다.현재
existsByUserPlace_User_IdAndWaybleZone_Id메서드명이 너무 복잡하여 실수를 유발할 수 있습니다.다음과 같이 더 간단한 메서드로 개선하는 것을 고려해보세요:
-boolean alreadySaved = mappingRepository.existsByUserPlace_User_IdAndWaybleZone_Id(request.userId(), request.waybleZoneId()); +boolean alreadySaved = mappingRepository.existsByUserIdAndWaybleZoneId(request.userId(), request.waybleZoneId());또는 커스텀 쿼리를 사용하여 더 명확하게 표현할 수 있습니다.
src/main/java/com/wayble/server/user/controller/UserPlaceController.java (1)
30-31: 임시 Authorization 헤더에 대한 개선 제안입니다.테스트용 임시 헤더라고 하셨지만, 추후 인증 기능 구현 시 놓치지 않도록 TODO 주석을 추가하는 것이 좋겠습니다.
-// 테스트를 위해 임시 허용 (로그인 구현되면 삭제) +// TODO: 로그인 구현 후 Authorization 헤더 필수로 변경 필요
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
src/main/java/com/wayble/server/user/controller/UserPlaceController.java(1 hunks)src/main/java/com/wayble/server/user/dto/UserPlaceRequestDto.java(1 hunks)src/main/java/com/wayble/server/user/entity/User.java(1 hunks)src/main/java/com/wayble/server/user/exception/UserErrorCase.java(1 hunks)src/main/java/com/wayble/server/user/repository/UserPlaceRepository.java(1 hunks)src/main/java/com/wayble/server/user/repository/UserPlaceWaybleZoneMappingRepository.java(1 hunks)src/main/java/com/wayble/server/user/service/UserPlaceService.java(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (4)
src/main/java/com/wayble/server/user/repository/UserPlaceRepository.java (1)
8-10: 표준적인 JPA 리포지토리 구현입니다.Spring Data JPA 규칙을 잘 따르고 있으며, 메서드명과 반환 타입이 적절합니다.
Optional사용으로 null 안전성도 보장되고 있습니다.src/main/java/com/wayble/server/user/repository/UserPlaceWaybleZoneMappingRepository.java (1)
6-8: 중복 검사를 위한 적절한 존재 여부 확인 메서드입니다.메서드명이 Spring Data JPA 규칙을 정확히 따르고 있으며, boolean 반환 타입으로 중복 저장 방지 로직에 적합합니다.
src/main/java/com/wayble/server/user/exception/UserErrorCase.java (1)
12-13: 새로운 오류 케이스들이 적절히 정의되었습니다.웨이블존 미존재와 중복 장소 저장에 대한 오류 케이스가 올바른 HTTP 상태 코드와 함께 정의되었습니다.
src/main/java/com/wayble/server/user/dto/UserPlaceRequestDto.java (1)
5-9: 깔끔하고 표준적인 DTO 구현입니다.Record 클래스를 사용한 불변 데이터 전송 객체로,
@NotNull어노테이션으로 필수 필드 검증이 적절히 설정되어 있습니다. 필드 타입과 명명도 적절합니다.
| @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) | ||
| private List<UserPlace> userPlaces = new ArrayList<>(); |
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.
UserPlace 엔티티 import 구문이 누락되었습니다.
새로 추가된 userPlaces 필드는 UserPlace 엔티티를 참조하고 있지만, 해당 클래스의 import 구문이 없어 컴파일 오류가 발생할 것입니다.
파일 상단에 다음 import를 추가해주세요:
import com.wayble.server.common.entity.BaseEntity;
import com.wayble.server.review.entity.Review;
+import com.wayble.server.user.entity.UserPlace;
import jakarta.persistence.*;📝 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.
| @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) | |
| private List<UserPlace> userPlaces = new ArrayList<>(); | |
| import com.wayble.server.common.entity.BaseEntity; | |
| import com.wayble.server.review.entity.Review; | |
| import com.wayble.server.user.entity.UserPlace; | |
| import jakarta.persistence.*; |
🤖 Prompt for AI Agents
In src/main/java/com/wayble/server/user/entity/User.java around lines 61 to 62,
the UserPlace entity is referenced in the userPlaces field but its import
statement is missing, causing a compilation error. Add the appropriate import
statement for the UserPlace class at the top of the file to resolve this issue.
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.
현재 같은 패키지 내 클래스여서 import 없이도 사용할 수 있는거 아니야? 파일 내에서도 컴파일 오류 안나고 있어.
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.
@seung-in-Yoo 맞습니다! 제가 실수했네요. 같은 패키지 내의 클래스들은 import 없이 사용할 수 있습니다.
User 클래스와 UserPlace 클래스가 모두 com.wayble.server.user.entity 패키지에 있기 때문에 별도의 import 구문이 필요하지 않습니다. 불필요한 지적을 해서 죄송합니다. 정정해 주셔서 감사합니다!
🐰
╭─╮
( ・ω・) 학습했어요!
╰─╯
✏️ Learnings added
Learnt from: seung-in-Yoo
PR: Wayble-Project/wayble-spring#37
File: src/main/java/com/wayble/server/user/entity/User.java:61-62
Timestamp: 2025-07-13T15:08:59.288Z
Learning: Java에서 같은 패키지 내의 클래스들은 import 구문 없이 서로를 참조할 수 있다. com.wayble.server.user.entity 패키지 내의 클래스들은 명시적인 import 없이 사용 가능하다.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
src/main/java/com/wayble/server/user/exception/UserErrorCase.java
Outdated
Show resolved
Hide resolved
src/main/java/com/wayble/server/user/controller/UserPlaceController.java
Outdated
Show resolved
Hide resolved
src/main/java/com/wayble/server/user/controller/UserPlaceController.java
Show resolved
Hide resolved
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/main/java/com/wayble/server/user/exception/UserErrorCase.java (1)
12-14: 중복 저장 에러에 대해 더 적절한 HTTP 상태 코드 사용을 고려해보세요.새로 추가된 에러 케이스들이 전반적으로 잘 정의되어 있습니다. 다만
PLACE_ALREADY_SAVED의 경우 중복/충돌 상황을 나타내므로 HTTP 409 (Conflict) 상태 코드가 의미상 더 적절할 수 있습니다.다음과 같이 수정하는 것을 고려해보세요:
- PLACE_ALREADY_SAVED(400, 1003, "이미 저장한 장소입니다."), + PLACE_ALREADY_SAVED(409, 1003, "이미 저장한 장소입니다."),하지만 현재의 400 상태 코드도 클라이언트 오류를 나타내므로 충분히 적절합니다.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/main/java/com/wayble/server/review/controller/ReviewController.java(1 hunks)src/main/java/com/wayble/server/user/controller/UserPlaceController.java(1 hunks)src/main/java/com/wayble/server/user/exception/UserErrorCase.java(1 hunks)src/main/java/com/wayble/server/user/service/UserPlaceService.java(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- src/main/java/com/wayble/server/review/controller/ReviewController.java
🚧 Files skipped from review as they are similar to previous changes (2)
- src/main/java/com/wayble/server/user/service/UserPlaceService.java
- src/main/java/com/wayble/server/user/controller/UserPlaceController.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (1)
src/main/java/com/wayble/server/user/exception/UserErrorCase.java (1)
11-11: 이전 리뷰 피드백이 적절히 반영되었습니다.
USER_NOT_FOUND의 HTTP 상태 코드가 400에서 404로 올바르게 수정되어 "리소스를 찾을 수 없음"을 정확히 표현하고 있습니다.
#️⃣ 연관된 이슈
#34
📝 작업 내용
📸 스크린샷 (선택)
응답 성공
응답 실패
💬 리뷰 요구사항 (선택)
Summary by CodeRabbit
신규 기능
버그 수정