diff --git a/backend/entities/__init__.py b/backend/entities/__init__.py index 4191027..c7df32e 100644 --- a/backend/entities/__init__.py +++ b/backend/entities/__init__.py @@ -1,2 +1,3 @@ from .entity_base import EntityBase from .sample_entity import SampleEntity +from .program_enum import ProgramEnum diff --git a/backend/entities/program_enum.py b/backend/entities/program_enum.py new file mode 100644 index 0000000..9876ee8 --- /dev/null +++ b/backend/entities/program_enum.py @@ -0,0 +1,10 @@ +from sqlalchemy.orm import Enum + + +class ProgramEnum(Enum): + ECONOMIC = "economic" + DOMESTIC = "domestic" + COMMUNITY = "community" + + def __init__(self): + super().__init__(name="program_enum") diff --git a/backend/entities/resource_entity.py b/backend/entities/resource_entity.py index 4adea78..b38e625 100644 --- a/backend/entities/resource_entity.py +++ b/backend/entities/resource_entity.py @@ -1,38 +1,68 @@ """ 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 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 backend.entities.program_enum import ProgramEnum -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[ProgramEnum] = mapped_column(ProgramEnum, 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. + # 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..bab1781 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 @@ -12,9 +12,8 @@ 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 +# Import self for to model +from typing import Self class ResourceTagEntity(EntityBase): @@ -30,3 +29,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..f9c2575 100644 --- a/backend/entities/serivce_entity.py +++ b/backend/entities/serivce_entity.py @@ -12,30 +12,24 @@ from .entity_base import EntityBase # Import datetime for created_at type from datetime import datetime -# Import enums for Program -import enum -from sqlalchemy import Enum - - -class ProgramEnum(enum.Enum): - """Determine program for Service""" - DOMESTIC = "DOMESTIC" - ECONOMIC = "ECONOMIC" - COMMUNITY = "COMMUNITY" +# Import ProgramType enumeration +from backend.entities.program_enum import ProgramEnum 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[ProgramEnum] = mapped_column(ProgramEnum, 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..3dbc107 100644 --- a/backend/entities/user_entity.py +++ b/backend/entities/user_entity.py @@ -2,27 +2,19 @@ # 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 - -class RoleEnum(enum.Enum): - """ Determine role for User """ - ADMIN = 'ADMIN' - EMPLOYEE = 'EMPLOYEE' - VOLUNTEER = 'VOLUNTEER' - -class ProgramEnum(enum.Enum): - """Determine program for User """ - DOMESTIC = 'DOMESTIC' - ECONOMIC = 'ECONOMIC' - COMMUNITY = 'COMMUNITY' +from backend.entities.program_enum import ProgramEnum +from user_enum import RoleEnum class UserEntity(EntityBase): @@ -34,10 +26,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(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[ProgramEnum]] = mapped_column( + ARRAY(ProgramEnum), nullable=False + ) experience: Mapped[int] = mapped_column(Integer, nullable=False) group: Mapped[str] = mapped_column(String(50)) - diff --git a/backend/entities/user_enum.py b/backend/entities/user_enum.py new file mode 100644 index 0000000..9ee1779 --- /dev/null +++ b/backend/entities/user_enum.py @@ -0,0 +1,12 @@ +from sqlalchemy.orm import Enum + + +class RoleEnum(Enum): + """Determine role for User""" + + ADMIN = "ADMIN" + EMPLOYEE = "EMPLOYEE" + VOLUNTEER = "VOLUNTEER" + + def __init__(self): + super().__init__(name="role_enum")