Skip to content

Conversation

@seung-in-Yoo
Copy link
Member

@seung-in-Yoo seung-in-Yoo commented Jul 13, 2025

#️⃣ 연관된 이슈

#34

📝 작업 내용

  • 유저가 특정 웨이블존을 개인 장소로 저장할 수 있는 기능 구현 => /api/v1/users/{userId}/places
  • 중복 저장 방지 로직 추가 → 이미 저장된 경우 400 Bad Request 반환
  • 존재하지 않는 유저 or 웨이블존: 404 , 이미 저장된 장소: 400

📸 스크린샷 (선택)

응답 성공

유저장소저장성공

응답 실패

유저장소저장실패

💬 리뷰 요구사항 (선택)

  • 현재 로그인 구현 안되어있기때문에 Swagger 테스트를 위해 Authorization 헤더는 필수 아님으로 설정하였고, 이후 로그인 인증 붙일 때 @RequestHeader 수정 필요

Summary by CodeRabbit

  • 신규 기능

    • 사용자가 웨이블존에 장소를 저장할 수 있는 API가 추가되었습니다.
    • 중복 저장 및 존재하지 않는 사용자/웨이블존에 대한 오류 처리가 개선되었습니다.
    • 저장된 장소 목록 관리 기능이 향상되었습니다.
  • 버그 수정

    • 장소 저장 시 중복 저장이나 잘못된 정보 입력에 대한 오류 메시지가 명확하게 제공됩니다.

@seung-in-Yoo seung-in-Yoo self-assigned this Jul 13, 2025
@seung-in-Yoo seung-in-Yoo added 💡 feature 기능 구현 및 개발 🔧 refactor 코드 리팩토링 labels Jul 13, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 13, 2025

"""

Walkthrough

사용자 장소 저장 기능이 새롭게 도입되었습니다. UserPlaceController와 UserPlaceService가 추가되어, 사용자의 장소를 저장하는 REST API 엔드포인트와 그 비즈니스 로직이 구현되었습니다. 관련 DTO, 엔티티 관계, 리포지토리, 오류 처리, 중복 검사 등이 함께 반영되었습니다.

Changes

파일/경로 요약 변경 내용 요약
.../controller/UserPlaceController.java 사용자 장소 저장을 위한 REST 컨트롤러(UserPlaceController) 및 POST 엔드포인트 추가
.../service/UserPlaceService.java 사용자 장소 저장 로직, 검증, 중복 검사, 예외 처리 등 서비스 계층(UserPlaceService) 구현
.../dto/UserPlaceRequestDto.java 사용자 장소 저장 요청용 DTO(UserPlaceRequestDto) 레코드 추가, 필드에 @NotNull 적용
.../entity/User.java User 엔티티에 UserPlace와의 1:N 관계(userPlaces 필드) 및 매핑 추가
.../repository/UserPlaceRepository.java
.../repository/UserPlaceWaybleZoneMappingRepository.java
사용자 장소 및 매핑 엔티티용 JPA 리포지토리, 중복/존재 여부 확인용 커스텀 메소드 추가
.../exception/UserErrorCase.java 장소 중복 및 웨이블존 미존재 오류 케이스(WAYBLE_ZONE_NOT_FOUND, PLACE_ALREADY_SAVED, INVALID_USER_ID) enum 항목 추가 및 USER_NOT_FOUND HTTP 상태 404로 변경

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: 성공 응답 반환
Loading

Possibly related issues

Suggested labels

🛠️ fix

Suggested reviewers

  • KiSeungMin

Poem

🐇
새로운 장소 저장의 길이 열렸네,
컨트롤러와 서비스가 손을 잡고,
중복도 검증하며 오류도 척척!
유저의 발걸음 따라
웨이블존에 추억을 저장해요.
코드를 타고 뛰는 토끼의 노래!
🗺️✨
"""

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

@seung-in-Yoo seung-in-Yoo linked an issue Jul 13, 2025 that may be closed by this pull request
4 tasks
Copy link

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

📥 Commits

Reviewing files that changed from the base of the PR and between 46422c9 and 982c0fd.

📒 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 어노테이션으로 필수 필드 검증이 적절히 설정되어 있습니다. 필드 타입과 명명도 적절합니다.

Comment on lines +61 to +62
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
private List<UserPlace> userPlaces = new ArrayList<>();
Copy link

@coderabbitai coderabbitai bot Jul 13, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

Suggested change
@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.

Copy link
Member Author

Choose a reason for hiding this comment

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

현재 같은 패키지 내 클래스여서 import 없이도 사용할 수 있는거 아니야? 파일 내에서도 컴파일 오류 안나고 있어.

Copy link

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.

Copy link

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

📥 Commits

Reviewing files that changed from the base of the PR and between 982c0fd and f3d3f25.

📒 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로 올바르게 수정되어 "리소스를 찾을 수 없음"을 정확히 표현하고 있습니다.

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

Labels

💡 feature 기능 구현 및 개발 🔧 refactor 코드 리팩토링

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] 유저 장소 저장 API 구현

2 participants