add(templates): base models and dto for girasol backend
Some checks failed
Deploy Girasol / deploy (push) Has been cancelled
Some checks failed
Deploy Girasol / deploy (push) Has been cancelled
This commit is contained in:
34
backend/src/news/dto.py
Normal file
34
backend/src/news/dto.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""News module DTO
|
||||
"""
|
||||
import datetime
|
||||
import uuid
|
||||
from typing import Optional
|
||||
|
||||
from sqlmodel import SQLModel
|
||||
from src.files.dto import ReadFile
|
||||
from src.news.models import BaseNews
|
||||
|
||||
|
||||
class CreateNews(BaseNews):
|
||||
"""CreateNews DTO
|
||||
"""
|
||||
hero_id: uuid.UUID
|
||||
|
||||
|
||||
class UpdateNews(SQLModel):
|
||||
"""UpdateNews DTO
|
||||
"""
|
||||
title: Optional[str] = None
|
||||
subtitle: Optional[str] = None
|
||||
long_description: Optional[dict] = None
|
||||
short_description: Optional[str] = None
|
||||
carousel: Optional[bool] = None
|
||||
banner: Optional[bool] = None
|
||||
expiry_date: Optional[datetime.datetime] = None
|
||||
|
||||
|
||||
class ReadNews(BaseNews):
|
||||
"""ReadNews DTO
|
||||
"""
|
||||
id: uuid.UUID
|
||||
hero: Optional[ReadFile] = None
|
||||
32
backend/src/news/models.py
Normal file
32
backend/src/news/models.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""News module models
|
||||
"""
|
||||
import datetime
|
||||
import uuid
|
||||
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
from sqlmodel import Field, SQLModel
|
||||
|
||||
|
||||
class BaseNews(SQLModel):
|
||||
"""Base model for a News
|
||||
|
||||
Attributes:
|
||||
"""
|
||||
title: str
|
||||
subtitle: str
|
||||
long_description: dict = Field(sa_type=JSONB, nullable=False)
|
||||
short_description: str
|
||||
carousel: bool
|
||||
banner: bool
|
||||
expiry_date: datetime.datetime
|
||||
|
||||
|
||||
class News(BaseNews, table=True):
|
||||
"""Database model representing a News
|
||||
|
||||
A plain blog post unrelated to a specific event,
|
||||
appears in the homepage carousel, as a site-wide banner or both
|
||||
"""
|
||||
id: uuid.UUID | None = Field(
|
||||
default=None, default_factory=uuid.uuid4, primary_key=True)
|
||||
hero_id: uuid.UUID = Field(foreign_key="file.id")
|
||||
Reference in New Issue
Block a user