From b3a4c45202f8bb3d501ce49247416dc56edf36b1 Mon Sep 17 00:00:00 2001 From: Felipe Cardoso Date: Wed, 5 Mar 2025 12:42:00 +0100 Subject: [PATCH] Add event themes API routes for CRUD operations Implemented API endpoints for creating, reading, updating, and listing event themes. Integrated the new routes into the FastAPI application router under the '/event_themes' prefix. --- backend/app/api/main.py | 3 +- backend/app/api/routes/event_themes.py | 68 +++++++++++++++++++++++ backend/app/api/routes/events/__init__.py | 0 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 backend/app/api/routes/event_themes.py create mode 100644 backend/app/api/routes/events/__init__.py diff --git a/backend/app/api/main.py b/backend/app/api/main.py index 6b6f08f..412bdb3 100644 --- a/backend/app/api/main.py +++ b/backend/app/api/main.py @@ -1,6 +1,7 @@ from fastapi import APIRouter from app.api.routes import auth - +from app.api.routes import event_themes api_router = APIRouter() api_router.include_router(auth.router, prefix="/auth", tags=["auth"]) +api_router.include_router(event_themes.router, prefix="/event_themes", tags=["event_themes"]) diff --git a/backend/app/api/routes/event_themes.py b/backend/app/api/routes/event_themes.py new file mode 100644 index 0000000..ddfdcb0 --- /dev/null +++ b/backend/app/api/routes/event_themes.py @@ -0,0 +1,68 @@ +# app/api/v1/themes/router.py +from typing import List +from uuid import UUID + +from fastapi import APIRouter, Depends, HTTPException, status +from sqlalchemy.orm import Session + +from app.core.database import get_db +from app.crud.event_theme import event_theme +from app.schemas.event_theme import EventThemeCreate, EventThemeResponse, EventThemeUpdate + +router = APIRouter() + + +@router.post("/", response_model=EventThemeResponse) +def create_theme( + *, + db: Session = Depends(get_db), + theme_in: EventThemeCreate +) -> EventThemeResponse: + """Create new event theme.""" + theme = event_theme.create(db, obj_in=theme_in) + print(theme) + return theme + + +@router.get("/", response_model=List[EventThemeResponse]) +def list_themes( + db: Session = Depends(get_db), + skip: int = 0, + limit: int = 100 +) -> List[EventThemeResponse]: + """List event themes.""" + themes = event_theme.get_multi(db, skip=skip, limit=limit) + return themes + + +@router.get("/{theme_id}", response_model=EventThemeResponse) +def get_theme( + *, + db: Session = Depends(get_db), + theme_id: UUID +) -> EventThemeResponse: + """Get specific theme by ID.""" + theme = event_theme.get(db, id=theme_id) + if not theme: + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, + detail="Theme not found" + ) + return theme + +@router.patch("/{theme_id}", response_model=EventThemeResponse) +def update_theme( + *, + db: Session = Depends(get_db), + theme_id: UUID, + theme_in: EventThemeUpdate +) -> EventThemeResponse: + """Update specific theme by ID.""" + theme = event_theme.get(db, id=theme_id) + if not theme: + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, + detail="Theme not found" + ) + theme = event_theme.update(db, db_obj=theme, obj_in=theme_in) + return theme diff --git a/backend/app/api/routes/events/__init__.py b/backend/app/api/routes/events/__init__.py new file mode 100644 index 0000000..e69de29