Skip to content

[Feature] API: Add DeleteCategory handler and archive endpoint #120

@mpaulosky

Description

@mpaulosky

Summary

The Categories API is missing a Delete/Archive endpoint. The domain model has ArchivedBy and ArchivedOn fields indicating soft-delete is the intended pattern — but no handler or endpoint exists to perform it.

Current State

CategoryEndpoints.cs exposes:

  • GET /api/v1/categories — List all
  • GET /api/v1/categories/{id} — Get by ID
  • POST /api/v1/categories — Create
  • PUT /api/v1/categories/{id} — Update
  • No Delete/Archive endpoint

Work Required

Following the existing CQRS vertical slice pattern:

1. Command + Handler

Create src/Api/Handlers/Categories/DeleteCategoryHandler.cs:

public record DeleteCategoryCommand(string Id, string ArchivedBy) : IRequest<Result<bool>>;
  • Set ArchivedBy, ArchivedOn on the entity
  • Set Archived = true
  • Persist via ICategoryRepository

2. Endpoint

Add to CategoryEndpoints.cs:

app.MapDelete("/{id}", async (string id, ClaimsPrincipal user, ISender sender) => ...)
   .RequireAuthorization("Admin");
  • Admin-only authorization (match UpdateCategory pattern)
  • Return 204 No Content on success, 404 if not found

3. Repository

Verify ICategoryRepository has ArchiveAsync or UpdateAsync that covers the archived state.

Acceptance Criteria

  • DELETE /api/v1/categories/{id} returns 204 for valid admin request
  • Returns 404 when category not found
  • Returns 401/403 for non-admin requests
  • Archived category is NOT returned in the default list (or is filtered out)
  • Handler tests pass (see linked test issue)

Files

  • src/Api/Handlers/Categories/DeleteCategoryHandler.cs (new)
  • src/Api/Handlers/Categories/CategoryEndpoints.cs
  • src/Api/Repositories/ICategoryRepository.cs

Metadata

Metadata

Assignees

No one assigned

    Labels

    go:yesReady to implementpriority:p2Next sprintrelease:backlogNot yet targetedsprint-3Sprint 3 — Full CRUD UI + ArchivesquadSquad triage inbox — Lead will assign to a membersquad:legolasAssigned to Legolas (Frontend Dev)squad:samAssigned to Sam (Backend Dev)type:featureNew capability

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions