Skip to content

MOSU-178 refactor: 비밀번호 변경 리팩토링#199

Merged
jbh010204 merged 2 commits intodevelopfrom
feat/mosu-178
Aug 5, 2025
Merged

MOSU-178 refactor: 비밀번호 변경 리팩토링#199
jbh010204 merged 2 commits intodevelopfrom
feat/mosu-178

Conversation

@jbh010204
Copy link
Member

@jbh010204 jbh010204 commented Aug 5, 2025

✨ 구현한 기능

  • @phonenumber 어노테이션 구현
  • 전화번호로 유저 인증하도록 변경

📢 논의하고 싶은 내용

🎸 기타

Summary by CodeRabbit

  • New Features

    • Introduced a custom annotation for phone number extraction in API endpoints.
    • Added automatic phone number formatting with hyphens for consistency.
  • Improvements

    • Password change now uses phone number verification directly, streamlining the process.
    • Enhanced security by extracting phone numbers from authentication tokens automatically.
  • API Changes

    • Password change request no longer requires a login ID; only the new password is needed.
    • Controller and documentation updated to reflect the new parameter handling.

@jbh010204 jbh010204 self-assigned this Aug 5, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 5, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This change refactors the password change feature to identify users by phone number rather than login ID. It introduces a custom @PhoneNumber annotation and argument resolver, a phone number formatting utility, and repository support for phone number-based queries. Controller and DTO signatures are updated accordingly.

Changes

Cohort / File(s) Change Summary
User Service Refactor
src/main/java/life/mosu/mosuserver/application/user/MyUserService.java
Modified changePassword logic to look up users by formatted phone number instead of login ID, and updated logging.
Repository Extension
src/main/java/life/mosu/mosuserver/domain/user/repository/UserJpaRepository.java
Added findByPhoneNumber(String phoneNumber) method for user lookup by phone number.
Custom Annotation
src/main/java/life/mosu/mosuserver/global/annotation/PhoneNumber.java
Introduced new @PhoneNumber annotation for method parameters.
Argument Resolver
src/main/java/life/mosu/mosuserver/global/resolver/PhoneNumberArgumentResolver.java
Added argument resolver to inject phone number into controller methods using the custom annotation.
Phone Number Utility
src/main/java/life/mosu/mosuserver/global/util/PhoneNumberUtil.java
Added utility class with static method to format phone numbers with hyphens and validate length.
Controller Signature Update
src/main/java/life/mosu/mosuserver/presentation/user/MyUserController.java
Updated changePassword method to receive phone number via @PhoneNumber annotation, removing direct security context access.
Controller Docs Update
src/main/java/life/mosu/mosuserver/presentation/user/MyUserControllerDocs.java
Updated interface method signature to include @PhoneNumber String phoneNumber parameter.
DTO Update
src/main/java/life/mosu/mosuserver/presentation/user/dto/request/ChangePasswordRequest.java
Removed loginId field from ChangePasswordRequest, leaving only newPassword.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller as MyUserController
    participant Resolver as PhoneNumberArgumentResolver
    participant Service as MyUserService
    participant Repo as UserJpaRepository
    participant Util as PhoneNumberUtil

    Client->>Controller: POST /change-password (with request body)
    Controller->>Resolver: Resolve @PhoneNumber parameter
    Resolver->>Controller: Inject phone number from security context
    Controller->>Util: formatPhoneNumberWithHyphen(phoneNumber)
    Util-->>Controller: Formatted phone number
    Controller->>Service: changePassword(request, formattedPhoneNumber)
    Service->>Repo: findByPhoneNumber(formattedPhoneNumber)
    Repo-->>Service: UserJpaEntity (if found)
    Service-->>Controller: ChangePasswordResponse
    Controller-->>Client: ResponseEntity<ApiResponseWrapper<ChangePasswordResponse>>
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Possibly related PRs

  • MOSU-30 feat: 비밀번호 변경 #91: Introduced the initial MyUserService class with a changePassword method using user ID; this PR refactors and extends that logic to use phone number-based lookup.

Suggested labels

우선순위 중

Suggested reviewers

  • chominju02

Poem

A bunny hopped in, with code to revise,
Now passwords change with phone—what a surprise!
Hyphens are added, IDs left behind,
An annotation new, in the code you'll find.
With resolvers and docs all neat and spry,
This rabbit waves—refactor, hop, and fly! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

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


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bd12aa0 and f6e5bfb.

📒 Files selected for processing (8)
  • src/main/java/life/mosu/mosuserver/application/user/MyUserService.java (2 hunks)
  • src/main/java/life/mosu/mosuserver/domain/user/repository/UserJpaRepository.java (1 hunks)
  • src/main/java/life/mosu/mosuserver/global/annotation/PhoneNumber.java (1 hunks)
  • src/main/java/life/mosu/mosuserver/global/resolver/PhoneNumberArgumentResolver.java (1 hunks)
  • src/main/java/life/mosu/mosuserver/global/util/PhoneNumberUtil.java (1 hunks)
  • src/main/java/life/mosu/mosuserver/presentation/user/MyUserController.java (2 hunks)
  • src/main/java/life/mosu/mosuserver/presentation/user/MyUserControllerDocs.java (2 hunks)
  • src/main/java/life/mosu/mosuserver/presentation/user/dto/request/ChangePasswordRequest.java (0 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/mosu-178

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.
  • 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.

@jbh010204 jbh010204 merged commit 8f36d92 into develop Aug 5, 2025
2 of 3 checks passed
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @jbh010204, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the password change mechanism by shifting the user authentication from login ID to phone number. It introduces a custom annotation and an argument resolver to streamline the retrieval of the authenticated user's phone number in controller methods, along with a dedicated utility for phone number formatting. These changes aim to simplify the password change flow and improve code clarity.

Highlights

  • Password Change Logic Refactor: The password change functionality has been refactored to authenticate users directly via their phone number instead of their login ID. This simplifies the process by removing the need for a separate login ID lookup and validation.
  • Custom @PhoneNumber Annotation: A new custom @PhoneNumber annotation has been introduced. This annotation, combined with a PhoneNumberArgumentResolver, allows the phone number of the authenticated user to be automatically injected into controller method parameters, leading to cleaner and more readable API signatures.
  • Phone Number Utility: A new utility class, PhoneNumberUtil, has been added to centralize the formatting of 11-digit phone numbers into a hyphenated XXX-XXXX-XXXX format, ensuring consistency across the application.
  • Request DTO Simplification: The ChangePasswordRequest DTO has been simplified by removing the loginId field, as user identification for password changes now relies solely on the authenticated phone number.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the password change functionality to use a new @PhoneNumber custom annotation and argument resolver. This cleans up the controller logic by abstracting away the details of retrieving the phone number from the security context.

Suggestions include using consistent language for logging, improving variable naming for clarity, and removing unused code and annotations. These changes will make the code easier to understand and maintain.

public ChangePasswordResponse changePassword(ChangePasswordRequest request, String phoneNumber) {

log.info("loginId: {}, phoneNumber: {}", request.loginId(), phoneNumber);
log.info("비밀번호 요청 하는 phoneNumber: {}", phoneNumber);

Choose a reason for hiding this comment

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

medium

The log message is in Korean. For consistency, it's better to use English. This improves maintainability, especially in a diverse team.

Suggested change
log.info("비밀번호 요청 하는 phoneNumber: {}", phoneNumber);
log.info("Request to change password for phoneNumber: {}", phoneNumber);

String loginId = request.loginId();
UserJpaEntity user = userJpaRepository.findByLoginId(loginId)
.orElseThrow(() -> new CustomRuntimeException(ErrorCode.USER_NOT_FOUND));
String rgxPhone = PhoneNumberUtil.formatPhoneNumberWithHyphen(phoneNumber);

Choose a reason for hiding this comment

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

medium

The variable name rgxPhone can be misleading. A more descriptive name like formattedPhoneNumber would improve code readability.

Suggested change
String rgxPhone = PhoneNumberUtil.formatPhoneNumberWithHyphen(phoneNumber);
String formattedPhoneNumber = PhoneNumberUtil.formatPhoneNumberWithHyphen(phoneNumber);

import life.mosu.mosuserver.global.annotation.PhoneNumber;
import life.mosu.mosuserver.global.filter.KmcAuthenticationToken;
import org.springframework.core.MethodParameter;
import org.springframework.core.io.support.SpringFactoriesLoader.ArgumentResolver;

Choose a reason for hiding this comment

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

medium

This import org.springframework.core.io.support.SpringFactoriesLoader.ArgumentResolver is unused and should be removed.


import org.springframework.stereotype.Component;

@Component

Choose a reason for hiding this comment

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

medium

The @Component annotation is unnecessary for a utility class that only contains static methods. Consider making the class final and providing a private constructor to prevent instantiation.

Comment on lines 59 to 60
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

Choose a reason for hiding this comment

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

medium

The authentication variable is initialized but is no longer used after the refactoring. This unused code should be removed.


public record ChangePasswordRequest(
String loginId,
@Schema(

Choose a reason for hiding this comment

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

medium

The loginId field is no longer needed in this DTO, as the phone number is now used for identification. Remove this field to simplify the request object.

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