endpoints - add SQLAlchemy models for RSVPS and singleton invitation configuration - implement phone number normalization (10d Colombia standard) and duplicate detection - add Authelia Remote-User security guard on all admin endpoints - use typing.Annotated for FastAPI dependencies and date.fromisoformat - add CSV export for RSVP responses - add SPA catch-all mount under /birthday/ - add linting and static check configuration
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Depends, status
|
|
from fastapi.responses import JSONResponse
|
|
from sqlalchemy.exc import SQLAlchemyError
|
|
from sqlalchemy.orm import Session
|
|
|
|
from ..database import get_db
|
|
from ..schemas import RSVPCreate
|
|
from ..services.rsvp import create_rsvp
|
|
|
|
router = APIRouter(tags=["RSVP"])
|
|
|
|
DbDep = Annotated[Session, Depends(get_db)]
|
|
|
|
|
|
@router.post("/rsvp", status_code=status.HTTP_201_CREATED)
|
|
def submit_rsvp(rsvp_in: RSVPCreate, db: DbDep):
|
|
try:
|
|
result_status, new_rsvp = create_rsvp(db, rsvp_in)
|
|
if result_status == "DUPLICATE":
|
|
return JSONResponse(
|
|
status_code=status.HTTP_409_CONFLICT,
|
|
content={"result": "DUPLICATE"},
|
|
)
|
|
assert new_rsvp is not None
|
|
return JSONResponse(
|
|
status_code=status.HTTP_201_CREATED,
|
|
content={"result": "SUCCESS", "name": new_rsvp.name},
|
|
)
|
|
except ValueError as e:
|
|
return JSONResponse(
|
|
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
|
content={"result": "VALIDATION_ERROR", "errors": {"phone": str(e)}},
|
|
)
|
|
except SQLAlchemyError:
|
|
return JSONResponse(
|
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
content={"result": "ERROR"},
|
|
)
|