Skip to content

story(machine): implement DELETE /api/v1/machines/{id} endpoint #637

@Zaba505

Description

@Zaba505

Description

Implement HTTP REST API endpoint for deleting a machine registration. This allows administrators to remove machines from the inventory when they are decommissioned or no longer managed.

Acceptance Criteria

  • Endpoint created in services/machine/endpoint/delete_machine.go
  • Route: DELETE /api/v1/machines/{id}
  • Implements OpenAPI-first handler pattern (z5labs/humus):
    • RequestBody() method defining OpenAPI request schema
    • Responses() method defining OpenAPI response schemas
    • ServeHTTP() method implementing HTTP handler logic
  • Path parameter validation:
    • Extract machine ID from path
    • Validate UUIDv7 format
    • Return HTTP 400 Bad Request with RFC 7807 Problem Details for invalid format
  • Machine existence check:
    • Query Firestore to verify machine exists
    • Return HTTP 404 Not Found with RFC 7807 Problem Details if not found
  • Firestore integration:
    • Delete machine from machines/{id} collection
    • Handle Firestore errors gracefully
    • Consider soft delete vs hard delete (optional: archive to deleted_machines collection)
  • Response:
    • HTTP 204 No Content on success
    • Empty response body
  • Error responses use RFC 7807 Problem Details format:
    • Content-Type: application/problem+json
    • Include type, title, status, detail, instance fields
    • 404 response includes machine_id field
  • Idempotency:
    • Deleting an already-deleted machine returns 404 (not 204)
    • Consider idempotency for concurrent delete requests
  • OpenTelemetry instrumentation:
    • Log machine deletion with machine_id
    • Metrics: deletion count, success/failure rate
    • Trace context propagation
  • Unit tests:
    • Test successful machine deletion
    • Test machine not found (404)
    • Test invalid machine ID format (400)
    • Test idempotency (delete twice)
    • Mock Firestore client
    • Test soft delete archiving (if implemented)

Related Issues

Part of Machine Service implementation
Related to API documentation in docs/content/r&d/services/machine-mgmt/delete-machine.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgoPull requests that update Go code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions