Skip to content
Snippets Groups Projects
Select Git revision
  • 58f93eae7980ec02643c52e335155a2bd6b2c041
  • main default
2 results

schemas.py

Blame
  • schemas.py 2.25 KiB
    """
    Pydantic schemas for the magasin app
    """
    from typing import Optional
    from datetime import datetime, timedelta
    from pydantic import BaseModel, Field
    
    
    class RecordBase(BaseModel):
        """Records base schema"""
        place: str = Field(..., title="Name of the RU corresponding the given record")
        date: datetime = Field(..., title="Date of the record")
        density: float = Field(..., title="Estimated density of people")
        waiting_time: Optional[timedelta] = Field(title="Estimated waiting time for people coming at this date")
    
    
    class Record(RecordBase):
        """Database records base schema"""
        id: int
    
        class Config:
            orm_mode = True
    
    
    class CommentBase(BaseModel):
        """Comments base schema"""
        comment: str = Field(..., title="Content of the comment posted")
    
    
    class Comment(CommentBase):
        """Database comments base schema"""
        id: int
        date: datetime = Field(..., title="Publication date of the comment")
        place: str = Field(..., title="Name of the RU corresponding the comment")
    
        class Config:
            orm_mode = True
    
    
    class NewsBase(BaseModel):
        """News sql table model"""
        title: str = Field(..., title="Title of the news")
        content: str = Field(..., title="Content of the news")
        end_date: datetime = Field(..., title="End date to display the news")
        place: str = Field(..., title="Name of the RU corresponding the news")
    
    
    class News(NewsBase):
        """Database news base schema"""
        id: int
        published_at: datetime = Field(..., title="Publication date of the news")
    
        class Config:
            orm_mode = True
    
    
    class OpeningHoursBase(BaseModel):
        """Database opening_hours base schema"""
        place: str = Field(..., title="Name of the RU corresponding the given record")
        day: int = Field(..., title="Day of the week")
        timeslot: bool = Field(..., title="Service slot (True for midday, False for evening)")
        open_hour: int = Field(..., title="Hour of the opening time")
        open_minute: int = Field(..., title="Minute of the opening time")
        close_hour: int = Field(..., title="Hour of the closing time")
        close_minute: int = Field(..., title="Minute of the closing time")
    
    
    class OpeningHours(OpeningHoursBase):
        """Database opening_hours base schema"""
        id: int
    
        class Config:
            orm_mode = True