mirror of
https://github.com/cssgunc/compass.git
synced 2025-04-06 20:50:17 -04:00
Merge remote-tracking branch 'origin/backend-emmafoster-GEN-95-entities' into emmafoster-GEN-95-wip
This commit is contained in:
commit
77e26416d1
|
@ -6,4 +6,5 @@ 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
|
||||
|
|
10
backend/entities/program_enum.py
Normal file
10
backend/entities/program_enum.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from sqlalchemy import Enum
|
||||
|
||||
|
||||
class ProgramEnum(Enum):
|
||||
ECONOMIC = "economic"
|
||||
DOMESTIC = "domestic"
|
||||
COMMUNITY = "community"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(name="program_enum")
|
|
@ -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,
|
||||
# )
|
||||
|
|
|
@ -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,
|
||||
# )
|
||||
|
|
|
@ -19,6 +19,7 @@ from sqlalchemy import Enum
|
|||
|
||||
class ProgramEnum(enum.Enum):
|
||||
"""Determine program for Service"""
|
||||
|
||||
DOMESTIC = "DOMESTIC"
|
||||
ECONOMIC = "ECONOMIC"
|
||||
COMMUNITY = "COMMUNITY"
|
||||
|
@ -26,10 +27,10 @@ class ProgramEnum(enum.Enum):
|
|||
|
||||
class ServiceEntity(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)
|
||||
|
@ -37,5 +38,7 @@ class ServiceEntity(EntityBase):
|
|||
requirements: Mapped[list[str]] = mapped_column(ARRAY(String))
|
||||
program: Mapped[ProgramEnum] = mapped_column(Enum(ProgramEnum), nullable=False)
|
||||
|
||||
#relationships
|
||||
serviceTags: Mapped[list["ServiceTagEntity"]] = relationship(back_populates="service", cascade="all,delete")
|
||||
# relationships
|
||||
serviceTags: Mapped[list["ServiceTagEntity"]] = relationship(
|
||||
back_populates="service", cascade="all,delete"
|
||||
)
|
||||
|
|
|
@ -3,37 +3,22 @@
|
|||
# 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
|
||||
|
||||
# Import self
|
||||
from typing import Self
|
||||
|
||||
|
||||
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):
|
||||
|
@ -48,10 +33,17 @@ class UserEntity(EntityBase):
|
|||
username: Mapped[str] = mapped_column(
|
||||
String(32), nullable=False, default="", unique=True
|
||||
)
|
||||
role: Mapped[RoleEnum] = mapped_column(Enum(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)
|
||||
program: Mapped[list[ProgramEnum]] = mapped_column(
|
||||
ARRAY(Enum(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)
|
||||
group: Mapped[str] = mapped_column(String(50))
|
||||
|
|
12
backend/entities/user_enum.py
Normal file
12
backend/entities/user_enum.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from sqlalchemy import Enum
|
||||
|
||||
|
||||
class RoleEnum(Enum):
|
||||
"""Determine role for User"""
|
||||
|
||||
ADMIN = "ADMIN"
|
||||
EMPLOYEE = "EMPLOYEE"
|
||||
VOLUNTEER = "VOLUNTEER"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(name="role_enum")
|
Loading…
Reference in New Issue
Block a user