Implement Routes for Invoices #189

Closed
opened 2026-01-19 22:27:33 +00:00 by duarteneves5 · 0 comments
duarteneves5 commented 2026-01-19 22:27:33 +00:00 (Migrated from github.com)

Implement the REST endpoints for the Invoice entity, connecting the API layer to the existing InvoiceRepo.

This module is responsible for the Snapshot Logic—locking in client, vehicle, and item details at the moment of emission. It must verify the existence of the source WorkOrder and ensure business rules (like address presence) are met before generation.

Technical Requirements:

  • File: src/routers/invoices.py
  • Prefix: /invoices
  • Tags: ["Invoices"]
  • Dependency: Inject InvoiceRepo using Depends().
  • Testing: Use AsyncMock to mock the repository layer. Do not connect to the real database.

Exception Mapping Strategy:

  • InvoiceNotFoundError -> 404 Not Found
  • ClientAddressMissingError -> 400 Bad Request (Cannot emit invoice without valid fiscal address)
  • InvoiceNumberConflictError -> 500 Internal Server Error (Should not happen with atomic counter, but handle as safety)
  • InvoiceDatabaseError -> 500 Internal Server Error

TDD Checklist:

Implement the REST endpoints for the **Invoice** entity, connecting the API layer to the existing `InvoiceRepo`. This module is responsible for the **Snapshot Logic**—locking in client, vehicle, and item details at the moment of emission. It must verify the existence of the source `WorkOrder` and ensure business rules (like address presence) are met before generation. **Technical Requirements:** - **File:** `src/routers/invoices.py` - **Prefix:** `/invoices` - **Tags:** `["Invoices"]` - **Dependency:** Inject `InvoiceRepo` using `Depends()`. - **Testing:** Use `AsyncMock` to mock the repository layer. Do not connect to the real database. **Exception Mapping Strategy:** - `InvoiceNotFoundError` -> **404 Not Found** - `ClientAddressMissingError` -> **400 Bad Request** (Cannot emit invoice without valid fiscal address) - `InvoiceNumberConflictError` -> **500 Internal Server Error** (Should not happen with atomic counter, but handle as safety) - `InvoiceDatabaseError` -> **500 Internal Server Error** **TDD Checklist:** - [x] #190 - [x] #191 - [x] #192
Sign in to join this conversation.
No description provided.