feat: Refactor API structure and implement core functionalities
- Updated requirements to include asyncpg, pyyaml, aiofiles, and httpx. - Modified schema.sql to add 'tipo_pasto' column in 'pasti' table. - Created .gitignore file to exclude unnecessary files and directories. - Added README.md for API implementation details and directory structure. - Introduced config.yaml for centralized configuration management. - Implemented core modules for database management, authentication, and exception handling. - Developed models for 'pietanze', 'pasti', and 'prenotazioni' with validation. - Created routes for CRUD operations on 'pietanze' with pagination and filtering. - Established logging and error handling mechanisms throughout the application. - Set up FastAPI application with CORS and health check endpoint.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
from pydantic import BaseModel, Field, validator
|
||||
from typing import List, Optional
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
|
||||
class StatoPrenotazione(str, Enum):
|
||||
attiva = "attiva"
|
||||
servita = "servita"
|
||||
pagata = "pagata"
|
||||
annullata = "annullata"
|
||||
completata = "completata"
|
||||
|
||||
class PrenotazioneBase(BaseModel):
|
||||
pasto_id: int
|
||||
pietanze_selezionate: List[int] = Field(
|
||||
description="Lista ID delle pietanze selezionate"
|
||||
)
|
||||
note: Optional[str] = Field(None, max_length=500)
|
||||
stato: StatoPrenotazione = StatoPrenotazione.attiva
|
||||
|
||||
@validator('pietanze_selezionate')
|
||||
def validate_pietanze_selezionate(cls, v):
|
||||
if not v or len(v) == 0:
|
||||
raise ValueError("Almeno una pietanza deve essere selezionata")
|
||||
# Check for duplicates
|
||||
if len(v) != len(set(v)):
|
||||
raise ValueError("Non sono ammesse pietanze duplicate")
|
||||
# Validate each ID
|
||||
for pietanza_id in v:
|
||||
if not isinstance(pietanza_id, int) or pietanza_id <= 0:
|
||||
raise ValueError(f"ID pietanza non valido: {pietanza_id}")
|
||||
return v
|
||||
|
||||
class PrenotazioneCreate(PrenotazioneBase):
|
||||
# user_id will be extracted from JWT token
|
||||
pass
|
||||
|
||||
class PrenotazioneUpdate(BaseModel):
|
||||
pietanze_selezionate: Optional[List[int]] = None
|
||||
note: Optional[str] = Field(None, max_length=500)
|
||||
stato: Optional[StatoPrenotazione] = None
|
||||
|
||||
@validator('pietanze_selezionate')
|
||||
def validate_pietanze_selezionate(cls, v):
|
||||
if v is None:
|
||||
return v
|
||||
if len(v) == 0:
|
||||
raise ValueError("Almeno una pietanza deve essere selezionata")
|
||||
if len(v) != len(set(v)):
|
||||
raise ValueError("Non sono ammesse pietanze duplicate")
|
||||
for pietanza_id in v:
|
||||
if not isinstance(pietanza_id, int) or pietanza_id <= 0:
|
||||
raise ValueError(f"ID pietanza non valido: {pietanza_id}")
|
||||
return v
|
||||
|
||||
class PrenotazioneResponse(PrenotazioneBase):
|
||||
id: int
|
||||
user_id: str
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
Reference in New Issue
Block a user