Files
eventspace/backend/app/api/routes/event_themes.py
Felipe Cardoso cbcd04d8e1 Rename schema and test files for consistency
Renamed `event_theme` and `test_user_schema` file paths and imports to follow consistent plural naming conventions. This improves code clarity and aligns file and import naming across the project.
2025-03-05 12:48:18 +01:00

69 lines
1.9 KiB
Python

# 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_themes 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