Skip to content

feat(life-events-api): implement Biotrackr.LifeEvents.Api service #314

@willvelida

Description

@willvelida

Phase 1 of #313

Create a new Biotrackr.LifeEvents.Api domain API service — the first domain API with write endpoints (POST/PUT/DELETE). Follows the Food.Api pattern as the cleanest existing template.

PR Scope

src/Biotrackr.LifeEvents.Api/ (new service — app + unit tests + integration tests)

Steps

  • Step 1.1: Scaffold solution and project structure (.sln, 3 .csproj, coverage.runsettings)
  • Step 1.2: Implement data models (LifeEventDocument, CreateLifeEventRequest, UpdateLifeEventRequest, PaginationRequest, LifeEventCategory)
  • Step 1.3: Implement repository (read with interval overlap queries + write with CreateItemAsync/ReplaceItemAsync/DeleteItemAsync)
  • Step 1.4: Implement endpoint handlers and LifeEventValidator (ASI01 prompt injection scanning on Description/Notes)
  • Step 1.5: Implement extensions (ServiceCollectionExtensions.AddCosmosDb(), EndpointRouteBuilderExtensions)
  • Step 1.6: Implement Program.cs with rate limiting (30 writes/min) and 64KB request body size limit
  • Step 1.7: Create Dockerfile and .dockerignore
  • Step 1.8: Create unit test project
  • Step 1.9: Implement LifeEventsHandlersShould tests (read + write + validation + injection scanning)
  • Step 1.10: Implement CosmosRepositoryShould tests
  • Step 1.11: Implement model and extension tests (LifeEventCategoryShould, PaginationRequestShould, etc.)
  • Step 1.12: Create integration test project with fixtures (WebApplicationFactory, ContractTestFixture, IntegrationTestFixture)
  • Step 1.13: Implement contract tests (ApiSmokeTests, ProgramStartupTests)
  • Step 1.14: Implement E2E tests (CRUD lifecycle, multi-day event overlap queries)
  • Step 1.15: Validate — build, run all tests, verify ≥70% coverage

API Endpoints

Route Method Handler Returns
GET / GET GetAllLifeEvents Ok<PaginationResponse<LifeEventDocument>>
GET /{date} GET GetLifeEventsByDate BadRequest | Ok<PaginationResponse<LifeEventDocument>>
GET /range/{startDate}/{endDate} GET GetLifeEventsByDateRange BadRequest | Ok<PaginationResponse<LifeEventDocument>>
POST / POST CreateLifeEvent BadRequest | Created<LifeEventDocument>
PUT /{id} PUT UpdateLifeEvent BadRequest | NotFound | Ok<LifeEventDocument>
DELETE /{id} DELETE DeleteLifeEvent NotFound | NoContent

Acceptance Criteria

  • Solution builds with 3 projects (app, unit tests, integration tests)
  • Unit tests pass with ≥70% line coverage
  • Contract tests verify DI registration and endpoint accessibility
  • Write endpoints include input validation and rate limiting
  • LifeEventValidator scans Description/Notes for prompt injection patterns (ASI01)
  • Interval overlap queries correctly handle multi-day events

Details

.copilot-tracking/details/2026-04-23/life-events-feature-details.md — Phase 1 (Steps 1.1–1.15)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions