diff --git a/backend/entities/resource_entity.py b/backend/entities/resource_entity.py index 34c9ffb..d5eb75b 100644 --- a/backend/entities/resource_entity.py +++ b/backend/entities/resource_entity.py @@ -1,68 +1,72 @@ """ Defines the table for storing resources """ + # Import our mapped SQL types from SQLAlchemy from sqlalchemy import Integer, String, DateTime + # Import mapping capabilities from the SQLAlchemy ORM from sqlalchemy.orm import Mapped, mapped_column, relationship + # Import the EntityBase that we are extending from .entity_base import EntityBase + # Import datetime for created_at type from datetime import datetime + # Import enums for Program -import enum +from sqlalchemy.types import Enum from sqlalchemy import Enum -class ProgramEnum(enum.Enum): - """ Determine program for Resource """ - DOMESTIC = 'DOMESTIC' - ECONOMIC = 'ECONOMIC' - COMMUNITY = 'COMMUNITY' +# Import self for to model +from typing import Self +from programtype_enum import ProgramType -class ResourceEntity(EntityBase): - #set table name +class ResourceEntity(EntityBase): + + # set table name __tablename__ = "resource" - #set fields + # set fields id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now) name: Mapped[str] = mapped_column(String(32), nullable=False) summary: Mapped[str] = mapped_column(String(100), nullable=False) link: Mapped[str] = mapped_column(String, nullable=False) - program: Mapped[ProgramEnum] = mapped_column(Enum(ProgramEnum), nullable=False) + program: Mapped[ProgramType] = mapped_column(Enum(ProgramType), nullable=False) - #relationships - resourceTags: Mapped[list["ResourceTagEntity"]] = relationship(back_populates="resource", cascade="all,delete") + # relationships + resourceTags: Mapped[list["ResourceTagEntity"]] = relationship( + back_populates="resource", cascade="all,delete" + ) - @classmethod - def from_model(cls, model: user_model) -> Self: - """ - Create a UserEntity from a User model. + # + # @classmethod + # def from_model(cls, model: user_model) -> Self: + # """ + # Create a UserEntity from a User model. - Args: - model (User): The model to create the entity from. - - Returns: - Self: The entity (not yet persisted). - """ - - return cls ( - id = model.id - created_at = model.created_at - name = model.name - summary = model.summary - link = model.link - program = model.program - ) - - def to_model(self) -> user_model: - return user_model ( - id = self.id - created_at = self.created_at - name = self.name - summary = self.summary - link = self.link - program = self.program - ) + # Args: + # model (User): The model to create the entity from. + # Returns: + # Self: The entity (not yet persisted). + # """ + # return cls ( + # id = model.id, + # created_at = model.created_at, + # name = model.name, + # summary = model.summary, + # link = model.link, + # program = model.program, + # ) + # def to_model(self) -> user_model: + # return user_model ( + # id = self.id, + # created_at = self.created_at, + # name = self.name, + # summary = self.summary, + # link = self.link, + # program = self.program, + # ) diff --git a/backend/entities/resource_tag_entity.py b/backend/entities/resource_tag_entity.py index 3b7d198..061e17a 100644 --- a/backend/entities/resource_tag_entity.py +++ b/backend/entities/resource_tag_entity.py @@ -1,7 +1,7 @@ """ Defines the table for resource tags """ # Import our mapped SQL types from SQLAlchemy -from sqlalchemy import ForeignKey, Integer, String, DateTime, ARRAY +from sqlalchemy import ForeignKey, Integer, String, DateTime # Import mapping capabilities from the SQLAlchemy ORM from sqlalchemy.orm import Mapped, mapped_column, relationship @@ -16,6 +16,9 @@ from datetime import datetime import enum from sqlalchemy import Enum +# Import self for to model +from typing import Self + class ResourceTagEntity(EntityBase): @@ -30,3 +33,18 @@ class ResourceTagEntity(EntityBase): # relationships resource: Mapped["ResourceEntity"] = relationship(back_populates="resourceTags") tag: Mapped["TagEntity"] = relationship(back_populates="resourceTags") + + # @classmethod + # def from_model (cls, model: resource_tag_model) -> Self: + # return cls ( + # id = model.id, + # resourceId = model.resourceId, + # tagId = model.tagId, + # ) + + # def to_model (self) -> resource_tag_model: + # return user_model( + # id = self.id, + # resourceId = self.resourceId, + # tagId = self.tagId, + # ) diff --git a/backend/entities/serivce_entity.py b/backend/entities/serivce_entity.py index 4e257ec..4616d7d 100644 --- a/backend/entities/serivce_entity.py +++ b/backend/entities/serivce_entity.py @@ -16,26 +16,24 @@ from datetime import datetime import enum from sqlalchemy import Enum - -class ProgramEnum(enum.Enum): - """Determine program for Service""" - DOMESTIC = "DOMESTIC" - ECONOMIC = "ECONOMIC" - COMMUNITY = "COMMUNITY" +# Import ProgramType enumeration +from programtype_enum import ProgramType class ResourceEntity(EntityBase): - #set table name + # set table name __tablename__ = "service" - #set fields + # set fields id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now) name: Mapped[str] = mapped_column(String(32), nullable=False) summary: Mapped[str] = mapped_column(String(100), nullable=False) requirements: Mapped[list[str]] = mapped_column(ARRAY(String)) - program: Mapped[ProgramEnum] = mapped_column(Enum(ProgramEnum), nullable=False) + program: Mapped[ProgramType] = mapped_column(Enum(ProgramType), nullable=False) - #relationships - resourceTags: Mapped[list["ServiceTagEntity"]] = relationship(back_populates="service", cascade="all,delete") + # relationships + resourceTags: Mapped[list["ServiceTagEntity"]] = relationship( + back_populates="service", cascade="all,delete" + ) diff --git a/backend/entities/user_entity.py b/backend/entities/user_entity.py index c7b77f0..16c89ab 100644 --- a/backend/entities/user_entity.py +++ b/backend/entities/user_entity.py @@ -2,27 +2,28 @@ # Import our mapped SQL types from SQLAlchemy from sqlalchemy import Integer, String, DateTime, ARRAY + # Import mapping capabilities from the SQLAlchemy ORM from sqlalchemy.orm import Mapped, mapped_column + # Import the EntityBase that we are extending from .entity_base import EntityBase + # Import datetime for created_at type from datetime import datetime + # Import enums for Role and Program import enum from sqlalchemy import Enum +from programtype_enumeration import ProgramType + class RoleEnum(enum.Enum): - """ Determine role for User """ - ADMIN = 'ADMIN' - EMPLOYEE = 'EMPLOYEE' - VOLUNTEER = 'VOLUNTEER' + """Determine role for User""" -class ProgramEnum(enum.Enum): - """Determine program for User """ - DOMESTIC = 'DOMESTIC' - ECONOMIC = 'ECONOMIC' - COMMUNITY = 'COMMUNITY' + ADMIN = "ADMIN" + EMPLOYEE = "EMPLOYEE" + VOLUNTEER = "VOLUNTEER" class UserEntity(EntityBase): @@ -34,10 +35,13 @@ class UserEntity(EntityBase): # set fields or 'columns' for the user table id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now) - username: Mapped[str] = mapped_column(String(32), nullable=False, default="", unique=True) - role: Mapped[RoleEnum] = mapped_column(Enum(RoleEnum), nullable=False) + username: Mapped[str] = mapped_column( + String(32), nullable=False, default="", unique=True + ) + role: Mapped[RoleEnum] = mapped_column(Enum(RoleEnum), nullable=False) email: Mapped[str] = mapped_column(String(50), nullable=False, unique=True) - program: Mapped[list[ProgramEnum]] = mapped_column(ARRAY(Enum(ProgramEnum)), nullable=False) + program: Mapped[list[ProgramType]] = mapped_column( + ARRAY(Enum(ProgramType)), nullable=False + ) experience: Mapped[int] = mapped_column(Integer, nullable=False) group: Mapped[str] = mapped_column(String(50)) -