teammates icon indicating copy to clipboard operation
teammates copied to clipboard

[#13320] Refactoring data deletion logic to enhance maintainability and debugging

Open rainboh0622 opened this issue 2 months ago • 2 comments

Fixes #13320

**Outline of Solution

  1. Successfully completed deletion method refactoring, consolidating deletion methods from multiple Logic classes into DeletionService.
  2. Reworked soft-delete methods into Db classes that did not already contain them.
  3. Successfully completed all modifications related to deletion preview as required by the proposal.

Modified Classes:

  1. DeletionService.java (created)
  • Unified entry point for all deletion operations
  1. DeletionPreviewData.java
  • Core data model, including:
    • Entity type and identifier
    • Count of affected entities (courses, students, instructors, feedback sessions, etc.)
    • Warning messages list
    • Cascaded deletion information
    • Critical flags (whether last instructor, whether will orphan course, etc.)
  1. DeletionPreviewService.java
  • Deletion preview service, providing the following preview methods:
    • previewCourseDeletion() - Preview course deletion
    • previewStudentDeletion() - Preview student deletion
    • previewInstructorDeletion() - Preview instructor deletion
    • previewAccountDeletion() - Preview account deletion
    • previewAccountRequestDeletion() - Preview account request deletion
    • previewNotificationDeletion() - Preview notification deletion
  1. LogicStarter.java
  • Initialises DeletionService.java and DeletionPreviewService.java.
  1. _Logic classes
  • Refactored Deletion methods into DeletionService.java, including:
    • AccountRequestsLogic.java
    • AccountsLogic.java
    • CoursesLogic.java
    • DataBundleLogic.java
    • DeadlineExtensionsLogic.java
    • FeedbackQuestionsLogic.java
    • FeedbackResponseCommentsLogic.java
    • FeedbackResponsesLogic.java
    • InstructorsLogic.java
    • NotificationsLogic.java
    • StudentsLogic.java
  1. _Db classes
  • Added softDelete_() and restoreDeleted_() methods, including:
    • AccountRequestsDb.java
    • AccountsDb.java
    • DeadlineExtensionsDb.java
    • FeedbackQuestionsDb.java
    • FeedbackResponseCommentsDb.java
    • FeedbackResponsesDb.java
    • InstructorsDb.java
    • NotificationsDb.java
    • StudentsDb.java
  1. Entity classes & attribute classes
  • Added deletedAt Instant and relevant methods into:

    • Entity classes in main/java/teammates/storage/entity/
    • BaseEntity.java in main/java/teammates/storage/sqlentity/
    • Atttribute classes in main/java/teammates/common/datatransfer/attributes/
  • Linked deletedAt Instants between corresponding entity/atttribute classes by editing valueOf().

  1. Database Layer Enhancements
  • Added count methods to the following Db classes to support preview functionality:
    • FeedbackSessionsDb: Added getFeedbackSessionsCountForCourse()
    • FeedbackQuestionsDb: Added getFeedbackQuestionsCountForCourse()
    • FeedbackResponsesDb: Added getFeedbackResponsesCountForCourse()
    • FeedbackResponseCommentsDb: Added getFeedbackResponseCommentsCountForCourse()
    • DeadlineExtensionsDb: Added getDeadlineExtensionsCountForCourse()
  1. API Endpoints Layer
  • Created the following REST API endpoints:
    • PreviewCourseDeletionAction - GET /webapi/course/deletion/preview
    • PreviewStudentDeletionAction - GET /webapi/student/deletion/preview
    • PreviewInstructorDeletionAction - GET /webapi/instructor/deletion/preview
    • PreviewAccountDeletionAction - GET /webapi/account/deletion/preview
  1. Output Format
  • DeletionPreviewOutput.java. API response format, containing:
    • Statistics of all affected entities
    • Warning messages
    • Cascaded deletion details
    • Well-structured data for frontend display
  1. Routing Configuration
  • Added new URI constants in Const.java
  • Registered all preview API endpoints in ActionFactory.java
  • Initialized DeletionPreviewService.java dependencies in LogicStarter.java
  1. Created or modified basic test framework:
  • DeletionServiceTest.java - Deletion service unit tests
  • DeletionPreviewServiceTest.java - Service layer unit tests
  • PreviewCourseDeletionActionTest.java - API endpoint test template
  • _DbTest.java in test/java/teammates/storage/api/ - Soft delete unit tests

rainboh0622 avatar Oct 25 '25 13:10 rainboh0622

Hi @rainboh0622, thank you for your interest in contributing to TEAMMATES! However, your PR does not appear to follow our contribution guidelines:

  • Title must start with the issue number the PR is fixing in square brackets, e.g. [#<issue-number>]

Please address the above before we proceed to review your PR.

github-actions[bot] avatar Oct 25 '25 13:10 github-actions[bot]

Update PR title to start with [#13320] (add a space between it and the rest of title?)

u7676784 avatar Oct 25 '25 23:10 u7676784