Skip to content

Conversation

@ekgns33
Copy link
Contributor

@ekgns33 ekgns33 commented Jul 7, 2025

작업 내용

  • 회원 탈퇴시 사유 선택지 추가
  • 기타 선택 후 직접 입력 필드 추가
  • 테스트 코드 작성

Summary by CodeRabbit

  • New Features

    • Added the ability for users to specify a withdrawal reason and optional detailed explanation when deleting their account.
    • Withdrawal reasons are now recorded and stored for future reference.
  • Bug Fixes

    • Improved input validation to ensure detailed explanations are only accepted when the "Other" reason is selected and are limited to 255 characters.
  • Tests

    • Added tests to verify correct handling of withdrawal reasons and validation errors for invalid input.

@ekgns33 ekgns33 requested a review from Copilot July 7, 2025 07:34
@ekgns33 ekgns33 self-assigned this Jul 7, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 7, 2025

Walkthrough

A user withdrawal reason feature was implemented. This includes new API DTOs and validation, a database table for storing withdrawal reasons, service and domain logic for handling reasons, and corresponding repository and migration scripts. Tests were added and updated to cover new validation rules and request structures.

Changes

File(s) Change Summary
.../user/controller/UserWithdrawController.java Modified deleteUser method to accept and validate a WithdrawRequest body; updated to use command object.
.../user/controller/request/WithdrawRequest.java Added new DTO class for withdrawal requests with validation and conversion to command.
.../user/domain/UserWithdrawReason.java
.../user/domain/WithdrawalReason.java
Added new JPA entity and enum for withdrawal reasons, including validation logic.
.../user/repository/UserWithdrawReasonRepository.java Added new JPA repository interface for withdrawal reasons.
.../user/service/WithdrawService.java Updated withdrawal logic to accept a command object and save withdrawal reason; added helper method.
.../user/service/dto/command/WithdrawCommand.java Added new record class to encapsulate withdrawal command data.
.../resources/db/migration/V20250707__add_withdraw_reason.sql
.../test/resources/db/migration/h2/V20250707__add_withdraw_reason.sql
Added migration scripts to create user_withdrawal_reason table in main and test databases.
.../user/api/UserWithdrawAcceptanceTest.java Updated and added tests for withdrawal reason validation and request structure.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant UserWithdrawController
    participant WithdrawService
    participant UserWithdrawReasonRepository
    participant UserRepository

    Client->>UserWithdrawController: DELETE /user/withdraw (with WithdrawRequest)
    UserWithdrawController->>WithdrawService: withdraw(WithdrawCommand)
    WithdrawService->>UserWithdrawReasonRepository: save(UserWithdrawReason)
    WithdrawService->>UserRepository: delete user data
    WithdrawService-->>UserWithdrawController: complete
    UserWithdrawController-->>Client: 204 No Content
Loading

Suggested labels

size/M

Suggested reviewers

  • jeeheaG

Poem

A bunny hopped and wrote some code,
To track why users leave the road.
With reasons now so clear and neat,
And tests to keep the logic sweet.
In tables new, these tales reside—
A warren’s wisdom, system-wide! 🐇


📜 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 e898670 and 013fb24.

📒 Files selected for processing (1)
  • src/test/java/org/runimo/runimo/user/api/UserWithdrawAcceptanceTest.java (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/java/org/runimo/runimo/user/api/UserWithdrawAcceptanceTest.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 and analyze
✨ 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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds the ability for users to specify a withdrawal reason (including a custom “other” reason) by introducing DB tables, domain models, controller and service changes, plus acceptance tests.

  • Create user_withdrawal_reason table in both main and test H2 migrations
  • Introduce WithdrawalReason enum, UserWithdrawReason entity, repository, and WithdrawCommand DTO
  • Update controller, service, and tests to pass and validate the new reason fields

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/test/resources/db/migration/h2/V20250707__add_withdraw_reason.sql Add test DB table for withdrawal reasons
src/main/resources/db/migration/V20250707__add_withdraw_reason.sql Add production DB table for withdrawal reasons
src/main/java/org/runimo/runimo/user/service/dto/command/WithdrawCommand.java Introduce WithdrawCommand record
src/main/java/org/runimo/runimo/user/service/WithdrawService.java Persist withdrawal reason alongside user deletion
src/main/java/org/runimo/runimo/user/repository/UserWithdrawReasonRepository.java Add JPA repository for withdrawal reasons
src/main/java/org/runimo/runimo/user/domain/WithdrawalReason.java Define enum of possible withdrawal reasons
src/main/java/org/runimo/runimo/user/domain/UserWithdrawReason.java Implement entity and business validation
src/main/java/org/runimo/runimo/user/controller/request/WithdrawRequest.java Extend request DTO with reason fields and conversion
src/main/java/org/runimo/runimo/user/controller/UserWithdrawController.java Accept and forward withdrawal reason in DELETE API
src/test/java/org/runimo/runimo/user/api/UserWithdrawAcceptanceTest.java Add tests for valid/invalid withdrawal-reason flows
Comments suppressed due to low confidence (3)

src/main/java/org/runimo/runimo/user/controller/request/WithdrawRequest.java:18

  • The example value FOUND_BETTER_SERVICE does not match any WithdrawalReason constant. Update the example to a valid enum name.
    @Schema(description = "탈퇴 이유", example = "FOUND_BETTER_SERVICE")

src/main/java/org/runimo/runimo/user/domain/UserWithdrawReason.java:45

  • Throwing a raw IllegalArgumentException will result in a 500 unless you handle it. Introduce a @ControllerAdvice to map this to a 400 Bad Request for clearer API semantics.
            throw new IllegalArgumentException("customReason는 OTHER 타입일 때만 필요합니다.");

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

🧹 Nitpick comments (2)
src/test/java/org/runimo/runimo/user/api/UserWithdrawAcceptanceTest.java (1)

88-127: Consider adding test for invalid withdrawal reason enum values.

While the current tests cover validation constraints, consider adding a test case for invalid withdrawal reason enum values to ensure proper error handling.

Add a test case like:

@Test
@Sql(scripts = "/sql/user_mypage_test_data.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
void 유효하지_않은_탈퇴_사유_에러() throws JsonProcessingException {
    WithdrawRequest request = new WithdrawRequest(
        "INVALID_REASON",
        ""
    );

    given()
        .header("Authorization", token)
        .contentType(ContentType.JSON)
        .body(objectMapper.writeValueAsString(request))
        .when()
        .delete("/api/v1/users")
        .then()
        .statusCode(400);
}
src/main/java/org/runimo/runimo/user/domain/UserWithdrawReason.java (1)

24-25: Consider adding audit timestamp and foreign key relationship.

While the current implementation captures the essential data, consider enhancing the entity for better audit capabilities and data integrity.

Consider adding:

  1. Audit timestamps (created_at)
  2. Foreign key relationship to User (though this might be intentionally omitted for audit purposes)
 @Column(name = "user_id", nullable = false)
 private Long userId;

+@Column(name = "created_at", nullable = false)
+private LocalDateTime createdAt;

+@PrePersist
+protected void onCreate() {
+    createdAt = LocalDateTime.now();
+}

This would provide better audit trail capabilities for withdrawal reasons.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 531e924 and e898670.

📒 Files selected for processing (10)
  • src/main/java/org/runimo/runimo/user/controller/UserWithdrawController.java (2 hunks)
  • src/main/java/org/runimo/runimo/user/controller/request/WithdrawRequest.java (1 hunks)
  • src/main/java/org/runimo/runimo/user/domain/UserWithdrawReason.java (1 hunks)
  • src/main/java/org/runimo/runimo/user/domain/WithdrawalReason.java (1 hunks)
  • src/main/java/org/runimo/runimo/user/repository/UserWithdrawReasonRepository.java (1 hunks)
  • src/main/java/org/runimo/runimo/user/service/WithdrawService.java (3 hunks)
  • src/main/java/org/runimo/runimo/user/service/dto/command/WithdrawCommand.java (1 hunks)
  • src/main/resources/db/migration/V20250707__add_withdraw_reason.sql (1 hunks)
  • src/test/java/org/runimo/runimo/user/api/UserWithdrawAcceptanceTest.java (5 hunks)
  • src/test/resources/db/migration/h2/V20250707__add_withdraw_reason.sql (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 and analyze
🔇 Additional comments (12)
src/main/java/org/runimo/runimo/user/service/dto/command/WithdrawCommand.java (1)

5-9: LGTM! Clean command object design.

The record structure is well-designed for encapsulating withdrawal command data. The separation of concerns is appropriate with validation likely handled at the request DTO level.

src/main/java/org/runimo/runimo/user/repository/UserWithdrawReasonRepository.java (1)

6-6: LGTM! Standard JPA repository implementation.

The repository interface follows Spring Data JPA conventions appropriately.

src/main/java/org/runimo/runimo/user/controller/UserWithdrawController.java (2)

7-7: LGTM! Proper validation annotation added.

Good addition of the @Valid annotation for request validation.


31-36: LGTM! Clean controller method design.

The updated method signature properly handles both the user ID and withdrawal request body with appropriate validation. The conversion to command object maintains good separation of concerns.

src/main/java/org/runimo/runimo/user/service/WithdrawService.java (2)

34-46: LGTM! Well-structured withdrawal flow with proper reason tracking.

The refactored withdraw method maintains the existing withdrawal logic while properly integrating the new reason tracking feature. The separation of concerns with the helper method is good practice.


65-71: LGTM! Clean helper method implementation.

The createUserWithdrawReason method is well-implemented with proper builder pattern usage and clear parameter mapping from the command object.

src/main/java/org/runimo/runimo/user/controller/request/WithdrawRequest.java (1)

18-22: LGTM! Proper validation annotations applied.

The field definitions are well-structured with appropriate Swagger documentation and validation constraints. The @Length annotation correctly limits the reason detail to 255 characters.

src/test/java/org/runimo/runimo/user/api/UserWithdrawAcceptanceTest.java (2)

55-86: LGTM! Well-updated test with proper new request structure.

The existing test has been properly updated to use the new WithdrawRequest structure while maintaining the same validation logic. The test flow is clear and comprehensive.


88-127: LGTM! Comprehensive validation test coverage.

The new validation tests properly cover the business rules:

  1. Detailed reasons are only allowed for "OTHER" withdrawal reasons
  2. Reason details must not exceed 255 characters

The test data and assertions are appropriate for these scenarios.

src/main/java/org/runimo/runimo/user/domain/WithdrawalReason.java (1)

1-18: LGTM! Well-defined withdrawal reason enum.

The enum is properly structured with clear Korean descriptions and appropriate constant names. The inclusion of the "OTHER" option aligns well with the custom reason functionality in the domain model.

src/main/java/org/runimo/runimo/user/domain/UserWithdrawReason.java (2)

15-32: LGTM! Well-structured JPA entity with proper annotations.

The entity is correctly mapped with appropriate JPA annotations. The column mappings are clear and the enum is properly stored as STRING type for readability.


34-47: LGTM! Excellent validation logic implementation.

The validation in the constructor ensures data integrity by enforcing the business rule that custom reasons are only allowed when the withdrawal reason is "OTHER". The validation method is clear and provides a descriptive error message.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 7, 2025

@ekgns33 ekgns33 merged commit 39e739e into main Jul 7, 2025
4 checks passed
@ekgns33 ekgns33 deleted the feat/add-signout-reason branch July 7, 2025 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants