Skip to content

Commit

Permalink
#22: feat: add new field to the FilmReview - created_at
Browse files Browse the repository at this point in the history
  • Loading branch information
ReznikovRoman committed Jul 9, 2022
1 parent 44f99c2 commit d111980
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/ugc/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ class FilmReviewDetail(Schema):
film_id = fields.UUID()
title = fields.Str()
review = fields.Str()
created_at = fields.DateTime()
4 changes: 3 additions & 1 deletion src/ugc/domain/reviews/factories.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime

from ..factories import BaseModelFactory
from .types import FilmReview

Expand All @@ -10,5 +12,5 @@ class FilmReviewFactory(BaseModelFactory[FilmReview]):
def create_new(self, **kwargs) -> FilmReview:
return self.cls(
user_id=kwargs["user_id"], film_id=kwargs["film_id"],
title=kwargs["title"], review=kwargs["review"],
title=kwargs["title"], review=kwargs["review"], created_at=datetime.datetime.now(),
)
6 changes: 4 additions & 2 deletions src/ugc/domain/reviews/types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
from typing import Any
from uuid import UUID

Expand All @@ -11,14 +12,15 @@ class FilmReview(BaseModel):
film_id: UUID
title: str
review: str
created_at: datetime.datetime

id: bytes | str | None = None # noqa: VNE003

@classmethod
def from_dict(cls, data: dict) -> "FilmReview":
dct = {
"user_id": data["user_id"], "film_id": data["film_id"],
"title": data["title"], "review": data["review"],
"title": data["title"], "review": data["review"], "created_at": data["created_at"],
}
if review_id := data.get("id"):
dct["id"] = review_id
Expand All @@ -27,7 +29,7 @@ def from_dict(cls, data: dict) -> "FilmReview":
def to_dict(self) -> dict[str, Any]:
dct = {
"user_id": str(self.user_id), "film_id": str(self.film_id),
"title": self.title, "review": self.review,
"title": self.title, "review": self.review, "created_at": self.created_at,
}
if self.id:
dct["id"] = str(self.id)
Expand Down

0 comments on commit d111980

Please sign in to comment.