Skip to content

feature/#201 회원 비밀번호 변경 구현#202

Merged
LeeShinHaeng merged 9 commits intodevelopfrom
feature/#201-user-update-password
Feb 13, 2025
Merged

feature/#201 회원 비밀번호 변경 구현#202
LeeShinHaeng merged 9 commits intodevelopfrom
feature/#201-user-update-password

Conversation

@LeeShinHaeng
Copy link
Copy Markdown
Contributor

Summary

회원 비밀번호 변경 기능 구현

Tasks

  • 회원 비밀번호 변경 기능을 도메인 로직으로 작성했습니다.
  • 관련 비즈니스 로직을 Facade와 CommandService에 작성했습니다.
  • 엔드포인트를 생성했습니다.
  • 테스트 코드를 작성했습니다.

@LeeShinHaeng LeeShinHaeng added the ✨feature create new feature label Feb 13, 2025
@LeeShinHaeng LeeShinHaeng requested a review from a team February 13, 2025 02:26
@LeeShinHaeng LeeShinHaeng self-assigned this Feb 13, 2025
@LeeShinHaeng LeeShinHaeng linked an issue Feb 13, 2025 that may be closed by this pull request
2 tasks
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 13, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

이 변경사항은 사용자 비밀번호 업데이트 기능을 추가하는 작업입니다. API 계층(UserFacade, UserController, UserControllerImpl)에서는 비밀번호 업데이트를 위한 새로운 메서드와 엔드포인트가 구현되었으며, 요청 데이터를 캡슐화하는 UserPasswordUpdateRequest 레코드가 추가되었습니다. 도메인 계층(User, UserCommandService)에도 비밀번호 업데이트 로직이 포함되었고, 각 계층에 대한 성공 및 예외 상황 테스트가 보완되었습니다.

Changes

파일 변경 요약
aics-api/.../UserFacade.java
aics-api/.../UserController.java
aics-api/.../UserControllerImpl.java
비밀번호 업데이트 기능을 위한 updatePassword 메서드 추가, 관련 요청 객체 및 API 엔드포인트 구현 (import 재배치 포함)
aics-api/.../UserPasswordUpdateRequest.java 사용자 비밀번호 업데이트에 필요한 데이터(원래 비밀번호, 새 비밀번호)를 캡슐화하는 새로운 record 추가
aics-api/.../UserFacadeTest.java updatePassword_SuccessupdatePassword_ThrowsException 테스트 메서드 추가하여 성공/예외 케이스 검증
aics-domain/.../UserCommandService.java
aics-domain/.../User.java
도메인 계층에서 비밀번호 업데이트를 위한 updatePassword 메서드 추가 (비밀번호 검증 및 업데이트 로직 포함)
aics-domain/.../UserCommandServiceTest.java
aics-domain/.../UserDomainTest.java
도메인 계층의 비밀번호 업데이트 기능에 대한 성공 테스트 메서드 추가

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 13, 2025

Test Coverage Report

Overall Project 95.96% 🍏
Files changed 100% 🍏

Module Coverage
aics-api 100% 🍏
aics-domain 94.43% 🍏
Files
Module File Coverage
aics-api UserFacade.java 100% 🍏
aics-domain UserCommandService.java 100% 🍏
User.java 100% 🍏

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Impacted file tree graph

@@              Coverage Diff              @@
##             develop     #202      +/-   ##
=============================================
+ Coverage      92.99%   93.73%   +0.74%     
- Complexity       129      136       +7     
=============================================
  Files             48       48              
  Lines            371      383      +12     
  Branches           4        4              
=============================================
+ Hits             345      359      +14     
+ Misses            21       20       -1     
+ Partials           5        4       -1     
Files with missing lines Coverage Δ Complexity Δ
...gu/developers/api/user/application/UserFacade.java 100.00% <100.00%> (ø) 4.00 <1.00> (+1.00)
...n/user/application/command/UserCommandService.java 100.00% <100.00%> (ø) 5.00 <1.00> (+1.00)
...n/java/kgu/developers/domain/user/domain/User.java 100.00% <100.00%> (+6.25%) 19.00 <4.00> (+5.00)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cd08433...88fe4cc. Read the comment docs.

Copy link
Copy Markdown
Contributor

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

🧹 Nitpick comments (5)
aics-api/src/main/java/kgu/developers/api/user/presentation/request/UserPasswordUpdateRequest.java (2)

14-15: 정규식 패턴의 보안성 강화 필요

현재 비밀번호 정규식이 기본적인 요구사항은 충족하지만, 보안을 더욱 강화하기 위해 다음 사항들을 고려해보시기 바랍니다:

  • 대문자 포함 필수
  • 특수문자 최소 개수 지정
  • 연속된 문자 제한
-		regexp = "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[!@#$%^&*(),.?\":{}|<>])[A-Za-z\\d!@#$%^&*(),.?\":{}|<>]{8,15}$",
+		regexp = "^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[!@#$%^&*(),.?\":{}|<>]){2,}(?!.*(.)\1{2})[A-Za-z\\d!@#$%^&*(),.?\":{}|<>]{8,15}$",
-		message = "비밀번호는 영문, 숫자, 특수문자를 포함하여 8~15자리여야 합니다."
+		message = "비밀번호는 대소문자, 숫자, 특수문자(최소 2개)를 포함하여 8~15자리여야 하며, 연속된 문자는 사용할 수 없습니다."

20-26: 중복 정규식 패턴 리팩토링 필요

originalPassword와 newPassword에 동일한 정규식 패턴이 중복되어 있습니다. 상수로 추출하여 재사용하는 것이 좋습니다.

+	private static final String PASSWORD_PATTERN = "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[!@#$%^&*(),.?\":{}|<>])[A-Za-z\\d!@#$%^&*(),.?\":{}|<>]{8,15}$";
+	private static final String PASSWORD_MESSAGE = "비밀번호는 영문, 숫자, 특수문자를 포함하여 8~15자리여야 합니다.";

	@Pattern(
-		regexp = "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[!@#$%^&*(),.?\":{}|<>])[A-Za-z\\d!@#$%^&*(),.?\":{}|<>]{8,15}$",
-		message = "비밀번호는 영문, 숫자, 특수문자를 포함하여 8~15자리여야 합니다."
+		regexp = PASSWORD_PATTERN,
+		message = PASSWORD_MESSAGE
	)
aics-api/src/main/java/kgu/developers/api/user/application/UserFacade.java (1)

40-43: 트랜잭션 격리 수준 검토 필요

비밀번호 변경과 같은 중요한 작업에는 적절한 트랜잭션 격리 수준이 필요합니다.

+	@Transactional(isolation = Isolation.REPEATABLE_READ)
 	public void updatePassword(UserPasswordUpdateRequest request) {
 		User user = userQueryService.me();
 		userCommandService.updatePassword(user, request.originalPassword(), request.newPassword());
 	}
aics-api/src/main/java/kgu/developers/api/user/presentation/UserControllerImpl.java (1)

53-59: API 응답 및 문서화 개선 필요

비밀번호 변경 API에 대한 개선사항:

  1. Swagger 문서화 누락
  2. 성공/실패 시나리오에 대한 응답 코드 명시 필요
+	@Operation(summary = "비밀번호 변경", description = "사용자의 비밀번호를 변경합니다.")
+	@ApiResponses(value = {
+		@ApiResponse(responseCode = "204", description = "비밀번호 변경 성공"),
+		@ApiResponse(responseCode = "400", description = "잘못된 비밀번호 형식"),
+		@ApiResponse(responseCode = "401", description = "인증 실패")
+	})
 	@Override
 	@PatchMapping("/password")
 	public ResponseEntity<Void> updatePassword(
 		@Valid @RequestBody UserPasswordUpdateRequest request
 	) {
 		userFacade.updatePassword(request);
 		return ResponseEntity.noContent().build();
 	}
aics-api/src/testFixtures/java/user/application/UserFacadeTest.java (1)

110-121: 비밀번호 업데이트 성공 테스트에 검증 로직을 보완하면 좋겠습니다.

현재 테스트는 예외가 발생하지 않는 것만 확인하고 있습니다. 비밀번호가 실제로 변경되었는지 검증하는 로직을 추가하면 더 완성도 높은 테스트가 될 것 같습니다.

다음과 같이 검증 로직을 추가해보세요:

 @Test
 @DisplayName("updatePassword는 주어진 형식으로 변경하는 경우 예외를 던지지 않는다")
 public void updatePassword_Success() {
     // given
     UserPasswordUpdateRequest request = UserPasswordUpdateRequest.builder()
         .originalPassword("password1234")
         .newPassword("newpass1234")
         .build();

+    // when
     assertDoesNotThrow(() -> userFacade.updatePassword(request));
+
+    // then
+    // 변경된 비밀번호로 로그인이 가능한지 확인
+    assertDoesNotThrow(() -> userFacade.login(
+        new UserLoginRequest("202411345", "newpass1234")
+    ));
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cd08433 and a8c4a9e.

📒 Files selected for processing (9)
  • aics-api/src/main/java/kgu/developers/api/user/application/UserFacade.java (2 hunks)
  • aics-api/src/main/java/kgu/developers/api/user/presentation/UserController.java (2 hunks)
  • aics-api/src/main/java/kgu/developers/api/user/presentation/UserControllerImpl.java (3 hunks)
  • aics-api/src/main/java/kgu/developers/api/user/presentation/request/UserPasswordUpdateRequest.java (1 hunks)
  • aics-api/src/testFixtures/java/user/application/UserFacadeTest.java (3 hunks)
  • aics-domain/src/main/java/kgu/developers/domain/user/application/command/UserCommandService.java (1 hunks)
  • aics-domain/src/main/java/kgu/developers/domain/user/domain/User.java (1 hunks)
  • aics-domain/src/testFixtures/java/user/application/UserCommandServiceTest.java (2 hunks)
  • aics-domain/src/testFixtures/java/user/domain/UserDomainTest.java (1 hunks)
🔇 Additional comments (3)
aics-api/src/main/java/kgu/developers/api/user/presentation/UserController.java (1)

58-69: 비밀번호 업데이트 API 구현이 적절합니다.

API 문서화와 입력 유효성 검증이 잘 구현되어 있습니다. 204 응답 코드는 비밀번호 업데이트 작업에 적합합니다.

aics-api/src/testFixtures/java/user/application/UserFacadeTest.java (2)

5-5: 비밀번호 관련 설정이 적절히 구현되었습니다!

비밀번호 암호화를 위한 BCryptPasswordEncoder 설정과 관련 import문이 잘 추가되었으며, 테스트 데이터의 비밀번호도 올바르게 인코딩되어 있습니다.

Also applies to: 12-12, 21-21, 35-35, 43-43


123-136: 예외 처리 테스트가 잘 구현되었습니다!

잘못된 원본 비밀번호를 입력했을 때 InvalidPasswordException이 발생하는지 적절히 검증하고 있습니다. 테스트 구조와 검증 방식이 명확합니다.

Copy link
Copy Markdown
Contributor

@minjo-on minjo-on left a comment

Choose a reason for hiding this comment

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

LGTM😁

Copy link
Copy Markdown
Member

@LeeHanEum LeeHanEum left a comment

Choose a reason for hiding this comment

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

빠른 작업 대단히 감사합니다.
몇가지 코멘트만 확인 부탁드려요 👍

Copy link
Copy Markdown
Member

@LeeHanEum LeeHanEum left a comment

Choose a reason for hiding this comment

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

고생하셨습니다 👍

@LeeShinHaeng LeeShinHaeng merged commit c2f9549 into develop Feb 13, 2025
4 checks passed
@LeeShinHaeng LeeShinHaeng deleted the feature/#201-user-update-password branch February 13, 2025 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨feature create new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

회원 비밀번호 변경 기능

3 participants