Skip to content

[feat] 유저 정보 수정 API 구현 #74

Merged
seung-in-Yoo merged 5 commits into
developfrom
feature/seungin
Jul 27, 2025
Merged

[feat] 유저 정보 수정 API 구현 #74
seung-in-Yoo merged 5 commits into
developfrom
feature/seungin

Conversation

@seung-in-Yoo

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

Copy link
Copy Markdown
Member

#️⃣ 연관된 이슈

#73

📝 작업 내용

  • 유저 정보 수정 API (/api/v1/users/info) 를 구현하였습니다. (HTTP: PATCH)
  • 로그인된 사용자 본인의 유저 정보 (닉네임, 생년월일, 성별, 유저 타입, 장애유형, 이동보조수단)에 대해서 수정이 가능합니다.
  • 수정 시 DTO에 들어온 값만 선택적으로 업데이트하도록 처리하였습니다. (null이면 변경X)

🖼️ 스크린샷 (선택)

내정보수정완료(1)

💬 리뷰 요구사항 (선택)

아마 유저 정보 등록 및 수정에서 유저의 실제 이름을 등록 및 수정하는 로직도 필요할 것 같아서 프론트분들과 상의 해보고 추후에 리팩토링 하겠습니다.

Summary by CodeRabbit

  • 신규 기능

    • 인증된 사용자가 자신의 상세 정보를 수정할 수 있는 PATCH 엔드포인트(/api/v1/users/info)가 추가되었습니다.
    • 사용자 정보 수정 시 닉네임, 생년월일, 성별, 회원 유형, 장애 유형, 보조기구 정보를 선택적으로 입력할 수 있습니다.
  • 스타일

    • 일부 내부 코드의 형식이 더 간결하게 개선되었습니다.

@seung-in-Yoo seung-in-Yoo self-assigned this Jul 27, 2025
@seung-in-Yoo seung-in-Yoo added the 💡 feature 기능 구현 및 개발 label Jul 27, 2025
@coderabbitai

coderabbitai Bot commented Jul 27, 2025

Copy link
Copy Markdown

"""

Walkthrough

사용자가 자신의 상세 정보를 수정할 수 있도록 하는 PATCH 엔드포인트(/api/v1/users/info)가 UserController에 추가되었습니다. 이를 위해 UserInfoUpdateRequestDto DTO와 UserInfoService의 updateUserInfo 메서드가 도입되었으며, User 엔티티의 일부 setter 메서드가 코드 스타일만 변경되었습니다.

Changes

파일 Cohort 변경 요약
.../controller/UserController.java 사용자 정보 수정 PATCH 엔드포인트 추가 및 서비스 연결
.../dto/UserInfoUpdateRequestDto.java 사용자 정보 수정용 DTO 신설, 관련 필드 정의
.../service/UserInfoService.java 사용자 정보 업데이트 로직 및 트랜잭션 메서드 추가
.../entity/User.java 일부 setter 메서드 코드 스타일(한 줄)로 변경, 로직 변화 없음

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant UserController
    participant UserInfoService
    participant UserRepository
    participant User

    Client->>UserController: PATCH /api/v1/users/info (UserInfoUpdateRequestDto)
    UserController->>UserInfoService: updateUserInfo(userId, dto)
    UserInfoService->>UserRepository: findById(userId)
    UserRepository-->>UserInfoService: User
    UserInfoService->>User: set* (필드별 조건부 업데이트)
    UserInfoService->>UserRepository: save(User)
    UserInfoService-->>UserController: void
    UserController-->>Client: 성공 응답 반환
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • KiSeungMin

Poem

🐇
사용자의 정보, 살짝 손질해요
PATCH 한 번에 새로워져요
DTO와 서비스, 컨트롤러도
깔끔하게 이어진 코드의 흐름
봄바람처럼 부드럽게
리뷰도 금방 끝나길 바라요!
🥕
"""

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/seungin

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 generate unit tests to generate unit tests for 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 27, 2025 that may be closed by this pull request
4 tasks

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
src/main/java/com/wayble/server/user/controller/UserController.java (1)

141-163: 새로운 PATCH 엔드포인트 구현이 올바릅니다.

사용자 정보 수정 API가 적절하게 구현되었습니다. 기존 코드 패턴을 따르고 있으며 OpenAPI 문서화도 완료되었습니다.

인증 처리 로직(lines 155-159)이 기존 registerUserInfo 메서드와 중복됩니다. 향후 리팩토링을 고려해보세요.

중복된 인증 로직을 헬퍼 메서드로 추출할 수 있습니다:

+    private Long getCurrentUserId() {
+        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+        if (!(authentication.getPrincipal() instanceof Long userId)) {
+            throw new ApplicationException(UserErrorCase.FORBIDDEN);
+        }
+        return userId;
+    }

     public CommonResponse<String> updateUserInfo(
             @RequestBody @Valid UserInfoUpdateRequestDto dto
     ) {
-        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
-        if (!(authentication.getPrincipal() instanceof Long)) {
-            throw new ApplicationException(UserErrorCase.FORBIDDEN);
-        }
-        Long userId = (Long) authentication.getPrincipal();
+        Long userId = getCurrentUserId();

         userInfoService.updateUserInfo(userId, dto);
         return CommonResponse.success("내 정보 수정 완료");
     }
src/main/java/com/wayble/server/user/dto/UserInfoUpdateRequestDto.java (1)

1-15: DTO 구조는 적절하지만 검증 로직 추가를 고려하세요.

PATCH 작업을 위한 nullable 필드 설계가 적절합니다. 하지만 다음 개선사항을 고려해보세요:

  1. birthDate 필드에 대한 형식 검증 추가
  2. userTypeDISABLED가 아닐 때 disabilityType, mobilityAid가 null인지 검증
  3. 테스트 용이성을 위한 생성자 또는 빌더 패턴 추가

검증 어노테이션을 추가할 수 있습니다:

+import jakarta.validation.constraints.Pattern;
+
 @Getter
 public class UserInfoUpdateRequestDto {
     private String nickname;
+    @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "생년월일은 YYYY-MM-DD 형식이어야 합니다")
     private String birthDate;        // YYYY-MM-DD (nullable)
     private Gender gender;           // MALE, FEMALE, UNKNOWN (nullable)
     private UserType userType;       // GENERAL, DISABLED, COMPANION (nullable)
     private String disabilityType;   // userType이 DISABLED일 때만 값, 아니면 null
     private String mobilityAid;      // userType이 DISABLED일 때만 값, 아니면 null
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9ce7f3a and c079974.

📒 Files selected for processing (4)
  • src/main/java/com/wayble/server/user/controller/UserController.java (2 hunks)
  • src/main/java/com/wayble/server/user/dto/UserInfoUpdateRequestDto.java (1 hunks)
  • src/main/java/com/wayble/server/user/entity/User.java (1 hunks)
  • src/main/java/com/wayble/server/user/service/UserInfoService.java (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/main/java/com/wayble/server/user/service/UserInfoService.java (1)

Learnt from: seung-in-Yoo
PR: #37
File: src/main/java/com/wayble/server/user/entity/User.java:61-62
Timestamp: 2025-07-13T15:08:59.318Z
Learning: Java에서 같은 패키지 내의 클래스들은 import 구문 없이 서로를 참조할 수 있다. com.wayble.server.user.entity 패키지 내의 클래스들은 명시적인 import 없이 사용 가능하다.

🔇 Additional comments (4)
src/main/java/com/wayble/server/user/entity/User.java (1)

98-106: 코드 포매팅 개선이 적절합니다.

setter 메서드들을 단일 라인 형태로 리팩토링한 것이 코드 간결성을 향상시키면서 기능은 그대로 유지하고 있습니다.

src/main/java/com/wayble/server/user/controller/UserController.java (1)

7-7: 새로운 DTO import가 적절합니다.

UserInfoUpdateRequestDto가 올바르게 import되었습니다.

src/main/java/com/wayble/server/user/service/UserInfoService.java (2)

6-6: 새로운 DTO import가 적절합니다.

UserInfoUpdateRequestDto가 올바르게 import되었습니다.


54-86: 전체적인 메서드 구현이 적절합니다.

사용자 정보 선택적 업데이트 로직이 올바르게 구현되었습니다. @Transactional 어노테이션과 null 체크를 통한 조건부 업데이트가 적절합니다.

Comment thread src/main/java/com/wayble/server/user/service/UserInfoService.java
Comment thread src/main/java/com/wayble/server/user/service/UserInfoService.java

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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/service/UserInfoService.java (1)

54-97: 사용자 정보 업데이트 메서드가 잘 구현되었습니다.

메서드 구조와 로직이 전반적으로 잘 설계되었고, 이전 리뷰 코멘트의 문제점들이 적절히 해결되었습니다:

  1. 날짜 파싱 예외 처리가 추가되었습니다
  2. 장애 관련 필드 업데이트 로직이 개선되었습니다

다만, 한 가지 잠재적 이슈가 있습니다: 현재 사용자가 DISABLED 타입이고 dto.getUserType()이 null이지만, dto.getDisabilityType() 또는 dto.getMobilityAid()를 null로 명시적으로 설정하여 해당 필드들을 지우고 싶은 경우에 대한 처리가 불완전합니다.

다음과 같이 개선할 수 있습니다:

 UserType finalUserType = dto.getUserType() != null ? dto.getUserType() : user.getUserType();
 if (finalUserType == UserType.DISABLED) {
-    if (dto.getDisabilityType() != null) {
+    if (dto.getDisabilityType() != null || (dto.getUserType() == null && dto.getDisabilityType() == null)) {
         user.setDisabilityType(dto.getDisabilityType());
     }
-    if (dto.getMobilityAid() != null) {
+    if (dto.getMobilityAid() != null || (dto.getUserType() == null && dto.getMobilityAid() == null)) {
         user.setMobilityAid(dto.getMobilityAid());
     }
 } else if (dto.getUserType() != null) {
     user.setDisabilityType(null);
     user.setMobilityAid(null);
 }

하지만 현재 구현도 일반적인 사용 시나리오에서는 충분히 작동합니다.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c079974 and 805b80a.

📒 Files selected for processing (1)
  • src/main/java/com/wayble/server/user/service/UserInfoService.java (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/main/java/com/wayble/server/user/service/UserInfoService.java (1)

Learnt from: seung-in-Yoo
PR: #37
File: src/main/java/com/wayble/server/user/entity/User.java:61-62
Timestamp: 2025-07-13T15:08:59.318Z
Learning: Java에서 같은 패키지 내의 클래스들은 import 구문 없이 서로를 참조할 수 있다. com.wayble.server.user.entity 패키지 내의 클래스들은 명시적인 import 없이 사용 가능하다.

🔇 Additional comments (1)
src/main/java/com/wayble/server/user/service/UserInfoService.java (1)

6-6: 새로운 DTO import가 적절하게 추가되었습니다.

UserInfoUpdateRequestDto import가 올바르게 추가되어 새로운 업데이트 메서드에서 사용할 수 있습니다.

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

Labels

💡 feature 기능 구현 및 개발

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] 유저 정보 수정 API 구현

1 participant