d5705c3a28
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
Co-authored-by: Thomas Peetz <thomas.peetz@cimt-ag.de> Reviewed-on: #98
68 lines
1.7 KiB
Python
68 lines
1.7 KiB
Python
from datetime import datetime
|
|
|
|
from pydantic import BaseModel
|
|
|
|
from src.db.models.media import MediaLofi
|
|
|
|
class MediaLofiResponse(BaseModel):
|
|
id: str
|
|
created_date: datetime
|
|
last_modified_date: datetime
|
|
version: int
|
|
title: str = ""
|
|
file_name: str = ""
|
|
url: str = ""
|
|
review: bool = False
|
|
should_download: bool = False
|
|
|
|
class AddLofi(BaseModel):
|
|
url: str
|
|
|
|
class MediaLofiModel(BaseModel):
|
|
"""
|
|
Pydantic Model to import MediaLofi.
|
|
"""
|
|
id: str
|
|
created_date: datetime
|
|
last_modified_date: datetime
|
|
version: int = 0
|
|
title: str = ""
|
|
file_name: str = ""
|
|
url: str = ""
|
|
review: bool = False
|
|
should_download: bool = False
|
|
|
|
|
|
def lofi_to_model(model: MediaLofiResponse, medialofi: MediaLofi) -> MediaLofi:
|
|
"""
|
|
Set data of response to model
|
|
"""
|
|
medialofi.file_name = model.file_name
|
|
if model.url is not None:
|
|
medialofi.url = model.url
|
|
else:
|
|
medialofi.url = ""
|
|
if model.title is not None:
|
|
medialofi.title = model.title
|
|
else:
|
|
medialofi.title = ""
|
|
medialofi.last_modified_date = datetime.now()
|
|
medialofi.review = model.review
|
|
medialofi.should_download = model.should_download
|
|
return medialofi
|
|
|
|
|
|
def lofi_to_response(lofi: MediaLofi) -> MediaLofiResponse:
|
|
response: MediaLofiResponse = MediaLofiResponse(
|
|
id=lofi.id,
|
|
created_date=lofi.created_date,
|
|
last_modified_date=lofi.last_modified_date,
|
|
version=lofi.version,
|
|
file_name=str(lofi.file_name),
|
|
review=bool(lofi.review),
|
|
should_download=bool(lofi.should_download),
|
|
title=str(lofi.title),
|
|
url=str(lofi.url),
|
|
)
|
|
return response
|