mirror of
https://github.com/cssgunc/compass.git
synced 2025-04-10 06:10:17 -04:00
refactor enums
This commit is contained in:
parent
03f2204cb3
commit
42a2855839
|
@ -1,2 +1,3 @@
|
||||||
from .entity_base import EntityBase
|
from .entity_base import EntityBase
|
||||||
from .sample_entity import SampleEntity
|
from .sample_entity import SampleEntity
|
||||||
|
from .program_enum import ProgramEnum
|
||||||
|
|
10
backend/entities/program_enum.py
Normal file
10
backend/entities/program_enum.py
Normal file
|
@ -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")
|
|
@ -1,7 +0,0 @@
|
||||||
import enum
|
|
||||||
|
|
||||||
|
|
||||||
class ProgramType(enum.Enum):
|
|
||||||
ECONOMIC = "economic"
|
|
||||||
DOMESTIC = "domestic"
|
|
||||||
COMMUNITY = "community"
|
|
|
@ -12,13 +12,9 @@ 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
|
|
||||||
from sqlalchemy.types import Enum
|
|
||||||
from sqlalchemy import Enum
|
|
||||||
|
|
||||||
# Import self for to model
|
# Import self for to model
|
||||||
from typing import Self
|
from typing import Self
|
||||||
from backend.entities.program_type_enum import ProgramType
|
from backend.entities.program_enum import ProgramEnum
|
||||||
|
|
||||||
|
|
||||||
class ResourceEntity(EntityBase):
|
class ResourceEntity(EntityBase):
|
||||||
|
@ -32,7 +28,7 @@ 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)
|
||||||
link: Mapped[str] = mapped_column(String, nullable=False)
|
link: Mapped[str] = mapped_column(String, nullable=False)
|
||||||
program: Mapped[ProgramType] = mapped_column(Enum(ProgramType), nullable=False)
|
program: Mapped[ProgramEnum] = mapped_column(ProgramEnum, nullable=False)
|
||||||
|
|
||||||
# relationships
|
# relationships
|
||||||
resourceTags: Mapped[list["ResourceTagEntity"]] = relationship(
|
resourceTags: Mapped[list["ResourceTagEntity"]] = relationship(
|
||||||
|
|
|
@ -12,10 +12,6 @@ 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 enum
|
|
||||||
from sqlalchemy import Enum
|
|
||||||
|
|
||||||
# Import self for to model
|
# Import self for to model
|
||||||
from typing import Self
|
from typing import Self
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,8 @@ 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 enum
|
|
||||||
from sqlalchemy import Enum
|
|
||||||
|
|
||||||
# Import ProgramType enumeration
|
# Import ProgramType enumeration
|
||||||
from backend.entities.program_type_enum import ProgramType
|
from backend.entities.program_enum import ProgramEnum
|
||||||
|
|
||||||
|
|
||||||
class ResourceEntity(EntityBase):
|
class ResourceEntity(EntityBase):
|
||||||
|
@ -31,7 +27,7 @@ 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[ProgramType] = mapped_column(Enum(ProgramType), nullable=False)
|
program: Mapped[ProgramEnum] = mapped_column(ProgramEnum, nullable=False)
|
||||||
|
|
||||||
# relationships
|
# relationships
|
||||||
resourceTags: Mapped[list["ServiceTagEntity"]] = relationship(
|
resourceTags: Mapped[list["ServiceTagEntity"]] = relationship(
|
||||||
|
|
|
@ -13,10 +13,8 @@ from .entity_base import EntityBase
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
# Import enums for Role and Program
|
# Import enums for Role and Program
|
||||||
import enum
|
from backend.entities.program_enum import ProgramEnum
|
||||||
from sqlalchemy import Enum
|
from user_enum import RoleEnum
|
||||||
from program_type_enum import ProgramType
|
|
||||||
from user_enum import RoleType
|
|
||||||
|
|
||||||
|
|
||||||
class UserEntity(EntityBase):
|
class UserEntity(EntityBase):
|
||||||
|
@ -31,10 +29,10 @@ class UserEntity(EntityBase):
|
||||||
username: Mapped[str] = mapped_column(
|
username: Mapped[str] = mapped_column(
|
||||||
String(32), nullable=False, default="", unique=True
|
String(32), nullable=False, default="", unique=True
|
||||||
)
|
)
|
||||||
role: Mapped[RoleType] = mapped_column(Enum(RoleType), nullable=False)
|
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[ProgramType]] = mapped_column(
|
program: Mapped[list[ProgramEnum]] = mapped_column(
|
||||||
ARRAY(Enum(ProgramType)), nullable=False
|
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))
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
import enum
|
from sqlalchemy.orm import Enum
|
||||||
|
|
||||||
|
|
||||||
class RoleType(enum.Enum):
|
class RoleEnum(Enum):
|
||||||
"""Determine role for User"""
|
"""Determine role for User"""
|
||||||
|
|
||||||
ADMIN = "ADMIN"
|
ADMIN = "ADMIN"
|
||||||
EMPLOYEE = "EMPLOYEE"
|
EMPLOYEE = "EMPLOYEE"
|
||||||
VOLUNTEER = "VOLUNTEER"
|
VOLUNTEER = "VOLUNTEER"
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(name="role_enum")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user