Auth guards vary by endpoint — Create, Update, Delete are admin-only. Get and List accept both JWT users (active benefits only) and the admin key (all benefits).

Overview

A benefit is a specific offering — a free consultation, an insurance policy, a diagnostic test — provided by a Benefit Provider. Benefits carry a benefit_type enum and a benefit_details JSONB block whose variant must match the type. Responses always include provider_name via a JOIN — callers never need a separate provider lookup.

Benefit Types

benefit_typebenefit_details variantDescription
consultationConsultation { description }Free or subsidised doctor consultation
insurance_policyInsurancePolicy { description }Health or accident insurance
Type and details must be consistent — mismatches return BE-503.

Visibility by Actor


Auth Guards by Endpoint

EndpointJWT userAdmin keyNotes
POST /benefitsProvider must be active
GET /benefits✓ active only✓ all
GET /benefits/{id}✓ active only✓ all
PATCH /benefits/{id}
DELETE /benefits/{id}Sets status → inactive

Endpoints

POST /benefits

Admin only. Create a benefit. Provider must exist and be active.

GET /benefits

List benefits. JWT users see only active ones. Filter by provider_id, benefit_type, status.

GET /benefits/{benefit_id}

Fetch a benefit by UUID. JWT users receive 404 for inactive benefits.

PATCH /benefits/{benefit_id}

Admin only. Update name, benefit_details, or status.

DELETE /benefits/{benefit_id}

Admin only. Soft-delete (status → inactive).

Request / Response Examples

curl -X POST http://localhost:8080/benefits \
  -H 'Authorization: Bearer eyJhbGci...admin-jwt...' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "Free GP Consultation",
    "benefit_type": "CONSULTATION",
    "provider_id": "018f4c2a-1b3e-7d8f-9a0b-2c3d4e5f6a7b",
    "benefit_details": {
      "type": "Consultation",
      "description": "One free general physician consultation per month"
    }
  }'

Error Codes

CodeHTTPDescription
BE-500500Internal server error
BE-501404Benefit not found
BE-502409Name already exists for this provider
BE-503400benefit_type / benefit_details type mismatch
BE-504404Benefit provider not found or inactive
BE-505400Validation error (e.g. empty name)