Skip to content

Conversation

@efdao
Copy link
Collaborator

@efdao efdao commented Apr 1, 2025

#️⃣ 연관된 이슈>

📝 작업 내용> 이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능)

  1. 논의 삭제 비즈니스 로직 구현했습니다.
    • 논의 삭제 요청시 discussionStatus가 ONGOING이 아니라면 에러 발생합니다.
    • 논의 삭제 시 비트맵 삭제 수행합니다.
    • 해당 논의의 DiscussionParticipants도 DB에서 삭제합니다.
    • 최종적으로 Discussion 삭제합니다.

🙏 여기는 꼭 봐주세요! > 리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요

Summary by CodeRabbit

  • New Features
    • Introduced a secure option for discussion deletion that verifies user eligibility and discussion status before proceeding.
    • Enhanced participant management by automatically handling associated participant removals during the deletion process.
  • Tests
    • Expanded test coverage to ensure successful deletion and proper error handling when deletion conditions are not met, such as unauthorized access or invalid discussion status.

@efdao efdao added the 🛠️ BE Backend label Apr 1, 2025
@efdao efdao added this to the 😉 9차 스프린트 milestone Apr 1, 2025
@efdao efdao self-assigned this Apr 1, 2025
@efdao efdao requested a review from kwon204 as a code owner April 1, 2025 07:28
@coderabbitai
Copy link

coderabbitai bot commented Apr 1, 2025

Walkthrough

The pull request introduces a deletion workflow for discussions and their participants. A new DELETE endpoint is added to the discussion controller, and corresponding service methods in the DiscussionService and DiscussionParticipantService handle validations such as host verification and discussion status checks. Additionally, repository methods for retrieving and bulk deleting discussion participants by discussionId are added. The changes are complemented by comprehensive tests that cover successful deletion scenarios and error cases where deletion is not permitted.

Changes

Files Change Summary
backend/src/main/java/.../DiscussionController.java,
backend/src/main/java/.../DiscussionService.java
Added a deleteDiscussion method with HTTP DELETE mapping in the controller and service. Validates host, checks discussion status, deletes discussion bitmaps, participants, and the discussion entity. Introduced a private helper method for fetching discussion with lock.
backend/src/main/java/.../DiscussionParticipantRepository.java,
backend/src/main/java/.../DiscussionParticipantService.java
Added findByDiscussionId and deleteAllByDiscussionId methods in repository. Added deleteDiscussionParticipants service method to delete all participants by discussionId.
backend/src/test/java/.../DiscussionParticipantServiceTest.java,
backend/src/test/java/.../DiscussionServiceTest.java
Added tests covering successful deletion of discussion participants and discussions, and error scenarios for unauthorized user and invalid discussion status during deletion.

Sequence Diagram(s)

sequenceDiagram
  participant C as Client
  participant DC as DiscussionController
  participant DS as DiscussionService
  participant DPS as DiscussionParticipantService
  participant DMS as DiscussionBitmapService
  participant DR as DiscussionRepository

  C->>DC: DELETE /discussions/{discussionId}
  DC->>DS: deleteDiscussion(discussionId)
  DS->>DS: getDiscussionByIdWithLock(discussionId)
  DS->>DS: verify current user is host
  alt Not Host
      DS-->>C: ApiException (NOT_ALLOWED_USER)
  else
      DS->>DS: check discussion status (ONGOING)
      alt Not Ongoing
         DS-->>C: ApiException (DISCUSSION_NOT_ONGOING)
      else
         DS->>DMS: deleteDiscussionBitmaps(discussionId)
         DS->>DPS: deleteDiscussionParticipants(discussionId)
         DPS->>DPS: deleteAllByDiscussionId(discussionId)
         DS->>DR: delete discussion entity
         DS-->>C: 204 No Content
      end
  end
Loading

Suggested reviewers

  • kwon204

Poem

I hopped through lines of code so bright,
Adding delete flows with all my might.
Discussions vanish with a simple call,
Participants too, I handle them all.
With validations and tests in sight,
I’m the rabbit celebrating code delight!
🥕 Hop on and enjoy the new flight!


📜 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 8150c71dfefbb4f204334c2a5825b3faf23a15d2 and f121860.

📒 Files selected for processing (6)
  • backend/src/main/java/endolphin/backend/domain/discussion/DiscussionController.java (1 hunks)
  • backend/src/main/java/endolphin/backend/domain/discussion/DiscussionParticipantRepository.java (3 hunks)
  • backend/src/main/java/endolphin/backend/domain/discussion/DiscussionParticipantService.java (1 hunks)
  • backend/src/main/java/endolphin/backend/domain/discussion/DiscussionService.java (3 hunks)
  • backend/src/test/java/endolphin/backend/domain/discussion/DiscussionParticipantServiceTest.java (2 hunks)
  • backend/src/test/java/endolphin/backend/domain/discussion/DiscussionServiceTest.java (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • backend/src/main/java/endolphin/backend/domain/discussion/DiscussionParticipantService.java
  • backend/src/main/java/endolphin/backend/domain/discussion/DiscussionParticipantRepository.java
  • backend/src/test/java/endolphin/backend/domain/discussion/DiscussionParticipantServiceTest.java
  • backend/src/main/java/endolphin/backend/domain/discussion/DiscussionService.java
  • backend/src/main/java/endolphin/backend/domain/discussion/DiscussionController.java
  • backend/src/test/java/endolphin/backend/domain/discussion/DiscussionServiceTest.java
✨ 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.
    • 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.

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

@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 (2)
backend/src/main/java/endolphin/backend/domain/discussion/DiscussionController.java (1)

313-332: Well-designed DELETE endpoint with comprehensive API documentation

The endpoint is correctly implemented using proper HTTP method (DELETE), path variable validation, and response status (204 No Content). The OpenAPI documentation is thorough, covering all potential response scenarios.

Consider adding logging for this operation to aid in troubleshooting and auditing:

@DeleteMapping("/{discussionId}")
public ResponseEntity<Void> deleteDiscussion(
    @PathVariable("discussionId") @Min(1) Long discussionId) {
+   log.info("Deleting discussion with ID: {}", discussionId);
    discussionService.deleteDiscussion(discussionId);
+   log.info("Successfully deleted discussion with ID: {}", discussionId);
    return ResponseEntity.noContent().build();
}
backend/src/main/java/endolphin/backend/domain/discussion/DiscussionParticipantService.java (1)

83-88: Consider graceful handling of the "no participants" case in deletion method

The current implementation will throw an exception if no participants are found, which may not be the desired behavior for a deletion operation.

Consider modifying the implementation to handle the case where no participants exist more gracefully:

public void deleteDiscussionParticipants(Long discussionId) {
-   List<DiscussionParticipant> participants = getDiscussionParticipantsByDiscussionId(
-       discussionId);
-
-   discussionParticipantRepository.deleteAll(participants);
+   List<DiscussionParticipant> participants = discussionParticipantRepository.findByDiscussionId(
+       discussionId);
+   
+   if (!participants.isEmpty()) {
+       discussionParticipantRepository.deleteAll(participants);
+   }
}

This approach treats "no participants found" as a valid state for deletion rather than an error condition.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5aa4921 and 8150c71dfefbb4f204334c2a5825b3faf23a15d2.

📒 Files selected for processing (6)
  • backend/src/main/java/endolphin/backend/domain/discussion/DiscussionController.java (1 hunks)
  • backend/src/main/java/endolphin/backend/domain/discussion/DiscussionParticipantRepository.java (1 hunks)
  • backend/src/main/java/endolphin/backend/domain/discussion/DiscussionParticipantService.java (1 hunks)
  • backend/src/main/java/endolphin/backend/domain/discussion/DiscussionService.java (1 hunks)
  • backend/src/test/java/endolphin/backend/domain/discussion/DiscussionParticipantServiceTest.java (2 hunks)
  • backend/src/test/java/endolphin/backend/domain/discussion/DiscussionServiceTest.java (1 hunks)
🔇 Additional comments (8)
backend/src/main/java/endolphin/backend/domain/discussion/DiscussionParticipantRepository.java (1)

119-120: Clean implementation of the repository method

The newly added method follows Spring Data JPA's naming convention for automatic query generation, which is appropriate for this simple query. This method will be useful for retrieving all participants associated with a discussion, which is necessary for the deletion workflow.

backend/src/main/java/endolphin/backend/domain/discussion/DiscussionService.java (1)

398-412: Well-structured discussion deletion logic with appropriate validations

The method properly implements the requirements by:

  1. Verifying the user is the host
  2. Ensuring the discussion status is ONGOING
  3. Deleting associated data in the correct order (bitmaps, participants, then the discussion)

The implementation is thorough and handles the business rules specified in the PR objectives.

backend/src/main/java/endolphin/backend/domain/discussion/DiscussionParticipantService.java (1)

71-81: Good implementation with appropriate transaction and error handling

The method is correctly annotated with @Transactional(readOnly = true) for a read operation and properly validates the existence of participants.

backend/src/test/java/endolphin/backend/domain/discussion/DiscussionParticipantServiceTest.java (2)

613-629: Test correctly verifies discussion participant deletion.

The test properly verifies that the deleteDiscussionParticipants method works by:

  1. Setting up mock discussion participants
  2. Verifying the repository's deleteAll method is called with the correct participants

This test aligns with requirement #4 from the PR objectives (deleting participants associated with a discussion).


631-644: Test properly handles the error case for participant deletion.

This test correctly verifies that an exception is thrown when attempting to delete participants for a discussion that has none. The test ensures:

  1. The error code matches DISCUSSION_PARTICIPANT_NOT_FOUND
  2. The service method properly validates input before proceeding

Good practice to test both success and error scenarios.

backend/src/test/java/endolphin/backend/domain/discussion/DiscussionServiceTest.java (3)

906-927: Test correctly verifies the complete discussion deletion workflow.

This test properly validates the discussion deletion process by:

  1. Setting up a discussion with ONGOING status
  2. Verifying the user is the host before proceeding
  3. Checking that all required deletion steps are called in order:
    • Deleting discussion bitmaps
    • Deleting discussion participants
    • Deleting the discussion itself

This aligns with all the requirements specified in the PR objectives.


929-951: Test correctly verifies authorization for discussion deletion.

The test properly checks that only the host can delete a discussion by:

  1. Setting up a scenario where the current user is not the host
  2. Verifying that an ApiException with error code NOT_ALLOWED_USER is thrown
  3. Ensuring no deletion methods are called in this case

Good security practice to verify authorization before performing destructive operations.


953-975: Test correctly verifies discussion status validation.

This test properly validates that only discussions with ONGOING status can be deleted by:

  1. Setting up a discussion with FINISHED status
  2. Verifying that an ApiException with error code DISCUSSION_NOT_ONGOING is thrown
  3. Ensuring no deletion methods are called in this case

This aligns with requirement #2 from the PR objectives (error when discussion status is not ONGOING).

@efdao efdao requested a review from kwon204 April 3, 2025 04:04
@efdao efdao force-pushed the feature/be/delete-discussion branch from 8150c71 to f121860 Compare May 4, 2025 12:28
Copy link
Contributor

@kwon204 kwon204 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다

@efdao efdao merged commit 4c5ab3d into dev May 10, 2025
3 checks passed
@efdao efdao deleted the feature/be/delete-discussion branch May 10, 2025 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🛠️ BE Backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants