Refactor models and endpoints, add logging, and improve error handling.

This commit is contained in:
Esa Kataja
2024-12-01 22:29:00 +02:00
parent cecd9a4458
commit b5e693ab9f
8 changed files with 174 additions and 77 deletions
+24 -28
View File
@@ -1,44 +1,40 @@
from pydantic import BaseModel, Field
from datetime import datetime
from datetime import datetime, date
from typing import Optional
class Movie(BaseModel):
id: Optional[str] = Field(
default=None, examples=["123e4567-e89b-12d3-a456-426655440000"]
)
name: str = Field(
description="Name of the movie", examples=["A Maple Valley Christmas"]
class MovieBase(BaseModel):
name: Optional[str] | None = Field(
None, description="Name of the movie", examples=["A Maple Valley Christmas"]
)
imdb_id: str = Field(description="IMDB ID of the movie", examples=["tt1234567"])
actors: list[str] = Field(
description="Actors of the movie",
examples=[["Peyton List", "Andrew W. Walker"]],
)
showtime: date = Field(description="Showtime of the movie", examples=["2024-12-01"])
plot: str = Field(
description="Plot of the movie", examples=["Erica is a rancher..."]
)
release_date: datetime = Field(
description="Release date of the movie", examples=["2022-11-05"]
class MovieIn(MovieBase):
actors: Optional[list[str]] | None = Field(
None,
description="Actors of the movie",
examples=[["Peyton List", "Andrew W. Walker"]],
)
poster_url: str = Field(
description="Poster URL of the movie", examples=["https://..."]
release_date: datetime | None = Field(
None, description="Release date of the movie", examples=["2022-11-05"]
)
showtime: datetime = Field(
description="Showtime of the movie", examples=["2024-12-01"]
poster_url: str | None = Field(
None, description="Poster URL of the movie", examples=["https://..."]
)
is_watched: bool = Field(
default=False,
description="Whether the movie is watched or not",
examples=[True],
class Movie(MovieIn):
id: Optional[str] = Field(
default=None, examples=["123e4567-e89b-12d3-a456-426655440000"]
)
created_at: datetime = Field(
default_factory=datetime.utcnow,
description="Creation date of the movie",
examples=[datetime.utcnow()],
default_factory=datetime.utcnow, description="Creation date of the movie"
)
updated_at: datetime = Field(
default_factory=datetime.utcnow,
description="Modification date of the movie",
examples=[datetime.utcnow()],
modified_at: datetime = Field(
default_factory=datetime.utcnow, description="Modification date of the movie"
)