From 51270134eb2516dec34aa3b7f7235e511f766f43 Mon Sep 17 00:00:00 2001 From: Warren Quadland <59710771+wquadland@users.noreply.github.com> Date: Sun, 26 Mar 2023 16:51:43 -0400 Subject: [PATCH] Add post entity (#13) Add post entity --- backend/entities/post_entity.py | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 backend/entities/post_entity.py diff --git a/backend/entities/post_entity.py b/backend/entities/post_entity.py new file mode 100644 index 0000000..f1b8546 --- /dev/null +++ b/backend/entities/post_entity.py @@ -0,0 +1,47 @@ +'''User accounts for all registered users in the application.''' + + +from sqlalchemy import Integer, String +from sqlalchemy.orm import Mapped, mapped_column, relationship +from typing import Self +from .entity_base import EntityBase +from .user_role_entity import user_role_table +from ..models import User +from ..models import Post + + +__authors__ = ['Kris Jordan'] +__copyright__ = 'Copyright 2023' +__license__ = 'MIT' + + +class PostEntity(EntityBase): + __tablename__ = 'user' + + id: Mapped[int] = mapped_column(Integer, primary_key=True) + content: Mapped[str] = mapped_column(String(64), nullable=False, default='') + user: Mapped[User] = mapped_column(User, nullable=False, default='') + votes: Mapped[list[User]] + timestamp: Mapped[str] = mapped_column(String(64), nullable=False, default='') + + @classmethod + def from_model(cls, model: Post) -> Self: + return cls( + id=model.id, + content=model.content, + user=model.user, + votes=model.votes, + timestamp=model.timestamp, + ) + + def to_model(self) -> Post: + return Post( + id=self.id, + content=self.content, + user=self.user, + votes=self.votes, + timestamp=self.timestamp, + ) + + def update(self, model: Post) -> None: + self.content = model.content