Add CRUD operations and tests for EventTheme management
All checks were successful
Build and Push Docker Images / changes (push) Successful in 5s
Build and Push Docker Images / build-backend (push) Successful in 51s
Build and Push Docker Images / build-frontend (push) Has been skipped

Introduced CRUD implementation, schema definitions, and tests for EventTheme. This allows creation, retrieval, updating, deletion, and querying of active event themes. Comprehensive tests ensure functionality works as intended, including edge cases for nonexistent themes.
This commit is contained in:
2025-03-05 11:43:14 +01:00
parent d0bcb77438
commit 658ef1c7c2
3 changed files with 180 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
from typing import List, Optional
from sqlalchemy.orm import Session
from app.crud.base import CRUDBase
from app.models.event_theme import EventTheme
from app.schemas.event_theme import EventThemeCreate, EventThemeUpdate
class CRUDEventTheme(CRUDBase[EventTheme, EventThemeCreate, EventThemeUpdate]):
def get_by_name(self, db: Session, *, name: str) -> Optional[EventTheme]:
return db.query(EventTheme).filter(EventTheme.name == name).first()
def get_active_themes(
self, db: Session, *, skip: int = 0, limit: int = 100
) -> List[EventTheme]:
return (
db.query(self.model)
.filter(self.model.events.any())
.offset(skip)
.limit(limit)
.all()
)
event_theme = CRUDEventTheme(EventTheme)

View File

@@ -0,0 +1,31 @@
from typing import Dict, Optional
from pydantic import BaseModel
class EventThemeBase(BaseModel):
name: str
description: Optional[str] = None
preview_image_url: Optional[str] = None
color_palette: Dict[str, str]
fonts: Dict[str, str]
class EventThemeCreate(EventThemeBase):
pass
class EventThemeUpdate(EventThemeBase):
name: Optional[str] = None
color_palette: Optional[Dict[str, str]] = None
fonts: Optional[Dict[str, str]] = None
class EventThemeInDBBase(EventThemeBase):
id: str
class Config:
from_attributes = True
class EventTheme(EventThemeInDBBase):
pass