Skip to content

LNK-4730: Added Tenant Soft Delete - #1399

Merged
arianamihailescu merged 6 commits into
devfrom
LNK-4730-SoftDeleteTenant
Jan 29, 2026
Merged

LNK-4730: Added Tenant Soft Delete#1399
arianamihailescu merged 6 commits into
devfrom
LNK-4730-SoftDeleteTenant

Conversation

@arianamihailescu

@arianamihailescu arianamihailescu commented Jan 28, 2026

Copy link
Copy Markdown
Contributor

🛠️ Description of Changes

Added Tenant Soft Delete

🧪 Testing Performed

Tested locally

🧑‍🔬 Unit Testing

  • I have written or updated unit tests to cover my changes

📓 Documentation Updated

Please update any relevant sections in the project documentation that were impacted by the changes in the PR.

Summary by CodeRabbit

Release Notes

  • New Features
    • Added soft delete capability for facilities—facilities can now be marked as deleted without permanent removal.
    • Added "Show deleted" filter in the tenant dashboard to display or hide soft-deleted facilities.
    • Soft-deleted facilities are visually distinguished in listings with reduced opacity, and their associated actions are disabled.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 28, 2026

Copy link
Copy Markdown
Contributor

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.

  • 🔍 Trigger a full review
📝 Walkthrough

Walkthrough

This pull request implements a soft delete feature for facilities across the full stack. It adds an IsDeleted flag to the Facility entity and its associated models, creates a database migration, implements a soft delete operation in the business manager, exposes a new API endpoint, and updates the frontend dashboard to display and manage deleted facilities with filtering capabilities.

Changes

Cohort / File(s) Summary
Data Model & Migration
DotNet/Tenant/Data/Entities/Facility.cs, DotNet/Tenant/Migrations/20260127202702_AddIsDeletedFlag.cs, DotNet/Tenant/Migrations/20260127202702_AddIsDeletedFlag.Designer.cs, DotNet/Tenant/Migrations/TenantDbContextModelSnapshot.cs
Added IsDeleted boolean property to Facility entity, created EF Core migration to add IsDeleted column (default false) to Facilities table, and updated model snapshot to reflect new schema. Changed Facility class from partial to non-partial.
Shared & Business Models
DotNet/Shared/Application/Models/Tenant/FacilityModel.cs, DotNet/Tenant/Business/Models/FacilitySearchModel.cs
Extended FacilityModel and FacilitySearchModel with nullable IsDeleted property for client exposure and search filtering.
Business Logic Layer
DotNet/Tenant/Business/Managers/FacilityManager.cs, DotNet/Tenant/Business/Queries/FacilityQueries.cs
Added SoftDeleteAsync method to mark facilities as deleted and update modification timestamp. Enhanced PagedSearchAsync to accept includeDeleted flag and apply filtering. Refactored query construction for consistency with IsDeleted projection into results.
API Controller
DotNet/Tenant/Controllers/FacilityController.cs
Added includeDeleted parameter to GetFacilities and GetFacilityList endpoints; introduced new SoftDeleteFacility (HTTP DELETE soft/{facilityId}) endpoint with error handling and scheduling service integration.
Frontend Dashboard UI
Web/Admin.UI/src/app/components/tenant/tenant-dashboard/tenant-dashboard.component.html, Web/Admin.UI/src/app/components/tenant/tenant-dashboard/tenant-dashboard.component.ts, Web/Admin.UI/src/app/components/tenant/tenant-dashboard/tenant-dashboard.component.scss
Redesigned table from inline layout to card-based with dynamic column generation. Added checkbox to toggle visibility of deleted facilities. Introduced soft delete button in action column, conditional styling for deleted rows, and methods to manage deletion state. Implemented onSoftDeleteFacility with confirmation dialog and error handling.
Frontend Services & Models
Web/Admin.UI/src/app/interfaces/tenant/facility-config-model.interface.ts, Web/Admin.UI/src/app/services/gateway/tenant/tenant.service.ts
Extended IFacilityConfigModel interface with optional isDeleted property. Added softDeleteFacilityConfiguration method and updated listFacilities signature to accept showDeleted boolean parameter for API calls.

Sequence Diagram(s)

sequenceDiagram
    participant User as User / UI
    participant Ctrl as FacilityController
    participant Mgr as FacilityManager
    participant DB as Database (Facility)

    User->>Ctrl: DELETE /soft/{facilityId}
    Ctrl->>Mgr: SoftDeleteAsync(facilityId)
    Mgr->>DB: Retrieve Facility by facilityId
    alt Facility exists
        Mgr->>DB: Set IsDeleted = true, ModifyDate = now
        DB->>DB: Update Facility
        Mgr->>Ctrl: Return facilityId
        Ctrl->>User: HTTP 200 (success)
    else Facility not found
        Mgr->>Ctrl: Error logged & wrapped
        Ctrl->>User: HTTP 404 / Error response
    end
Loading
sequenceDiagram
    participant User as User / UI
    participant Svc as TenantService
    participant Ctrl as FacilityController
    participant Qry as FacilityQueries
    participant DB as Database

    User->>Svc: listFacilities(..., showDeleted=true)
    Svc->>Ctrl: GET /facilities?includeDeleted=true
    Ctrl->>Qry: PagedSearchAsync(..., includeDeleted=true)
    Qry->>DB: Query Facilities
    alt includeDeleted = true
        DB->>DB: Return all facilities (IsDeleted = true or false)
    else includeDeleted = false
        DB->>DB: Filter WHERE IsDeleted = false
    end
    DB->>Qry: Facilities with IsDeleted property
    Qry->>Ctrl: PagedConfigModel<FacilityModel>
    Ctrl->>Svc: HTTP 200 with results
    Svc->>User: Display facilities in table
    User->>User: Show deleted facilities dimmed if showDeleted enabled
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested reviewers

  • dvargaslantana
  • nvmLantana
  • amphillipsLGC

Poem

🐰 A soft delete born of care,
No data lost, just hidden fair,
Flags and queries dance in tune,
Tenants rest, but not too soon,
Seven years of audit cheer! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive Description covers main sections but lacks details: Testing Performed is vague ('Tested locally'), Unit Testing is unchecked, and Documentation Updated section is incomplete with only placeholder text. Expand 'Testing Performed' with specific test scenarios, confirm unit test status, and detail what documentation updates were made or are needed.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding tenant soft delete functionality.
Linked Issues check ✅ Passed Code changes comprehensively implement soft delete: backend adds IsDeleted property, SoftDeleteAsync methods, query filtering; UI adds soft delete button, showDeleted toggle, and hidden display of deleted items.
Out of Scope Changes check ✅ Passed All changes directly support tenant soft delete: IsDeleted property, soft delete operations, filtered queries, UI controls, and migrations. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

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

@arianamihailescu arianamihailescu changed the title Added Tenant Soft Delete LNK-4730: Added Tenant Soft Delete Jan 28, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
DotNet/Tenant/Controllers/FacilityController.cs (1)

150-165: IsDeleted filter only applies when search parameter is provided.

The IsDeleted = false filter (lines 159-162) is only set inside the if (!string.IsNullOrEmpty(search)) block. When search is empty/null but includeDeleted=false, the filter won't be applied and deleted facilities may be returned.

Suggested fix — apply filter regardless of search parameter
  public async Task<IActionResult> GetFacilityList([FromQuery] string? search, bool includeDeleted = false)
  {
      try
      {
          FacilitySearchModel searchModel = new FacilitySearchModel();
+         if (!includeDeleted)
+         {
+             searchModel.IsDeleted = false;
+         }
+
          if (!string.IsNullOrEmpty(search))
          {
              searchModel.FacilityName = search;
              searchModel.FacilityNameContains = true;
-             if (!includeDeleted)
-             {
-                 searchModel.IsDeleted = false;
-             }
          }

          var facilities = await _facilityQueries.SearchAsync(searchModel, HttpContext.RequestAborted);
🤖 Fix all issues with AI agents
In `@DotNet/Tenant/Business/Managers/FacilityManager.cs`:
- Around line 302-348: SoftDeleteAsync is missing an audit event after
successfully marking the facility as soft deleted; after the SaveChangesAsync
call in FacilityManager.SoftDeleteAsync, invoke the same audit creation flow
used in DeleteAsync (call _createAuditEventCommand.Execute with appropriate
parameters) to record an AuditEventType.Delete (or a dedicated SoftDelete type
if available), include facility id and relevant metadata (service name via
TenantConstants.ServiceName, action, resource id, and actor/context), and ensure
this call is placed inside the try block after persistence so failures to write
the audit bubble up; add/adjust unit tests to cover the successful soft-delete
path and verify the command is executed.

In `@DotNet/Tenant/Business/Queries/FacilityQueries.cs`:
- Around line 23-25: The interface default for sortBy in the PagedSearchAsync
signature (Task<PagedConfigModel<FacilityModel>> PagedSearchAsync) is
"FacilityName" but the concrete FacilityQueries implementation defaults to
"FacilityId"; update the interface signature's sortBy default to "FacilityId" so
both IFacilityQueries and FacilityQueries use the same default and callers get
consistent ordering behavior.

In
`@Web/Admin.UI/src/app/components/tenant/tenant-dashboard/tenant-dashboard.component.ts`:
- Around line 188-229: The soft-delete flow in onSoftDeleteFacility currently
only calls tenantService.softDeleteFacilityConfiguration and leaves report
deletion commented out; update the sequential deletion sequence (in
onSoftDeleteFacility) to include
safeDelete(this.reportService.deleteReports(facilityId)) (or the appropriate
soft-delete/hide method on reportService) in the concat so reports are processed
after configuration, keeping the existing safeDelete wrapper and error/404
handling; if report deletion is intended to be handled by the backend cascade,
remove the commented call and add a short comment referencing the backend
contract instead.
🧹 Nitpick comments (5)
Web/Admin.UI/src/app/components/tenant/tenant-dashboard/tenant-dashboard.component.scss (1)

33-35: Avoid global opacity on deleted rows.
Row-level opacity can reduce contrast and dim buttons/icons; consider styling text/background instead.

♻️ Suggested adjustment
.deleted-row {
-  opacity: 0.5;
+  color: rgba(0, 0, 0, 0.6);
+  background-color: rgba(0, 0, 0, 0.04);
}
Web/Admin.UI/src/app/services/gateway/tenant/tenant.service.ts (1)

70-78: Log message could distinguish soft delete from hard delete.

The log message Delete Facility configuration. (line 73) is identical to the one in deleteFacilityConfiguration (line 63). Consider making it more specific to aid debugging.

Suggested improvement
  softDeleteFacilityConfiguration(facilityId: string): Observable<IEntityDeletedResponse> {
    return this.http.delete<IEntityDeletedResponse>(`${this.appConfigService.config?.baseApiUrl}/facility/soft/${facilityId}`)
      .pipe(
-       tap(_ => console.log(`Delete Facility configuration.`)),
+       tap(_ => console.log(`Soft delete Facility configuration.`)),
        catchError((error) => {
          return this.errorHandler.handleError(error);
        })
      )
  }
DotNet/Tenant/Controllers/FacilityController.cs (1)

387-421: Consider disabling jobs instead of deleting them for soft delete.

The comment on line 416 raises a valid consideration. For soft delete semantics where data is preserved for potential restoration, deleting the jobs permanently may not be ideal. If a facility is ever "undeleted," the jobs would need to be recreated.

Would you like me to help design an approach to pause/disable jobs instead of deleting them, allowing for future restoration?

Web/Admin.UI/src/app/components/tenant/tenant-dashboard/tenant-dashboard.component.html (1)

41-52: Consider adding aria-label or title for disabled facility IDs.

When row.isDeleted is true, the facility ID is shown as disabled text without any indication of why it's disabled. Adding a title or aria-label could improve user experience.

Optional enhancement
  <ng-template `#disabledText`>
-   <span class="disabled-text">
+   <span class="disabled-text" title="Facility has been deleted">
      {{ row.facilityId }}
    </span>
  </ng-template>
DotNet/Tenant/Business/Queries/FacilityQueries.cs (1)

69-100: Add xUnit coverage for new filter/sort branches.

Please add unit tests that exercise includeDeleted true/false, FacilityNameContains true/false, and SortOrder ascending/descending. Use Moq (or equivalent) for repository dependencies and avoid network activity.
As per coding guidelines, suggest unit tests using XUnit when If/Else or Switch/Case blocks are introduced or modified.

Comment thread DotNet/Tenant/Business/Managers/FacilityManager.cs
Comment thread DotNet/Tenant/Business/Queries/FacilityQueries.cs
@arianamihailescu
arianamihailescu merged commit 3a5f387 into dev Jan 29, 2026
16 checks passed
@arianamihailescu
arianamihailescu deleted the LNK-4730-SoftDeleteTenant branch January 29, 2026 15:06
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