- examples/fixture-invoicing/: FastAPI + Vue + Postgres demo (4-entity invoice fixture)
- cfg/sample/: wraps the fixture (managed.repos points at examples/)
- ctrl/kind-{up,down,status}.sh + per-room k8s render in soleprint/ctrl/k8s/
- build.py: relative repo paths, resilient rmtree, optional k8s render hook
- cfg/.gitignore: stop ignoring sample/ and standalone/ template rooms
Manifests render cleanly but kind cluster has not been run end-to-end yet.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlalchemy.orm import Session
|
|
|
|
from db import get_session
|
|
from models import Customer
|
|
from schemas import CustomerIn, CustomerOut
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("", response_model=list[CustomerOut])
|
|
def list_customers(session: Session = Depends(get_session)):
|
|
return session.query(Customer).order_by(Customer.id).all()
|
|
|
|
|
|
@router.post("", response_model=CustomerOut, status_code=201)
|
|
def create_customer(payload: CustomerIn, session: Session = Depends(get_session)):
|
|
customer = Customer(**payload.model_dump())
|
|
session.add(customer)
|
|
session.commit()
|
|
session.refresh(customer)
|
|
return customer
|
|
|
|
|
|
@router.get("/{customer_id}", response_model=CustomerOut)
|
|
def get_customer(customer_id: int, session: Session = Depends(get_session)):
|
|
customer = session.get(Customer, customer_id)
|
|
if not customer:
|
|
raise HTTPException(404, "customer not found")
|
|
return customer
|
|
|
|
|
|
@router.put("/{customer_id}", response_model=CustomerOut)
|
|
def update_customer(
|
|
customer_id: int, payload: CustomerIn, session: Session = Depends(get_session)
|
|
):
|
|
customer = session.get(Customer, customer_id)
|
|
if not customer:
|
|
raise HTTPException(404, "customer not found")
|
|
for k, v in payload.model_dump().items():
|
|
setattr(customer, k, v)
|
|
session.commit()
|
|
session.refresh(customer)
|
|
return customer
|
|
|
|
|
|
@router.delete("/{customer_id}", status_code=204)
|
|
def delete_customer(customer_id: int, session: Session = Depends(get_session)):
|
|
customer = session.get(Customer, customer_id)
|
|
if not customer:
|
|
raise HTTPException(404, "customer not found")
|
|
session.delete(customer)
|
|
session.commit()
|