mirror of
https://github.com/cssgunc/compass.git
synced 2025-04-10 06:10:17 -04:00
Merge pull request #21 from cssgunc/emmafoster-GEN-95-wip
Emmafoster gen 95 wip
This commit is contained in:
commit
032e943a92
|
@ -1,3 +1,10 @@
|
||||||
from .entity_base import EntityBase
|
from .entity_base import EntityBase
|
||||||
from .sample_entity import SampleEntity
|
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 .program_enum import ProgramEnum
|
||||||
|
from .user_enum import RoleEnum
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from sqlalchemy.orm import Enum
|
from sqlalchemy import Enum
|
||||||
|
|
||||||
|
|
||||||
class ProgramEnum(Enum):
|
class ProgramEnum(Enum):
|
||||||
|
|
|
@ -23,8 +23,8 @@ class ResourceTagEntity(EntityBase):
|
||||||
|
|
||||||
# set fields or 'columns' for the user table
|
# set fields or 'columns' for the user table
|
||||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||||
resourceId: Mapped[int] = mapped_column(ForeignKey("event.id"), primary_key=True)
|
resourceId: Mapped[int] = mapped_column(ForeignKey("resource.id"))
|
||||||
tagId: Mapped[int] = mapped_column(ForeignKey("user.pid"), primary_key=True)
|
tagId: Mapped[int] = mapped_column(ForeignKey("tag.id"))
|
||||||
|
|
||||||
# relationships
|
# relationships
|
||||||
resource: Mapped["ResourceEntity"] = relationship(back_populates="resourceTags")
|
resource: Mapped["ResourceEntity"] = relationship(back_populates="resourceTags")
|
||||||
|
|
|
@ -12,11 +12,20 @@ from .entity_base import EntityBase
|
||||||
# Import datetime for created_at type
|
# Import datetime for created_at type
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
# Import ProgramType enumeration
|
# Import enums for Program
|
||||||
from backend.entities.program_enum import ProgramEnum
|
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
|
# set table name
|
||||||
__tablename__ = "service"
|
__tablename__ = "service"
|
||||||
|
@ -27,9 +36,9 @@ class ResourceEntity(EntityBase):
|
||||||
name: Mapped[str] = mapped_column(String(32), nullable=False)
|
name: Mapped[str] = mapped_column(String(32), nullable=False)
|
||||||
summary: Mapped[str] = mapped_column(String(100), nullable=False)
|
summary: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||||
requirements: Mapped[list[str]] = mapped_column(ARRAY(String))
|
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
|
# relationships
|
||||||
resourceTags: Mapped[list["ServiceTagEntity"]] = relationship(
|
serviceTags: Mapped[list["ServiceTagEntity"]] = relationship(
|
||||||
back_populates="service", cascade="all,delete"
|
back_populates="service", cascade="all,delete"
|
||||||
)
|
)
|
|
@ -10,15 +10,15 @@ from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
from .entity_base import EntityBase
|
from .entity_base import EntityBase
|
||||||
|
|
||||||
|
|
||||||
class ResourceTagEntity(EntityBase):
|
class ServiceTagEntity(EntityBase):
|
||||||
|
|
||||||
# set table name to user in the database
|
# set table name to user in the database
|
||||||
__tablename__ = "serviceTag"
|
__tablename__ = "serviceTag"
|
||||||
|
|
||||||
# set fields or 'columns' for the user table
|
# set fields or 'columns' for the user table
|
||||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||||
sericeId: Mapped[int] = mapped_column(ForeignKey("event.id"), primary_key=True)
|
serviceId: Mapped[int] = mapped_column(ForeignKey("service.id"))
|
||||||
tagId: Mapped[int] = mapped_column(ForeignKey("user.pid"), primary_key=True)
|
tagId: Mapped[int] = mapped_column(ForeignKey("tag.id"))
|
||||||
|
|
||||||
# relationships
|
# relationships
|
||||||
service: Mapped["ServiceEntity"] = relationship(back_populates="resourceTags")
|
service: Mapped["ServiceEntity"] = relationship(back_populates="resourceTags")
|
||||||
|
|
|
@ -26,3 +26,37 @@ class TagEntity(EntityBase):
|
||||||
resourceTags: Mapped[list["ResourceTagEntity"]] = relationship(back_populates="tag", cascade="all,delete")
|
resourceTags: Mapped[list["ResourceTagEntity"]] = relationship(back_populates="tag", cascade="all,delete")
|
||||||
serviceTags: Mapped[list["ServiceTagEntity"]] = 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,
|
||||||
|
)
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,22 +3,26 @@
|
||||||
# Import our mapped SQL types from SQLAlchemy
|
# Import our mapped SQL types from SQLAlchemy
|
||||||
from sqlalchemy import Integer, String, DateTime, ARRAY
|
from sqlalchemy import Integer, String, DateTime, ARRAY
|
||||||
|
|
||||||
|
|
||||||
# Import mapping capabilities from the SQLAlchemy ORM
|
# Import mapping capabilities from the SQLAlchemy ORM
|
||||||
from sqlalchemy.orm import Mapped, mapped_column
|
from sqlalchemy.orm import Mapped, mapped_column
|
||||||
|
|
||||||
|
|
||||||
# Import the EntityBase that we are extending
|
# Import the EntityBase that we are extending
|
||||||
from .entity_base import EntityBase
|
from .entity_base import EntityBase
|
||||||
|
|
||||||
|
|
||||||
# Import datetime for created_at type
|
# Import datetime for created_at type
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
# Import enums for Role and Program
|
# Import enums for Role and Program
|
||||||
from backend.entities.program_enum import ProgramEnum
|
from backend.entities.program_enum import ProgramEnum
|
||||||
from user_enum import RoleEnum
|
from .user_enum import RoleEnum
|
||||||
|
|
||||||
|
|
||||||
class UserEntity(EntityBase):
|
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
|
# set table name to user in the database
|
||||||
__tablename__ = "user"
|
__tablename__ = "user"
|
||||||
|
@ -30,9 +34,57 @@ class UserEntity(EntityBase):
|
||||||
String(32), nullable=False, default="", unique=True
|
String(32), nullable=False, default="", unique=True
|
||||||
)
|
)
|
||||||
role: Mapped[RoleEnum] = mapped_column(RoleEnum, nullable=False)
|
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)
|
email: Mapped[str] = mapped_column(String(50), nullable=False, unique=True)
|
||||||
program: Mapped[list[ProgramEnum]] = mapped_column(
|
program: Mapped[list[ProgramEnum]] = mapped_column(
|
||||||
ARRAY(ProgramEnum), nullable=False
|
ARRAY(ProgramEnum), nullable=False
|
||||||
)
|
)
|
||||||
|
program: Mapped[list[ProgramEnum]] = mapped_column(
|
||||||
|
ARRAY(ProgramEnum), nullable=False
|
||||||
|
)
|
||||||
experience: Mapped[int] = mapped_column(Integer, nullable=False)
|
experience: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||||
group: Mapped[str] = mapped_column(String(50))
|
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,
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from sqlalchemy.orm import Enum
|
from sqlalchemy import Enum
|
||||||
|
|
||||||
|
|
||||||
class RoleEnum(Enum):
|
class RoleEnum(Enum):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user