Merge pull request #21 from cssgunc/emmafoster-GEN-95-wip

Emmafoster gen 95 wip
This commit is contained in:
emmalynfoster 2024-03-25 19:58:51 -04:00 committed by GitHub
commit 032e943a92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 116 additions and 14 deletions

View File

@ -1,3 +1,10 @@
from .entity_base import EntityBase
from .sample_entity import SampleEntity
from .tag_entity import TagEntity
from .user_entity import UserEntity
from .resource_entity import ResourceEntity
from .resource_tag_entity import ResourceTagEntity
from .service_entity import ServiceEntity
from .service_tag_entity import ServiceTagEntity
from .program_enum import ProgramEnum
from .user_enum import RoleEnum

View File

@ -1,4 +1,4 @@
from sqlalchemy.orm import Enum
from sqlalchemy import Enum
class ProgramEnum(Enum):

View File

@ -23,8 +23,8 @@ class ResourceTagEntity(EntityBase):
# set fields or 'columns' for the user table
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
resourceId: Mapped[int] = mapped_column(ForeignKey("event.id"), primary_key=True)
tagId: Mapped[int] = mapped_column(ForeignKey("user.pid"), primary_key=True)
resourceId: Mapped[int] = mapped_column(ForeignKey("resource.id"))
tagId: Mapped[int] = mapped_column(ForeignKey("tag.id"))
# relationships
resource: Mapped["ResourceEntity"] = relationship(back_populates="resourceTags")

View File

@ -12,11 +12,20 @@ from .entity_base import EntityBase
# Import datetime for created_at type
from datetime import datetime
# Import ProgramType enumeration
from backend.entities.program_enum import ProgramEnum
# Import enums for Program
import enum
from sqlalchemy import Enum
class ResourceEntity(EntityBase):
class ProgramEnum(enum.Enum):
"""Determine program for Service"""
DOMESTIC = "DOMESTIC"
ECONOMIC = "ECONOMIC"
COMMUNITY = "COMMUNITY"
class ServiceEntity(EntityBase):
# set table name
__tablename__ = "service"
@ -27,9 +36,9 @@ class ResourceEntity(EntityBase):
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(ProgramEnum, nullable=False)
program: Mapped[ProgramEnum] = mapped_column(Enum(ProgramEnum), nullable=False)
# relationships
resourceTags: Mapped[list["ServiceTagEntity"]] = relationship(
serviceTags: Mapped[list["ServiceTagEntity"]] = relationship(
back_populates="service", cascade="all,delete"
)

View File

@ -10,15 +10,15 @@ from sqlalchemy.orm import Mapped, mapped_column, relationship
from .entity_base import EntityBase
class ResourceTagEntity(EntityBase):
class ServiceTagEntity(EntityBase):
# set table name to user in the database
__tablename__ = "serviceTag"
# set fields or 'columns' for the user table
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
sericeId: Mapped[int] = mapped_column(ForeignKey("event.id"), primary_key=True)
tagId: Mapped[int] = mapped_column(ForeignKey("user.pid"), primary_key=True)
serviceId: Mapped[int] = mapped_column(ForeignKey("service.id"))
tagId: Mapped[int] = mapped_column(ForeignKey("tag.id"))
# relationships
service: Mapped["ServiceEntity"] = relationship(back_populates="resourceTags")

View File

@ -26,3 +26,37 @@ class TagEntity(EntityBase):
resourceTags: Mapped[list["ResourceTagEntity"]] = relationship(back_populates="tag", cascade="all,delete")
serviceTags: Mapped[list["ServiceTagEntity"]] = relationship(back_populates="tag", cascade="all,delete")
"""
@classmethod
def from_model(cls, model: Tag) -> Self:
Create a user entity from model
Args: model (User): the model to create the entity from
Returns:
self: The entity
return cls(
id=model.id,
content=model.id,
)
def to_model(self) -> Tag:
Create a user model from entity
Returns:
User: A User model for API usage
return Tag(
id=self.id,
content=self.id,
)
"""

View File

@ -3,22 +3,26 @@
# 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
from backend.entities.program_enum import ProgramEnum
from user_enum import RoleEnum
from .user_enum import RoleEnum
class UserEntity(EntityBase):
"""Serves as the databse model for User table"""
"""Serves as the database model for User table"""
# set table name to user in the database
__tablename__ = "user"
@ -30,9 +34,57 @@ class UserEntity(EntityBase):
String(32), nullable=False, default="", unique=True
)
role: Mapped[RoleEnum] = mapped_column(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(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))
"""
@classmethod
def from_model(cls, model: User) -> Self:
Create a user entity from model
Args: model (User): the model to create the entity from
Returns:
self: The entity
return cls(
id=model.id,
username=model.username,
role=model.role,
email=model.email,
program=model.program,
experience=model.experience,
group=model.group,
)
def to_model(self) -> User:
Create a user model from entity
Returns:
User: A User model for API usage
return User(
id=self.id,
username=self.id,
role=self.role,
email=self.email,
program=self.program,
experience=self.experience,
group=self.group,
)
"""

View File

@ -1,4 +1,4 @@
from sqlalchemy.orm import Enum
from sqlalchemy import Enum
class RoleEnum(Enum):