Skip to content

feat: add remove doctor command - #53

Merged
saijaku0 merged 1 commit into
mainfrom
feat/remove-doctor
Feb 15, 2026
Merged

feat: add remove doctor command#53
saijaku0 merged 1 commit into
mainfrom
feat/remove-doctor

Conversation

@saijaku0

@saijaku0 saijaku0 commented Feb 15, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

Release Notes

  • New Features

    • Added administrative endpoint to delete doctors with safeguards preventing deletion if active appointments exist.
    • Implemented user account disabling capability for system administrators.
  • Chores

    • Enhanced database schema with improved tracking for attachments and relationship mappings.

@saijaku0
saijaku0 merged commit d8bea5f into main Feb 15, 2026
2 of 3 checks passed
@saijaku0
saijaku0 deleted the feat/remove-doctor branch February 15, 2026 19:45
@coderabbitai

coderabbitai Bot commented Feb 15, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

The pull request introduces a doctor deletion feature by adding a DELETE API endpoint, MediatR command handler, and supporting infrastructure. This includes a new Result type for consistent error handling, Identity service extensions for user disabling, domain model updates with navigation properties, and database migrations to reflect the schema changes.

Changes

Cohort / File(s) Summary
Doctor Deletion Feature
src/Booking/Booking.API/Controllers/DoctorsController.cs, src/Booking/Booking.Application/Doctors/Command/DeleteDoctor/DeleteDoctorCommand.cs, src/Booking/Booking.Application/Doctors/Command/DeleteDoctor/DeleteDoctorCommandHandler.cs
Added DELETE endpoint with admin authorization, MediatR command, and handler. Handler validates for active appointments, disables associated user via identity service, deactivates doctor, and persists changes.
Result Type & Extensions
src/Booking/Booking.Application/Common/Models/Result.cs, src/Booking/Booking.Application/Common/Extension/IdentityResultExtensions.cs
Introduced immutable Result type with Succeeded and Errors properties, plus factory methods. Added extension to convert IdentityResult to application Result type.
Service Interfaces & Implementations
src/Booking/Booking.Application/Common/Interfaces/IIdentityService.cs, src/Booking/Booking.Infrastructure/Services/IIdentityService.cs
Extended IIdentityService interface with DisableUserAsync method and implemented it to set user lockout indefinitely while updating security stamp.
Domain Model Updates
src/Booking/Booking.Domain/Entities/Doctor.cs
Added Deactivate() method and Appointments navigation property to Doctor entity for relationship tracking.
Database Schema & Migrations
src/Booking/Booking.Infrastructure/Migrations/20260215154948_UpdateDateCreatedAttachments.*, src/Booking/Booking.Infrastructure/Migrations/20260215162948_UpdateDoctorAppointment.*, src/Booking/Booking.Infrastructure/Persistence/BookingDbContext.cs, src/Booking/Booking.Infrastructure/Migrations/BookingDbContextModelSnapshot.cs
Added DateCreated column to AppointmentAttachments, established explicit Doctor\-Appointment navigation mapping, and updated migration snapshots.
Minor Cleanup
src/Booking/Booking.Application/Appointments/Dtos/AppointmentDetailDto.cs
Removed empty line within class definition.

Sequence Diagram

sequenceDiagram
    participant Client
    participant DoctorsController
    participant Mediator
    participant DeleteDoctorCommandHandler
    participant BookingDbContext
    participant IdentityService
    participant Database

    Client->>DoctorsController: DELETE /api/doctors/{id}
    DoctorsController->>Mediator: Send(DeleteDoctorCommand)
    Mediator->>DeleteDoctorCommandHandler: Handle(command)
    
    DeleteDoctorCommandHandler->>BookingDbContext: Load Doctor with Appointments
    BookingDbContext->>Database: Query Doctor & Appointments
    Database-->>BookingDbContext: Doctor entity
    BookingDbContext-->>DeleteDoctorCommandHandler: Doctor data
    
    alt Doctor not found
        DeleteDoctorCommandHandler-->>Mediator: NotFoundException
    else Active future appointments exist
        DeleteDoctorCommandHandler-->>Mediator: Exception
    else Clear to proceed
        DeleteDoctorCommandHandler->>IdentityService: DisableUserAsync(userId)
        IdentityService->>Database: Set lockout + Update security stamp
        Database-->>IdentityService: Success/Failure
        IdentityService-->>DeleteDoctorCommandHandler: Result
        
        alt User disable failed
            DeleteDoctorCommandHandler-->>Mediator: Exception with errors
        else User disabled successfully
            DeleteDoctorCommandHandler->>BookingDbContext: Deactivate doctor + SaveChangesAsync()
            BookingDbContext->>Database: Update Doctor.IsActive = false
            Database-->>BookingDbContext: Confirmation
            BookingDbContext-->>DeleteDoctorCommandHandler: Complete
            DeleteDoctorCommandHandler-->>Mediator: Success
        end
    end
    
    Mediator-->>DoctorsController: Result
    DoctorsController-->>Client: 204 No Content / 404 / 400
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hoppy deletion hops along,
Doctors deactivate, strong and long,
With Results so clear and appointments in check,
A migration snapshot \_ no need to fret or wreck! 🐇✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/remove-doctor

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai

coderabbitai Bot commented Feb 15, 2026

Copy link
Copy Markdown
Contributor

Note

Unit test generation is a public access feature. Expect some limitations and changes as we gather feedback and continue to improve it.


Generating unit tests... This may take up to 20 minutes.

@coderabbitai

coderabbitai Bot commented Feb 15, 2026

Copy link
Copy Markdown
Contributor

No files have been changed in this PR. Unable to generate unit tests.

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot mentioned this pull request Feb 18, 2026
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