Convert find invoice endpoint from POST to GET for RESTful design
This commit is contained in:
parent
a3124ddd4a
commit
96205c13f2
@ -80,7 +80,10 @@ This is a FastAPI application for generating and managing invoices. It allows yo
|
||||
- `GET /api/v1/invoices/{invoice_id}`: Get a specific invoice by ID
|
||||
- Query parameters:
|
||||
- `fields`: Comma-separated list of fields to include in the response (e.g., "id,invoice_number,total_amount")
|
||||
- `POST /api/v1/invoices/find`: Find an invoice by invoice number
|
||||
- `GET /api/v1/invoices/find`: Find an invoice by invoice number
|
||||
- Query parameters:
|
||||
- `invoice_number`: Invoice number to search for (required)
|
||||
- `fields`: Comma-separated list of fields to include in the response (e.g., "id,invoice_number,total_amount")
|
||||
- `PATCH /api/v1/invoices/{invoice_id}`: Update an invoice
|
||||
- `PATCH /api/v1/invoices/{invoice_id}/status`: Update invoice status
|
||||
- `DELETE /api/v1/invoices/{invoice_id}`: Delete an invoice
|
||||
|
@ -11,7 +11,6 @@ from app.models.invoice import Invoice, InvoiceItem
|
||||
from app.schemas.invoice import (
|
||||
InvoiceCreate,
|
||||
InvoiceDB,
|
||||
InvoiceSearchQuery,
|
||||
InvoiceStatusUpdate,
|
||||
InvoiceUpdate,
|
||||
invoice_db_filterable,
|
||||
@ -129,17 +128,34 @@ def get_invoice(
|
||||
return invoice
|
||||
|
||||
|
||||
@router.post("/find", response_model=InvoiceDB)
|
||||
def find_invoice_by_number(query: InvoiceSearchQuery, db: Session = Depends(get_db)):
|
||||
@router.get("/find", response_model=InvoiceDB)
|
||||
def find_invoice_by_number(
|
||||
invoice_number: str,
|
||||
fields: Optional[str] = None,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
Find an invoice by its invoice number.
|
||||
|
||||
Parameters:
|
||||
- invoice_number: The invoice number to search for
|
||||
- fields: Comma-separated list of fields to include in the response (e.g., "id,invoice_number,total_amount")
|
||||
If not provided, all fields will be returned.
|
||||
"""
|
||||
invoice = db.query(Invoice).filter(Invoice.invoice_number == query.invoice_number).first()
|
||||
invoice = db.query(Invoice).filter(Invoice.invoice_number == invoice_number).first()
|
||||
if invoice is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=f"Invoice with number {query.invoice_number} not found",
|
||||
detail=f"Invoice with number {invoice_number} not found",
|
||||
)
|
||||
|
||||
# If fields parameter is provided, filter the response
|
||||
if fields:
|
||||
# Process the response to include only the specified fields
|
||||
filtered_response = invoice_db_filterable.process_response(invoice, fields)
|
||||
return JSONResponse(content=filtered_response)
|
||||
|
||||
# Otherwise, return all fields
|
||||
return invoice
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user