Add RSVP routes and integrate with events API router
Some checks failed
Build and Push Docker Images / build-frontend (push) Blocked by required conditions
Build and Push Docker Images / changes (push) Successful in 4s
Build and Push Docker Images / build-backend (push) Has been cancelled

This commit introduces a new RSVP module with endpoints for creating, reading, updating, and deleting RSVPs, along with a custom status update endpoint. The router is integrated into the events API, providing full RSVP management capabilities. Validation and error handling have been implemented to ensure data consistency.
This commit is contained in:
2025-03-15 02:25:32 +01:00
parent 632a762d64
commit 85eed0eac0
2 changed files with 92 additions and 1 deletions

View File

@@ -22,11 +22,12 @@ from app.schemas.events import (
)
from app.api.routes.events import guests
from app.api.routes.events import rsvps
logger = logging.getLogger(__name__)
events_router = APIRouter()
events_router.include_router(guests.router, prefix="/guests", tags=["guests"])
events_router.include_router(rsvps.router, prefix="/rsvps", tags=["rsvps"])
def validate_event_access(
*,

View File

@@ -0,0 +1,90 @@
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from typing import List
from uuid import UUID
from app.core.database import get_db
from app.schemas.rsvp import RSVPSchema, RSVPSchemaCreate, RSVPSchemaUpdate
from app.crud.rsvp import crud_rsvp
router = APIRouter()
@router.post("/", response_model=RSVPSchema, operation_id="create_rsvp")
def create_rsvp(
rsvp_in: RSVPSchemaCreate,
db: Session = Depends(get_db)
):
# First, check if RSVP already exists to prevent duplicates
existing_rsvp = crud_rsvp.get_rsvp_by_event_and_guest(
db, event_id=rsvp_in.event_id, guest_id=rsvp_in.guest_id
)
if existing_rsvp:
raise HTTPException(
status_code=400, detail="RSVP already exists for this event and guest"
)
rsvp = crud_rsvp.create(db=db, obj_in=rsvp_in)
return rsvp
@router.get("/{rsvp_id}", response_model=RSVPSchema, operation_id="get_rsvp")
def read_rsvp(rsvp_id: UUID, db: Session = Depends(get_db)):
rsvp = crud_rsvp.get(db=db, id=str(rsvp_id))
if not rsvp:
raise HTTPException(status_code=404, detail="RSVP not found")
return rsvp
@router.get("/", response_model=List[RSVPSchema], operation_id="get_rsvps")
def read_rsvps(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
rsvps = crud_rsvp.get_multi(db=db, skip=skip, limit=limit)
return rsvps
@router.put("/{rsvp_id}", response_model=RSVPSchema, operation_id="update_rsvp")
def update_rsvp(
rsvp_id: UUID, rsvp_in: RSVPSchemaUpdate, db: Session = Depends(get_db)
):
rsvp = crud_rsvp.get(db, id=str(rsvp_id))
if not rsvp:
raise HTTPException(status_code=404, detail="RSVP not found")
updated_rsvp = crud_rsvp.update(db, db_obj=rsvp, obj_in=rsvp_in)
return updated_rsvp
@router.delete("/{rsvp_id}", response_model=RSVPSchema, operation_id="delete_rsvp")
def delete_rsvp(rsvp_id: UUID, db: Session = Depends(get_db)):
rsvp = crud_rsvp.get(db, id=str(rsvp_id))
if not rsvp:
raise HTTPException(status_code=404, detail="RSVP not found")
rsvp = crud_rsvp.remove(db, id=str(rsvp_id))
return rsvp
@router.patch("/{rsvp_id}/status", response_model=RSVPSchema, operation_id="update_rsvp_status")
def update_rsvp_status(
rsvp_id: UUID,
status: RSVPSchemaUpdate,
db: Session = Depends(get_db)
):
rsvp = crud_rsvp.get(db, id=str(rsvp_id))
if not rsvp:
raise HTTPException(status_code=404, detail="RSVP not found")
# Validation of provided fields specifically for status update
if not status.status:
raise HTTPException(status_code=400, detail="Status field required for update.")
updated_rsvp = crud_rsvp.update_rsvp_status(
db,
db_obj=rsvp,
status=status.status,
number_of_guests=status.number_of_guests,
response_message=status.response_message,
dietary_requirements=status.dietary_requirements,
additional_info=status.additional_info
)
return updated_rsvp