mirror of
https://github.com/cssgunc/compass.git
synced 2025-04-10 06:10:17 -04:00
commented out to/from model methods until we know model names
This commit is contained in:
parent
9cd703d29f
commit
3bc603cb70
|
@ -1,68 +1,72 @@
|
||||||
""" Defines the table for storing resources """
|
""" Defines the table for storing resources """
|
||||||
|
|
||||||
# Import our mapped SQL types from SQLAlchemy
|
# Import our mapped SQL types from SQLAlchemy
|
||||||
from sqlalchemy import Integer, String, DateTime
|
from sqlalchemy import Integer, String, DateTime
|
||||||
|
|
||||||
# Import mapping capabilities from the SQLAlchemy ORM
|
# Import mapping capabilities from the SQLAlchemy ORM
|
||||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
|
|
||||||
# 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 Program
|
# Import enums for Program
|
||||||
import enum
|
from sqlalchemy.types import Enum
|
||||||
from sqlalchemy import Enum
|
from sqlalchemy import Enum
|
||||||
|
|
||||||
class ProgramEnum(enum.Enum):
|
# Import self for to model
|
||||||
""" Determine program for Resource """
|
from typing import Self
|
||||||
DOMESTIC = 'DOMESTIC'
|
from programtype_enum import ProgramType
|
||||||
ECONOMIC = 'ECONOMIC'
|
|
||||||
COMMUNITY = 'COMMUNITY'
|
|
||||||
|
|
||||||
class ResourceEntity(EntityBase):
|
|
||||||
|
|
||||||
#set table name
|
class ResourceEntity(EntityBase):
|
||||||
|
|
||||||
|
# set table name
|
||||||
__tablename__ = "resource"
|
__tablename__ = "resource"
|
||||||
|
|
||||||
#set fields
|
# set fields
|
||||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now)
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now)
|
||||||
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)
|
||||||
link: Mapped[str] = mapped_column(String, 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
|
# relationships
|
||||||
resourceTags: Mapped[list["ResourceTagEntity"]] = relationship(back_populates="resource", cascade="all,delete")
|
resourceTags: Mapped[list["ResourceTagEntity"]] = relationship(
|
||||||
|
back_populates="resource", cascade="all,delete"
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
#
|
||||||
def from_model(cls, model: user_model) -> Self:
|
# @classmethod
|
||||||
"""
|
# def from_model(cls, model: user_model) -> Self:
|
||||||
Create a UserEntity from a User model.
|
# """
|
||||||
|
# Create a UserEntity from a User model.
|
||||||
|
|
||||||
Args:
|
# Args:
|
||||||
model (User): The model to create the entity from.
|
# 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
|
|
||||||
)
|
|
||||||
|
|
||||||
|
# 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 """
|
""" Defines the table for resource tags """
|
||||||
|
|
||||||
# Import our mapped SQL types from SQLAlchemy
|
# 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
|
# Import mapping capabilities from the SQLAlchemy ORM
|
||||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||||
|
@ -16,6 +16,9 @@ from datetime import datetime
|
||||||
import enum
|
import enum
|
||||||
from sqlalchemy import Enum
|
from sqlalchemy import Enum
|
||||||
|
|
||||||
|
# Import self for to model
|
||||||
|
from typing import Self
|
||||||
|
|
||||||
|
|
||||||
class ResourceTagEntity(EntityBase):
|
class ResourceTagEntity(EntityBase):
|
||||||
|
|
||||||
|
@ -30,3 +33,18 @@ class ResourceTagEntity(EntityBase):
|
||||||
# relationships
|
# relationships
|
||||||
resource: Mapped["ResourceEntity"] = relationship(back_populates="resourceTags")
|
resource: Mapped["ResourceEntity"] = relationship(back_populates="resourceTags")
|
||||||
tag: Mapped["TagEntity"] = 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,
|
||||||
|
# )
|
||||||
|
|
|
@ -16,26 +16,24 @@ from datetime import datetime
|
||||||
import enum
|
import enum
|
||||||
from sqlalchemy import Enum
|
from sqlalchemy import Enum
|
||||||
|
|
||||||
|
# Import ProgramType enumeration
|
||||||
class ProgramEnum(enum.Enum):
|
from programtype_enum import ProgramType
|
||||||
"""Determine program for Service"""
|
|
||||||
DOMESTIC = "DOMESTIC"
|
|
||||||
ECONOMIC = "ECONOMIC"
|
|
||||||
COMMUNITY = "COMMUNITY"
|
|
||||||
|
|
||||||
|
|
||||||
class ResourceEntity(EntityBase):
|
class ResourceEntity(EntityBase):
|
||||||
|
|
||||||
#set table name
|
# set table name
|
||||||
__tablename__ = "service"
|
__tablename__ = "service"
|
||||||
|
|
||||||
#set fields
|
# set fields
|
||||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now)
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now)
|
||||||
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(Enum(ProgramEnum), nullable=False)
|
program: Mapped[ProgramType] = mapped_column(Enum(ProgramType), nullable=False)
|
||||||
|
|
||||||
#relationships
|
# relationships
|
||||||
resourceTags: Mapped[list["ServiceTagEntity"]] = relationship(back_populates="service", cascade="all,delete")
|
resourceTags: Mapped[list["ServiceTagEntity"]] = relationship(
|
||||||
|
back_populates="service", cascade="all,delete"
|
||||||
|
)
|
||||||
|
|
|
@ -2,27 +2,28 @@
|
||||||
|
|
||||||
# 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
|
||||||
import enum
|
import enum
|
||||||
from sqlalchemy import Enum
|
from sqlalchemy import Enum
|
||||||
|
from programtype_enumeration import ProgramType
|
||||||
|
|
||||||
|
|
||||||
class RoleEnum(enum.Enum):
|
class RoleEnum(enum.Enum):
|
||||||
""" Determine role for User """
|
"""Determine role for User"""
|
||||||
ADMIN = 'ADMIN'
|
|
||||||
EMPLOYEE = 'EMPLOYEE'
|
|
||||||
VOLUNTEER = 'VOLUNTEER'
|
|
||||||
|
|
||||||
class ProgramEnum(enum.Enum):
|
ADMIN = "ADMIN"
|
||||||
"""Determine program for User """
|
EMPLOYEE = "EMPLOYEE"
|
||||||
DOMESTIC = 'DOMESTIC'
|
VOLUNTEER = "VOLUNTEER"
|
||||||
ECONOMIC = 'ECONOMIC'
|
|
||||||
COMMUNITY = 'COMMUNITY'
|
|
||||||
|
|
||||||
|
|
||||||
class UserEntity(EntityBase):
|
class UserEntity(EntityBase):
|
||||||
|
@ -34,10 +35,13 @@ class UserEntity(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)
|
||||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now)
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now)
|
||||||
username: Mapped[str] = mapped_column(String(32), nullable=False, default="", unique=True)
|
username: Mapped[str] = mapped_column(
|
||||||
role: Mapped[RoleEnum] = mapped_column(Enum(RoleEnum), nullable=False)
|
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)
|
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)
|
experience: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||||
group: Mapped[str] = mapped_column(String(50))
|
group: Mapped[str] = mapped_column(String(50))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user