Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add checklists models and populate #182

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from support_sphere.models.enums.app_permissions import AppPermissions
from support_sphere.models.enums.app_roles import AppRoles
from support_sphere.models.enums.operational_status import OperationalStatus
from support_sphere.models.enums.priority import Priority


__all__ = ['AppPermissions', 'AppRoles', 'OperationalStatus']
__all__ = ['AppPermissions', 'AppRoles', 'OperationalStatus', Priority]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from enum import Enum


class Priority(Enum):
LOW = ("low", "Low Priority")
MEDIUM = ("medium", "Medium Priority")
HIGH = ("high", "High Priority")

def __init__(self, priority, description):
self.priority = priority
self.description = description
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
from support_sphere.models.public.checklist_steps_order import ChecklistStepsOrder
from support_sphere.models.public.checklist_steps_template import ChecklistStepsTemplate
from support_sphere.models.public.checklist_type import ChecklistType
from support_sphere.models.public.checklist_step import ChecklistStep
from support_sphere.models.public.checklist_steps_state import ChecklistStepsState
from support_sphere.models.public.checklist import Checklist
from support_sphere.models.public.cluster import Cluster
from support_sphere.models.public.household import Household
from support_sphere.models.public.operational_event import OperationalEvent
from support_sphere.models.public.people import People
from support_sphere.models.public.people_group import PeopleGroup
from support_sphere.models.public.point_of_interest import PointOfInterest
from support_sphere.models.public.recurring_type import RecurringType
from support_sphere.models.public.resource import Resource
from support_sphere.models.public.resource_subtype_tag import ResourceSubtypeTag
from support_sphere.models.public.resource_tag import ResourceTag
from support_sphere.models.public.resource_type import ResourceType
from support_sphere.models.public.resource_cv import ResourceCV
from support_sphere.models.public.role_permission import RolePermission
from support_sphere.models.public.user_captain_cluster import UserCaptainCluster
from support_sphere.models.public.user_checklist import UserChecklist
from support_sphere.models.public.user_checklist_state import UserChecklistState
from support_sphere.models.public.user_profile import UserProfile
from support_sphere.models.public.user_resource import UserResource
from support_sphere.models.public.user_role import UserRole
from support_sphere.models.public.signup_code import SignupCode
from support_sphere.models.public.frequency import Frequency
from support_sphere.models.public.user_checklist import UserChecklists



# New models created should be exposed by adding to __all__. This is used by SQLModel.metadata
# https://sqlmodel.tiangolo.com/tutorial/create-db-and-table/#sqlmodel-metadata-order-matters
__all__ = [
"Checklist",
"ChecklistStepsOrder",
"ChecklistStepsTemplate",
"ChecklistType",
"ChecklistStep",
"ChecklistStepsState",
"Cluster",
"Household",
"OperationalEvent",
"People",
"PeopleGroup",
"PointOfInterest",
"RecurringType",
"Resource",
"ResourceSubtypeTag",
"ResourceTag",
Expand All @@ -45,9 +45,9 @@
"RolePermission",
"SignupCode",
"UserCaptainCluster",
"UserChecklist",
"UserChecklistState",
"UserProfile",
"UserResource",
"UserProfile",
"UserChecklists",
"UserRole",
"Frequency",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import uuid
import datetime
from typing import Optional
from sqlalchemy import Enum

from support_sphere.models.base import BasePublicSchemaModel
from support_sphere.models.enums import Priority
from sqlmodel import Field, Relationship


class Checklist(BasePublicSchemaModel, table=True):
"""
Represents a checklist entity in the 'public' schema under the 'checklists' table.
This table defines different types of checklists, including the associated frequency.

Attributes
----------
id : uuid
The unique identifier for the checklist.
recurring_type_id : uuid
The foreign key referring to the frequency.
title : str
The title of the checklist.
description : str, optional
A detailed description of the checklist.
current_version : int
The current version of this checklist.
updated_at : datetime
The timestamp for the last update of this checklist.
frequency : Frequency, optional
A relationship to the `Frequency` model.
user_checklists : list[UserChecklists]
A list of `UserChecklist` entities associated with this checklist.
"""

__tablename__ = "checklists"

id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
title: str | None = Field(nullable=False)
description: str | None = Field(nullable=True)
notes: str | None = Field(nullable=True)
updated_at: datetime.datetime = Field(
default_factory=lambda: datetime.datetime.now(datetime.UTC),
nullable=False
)
priority: Priority = Field(default=Priority.LOW, sa_type=Enum(Priority, name="priority"), nullable=False)
frequency_id: uuid.UUID | None = Field(foreign_key="public.frequency.id", nullable=True)

frequency: Optional["Frequency"] = Relationship(back_populates="checklists", cascade_delete=False)
user_checklists: list["UserChecklists"] = Relationship(back_populates="checklists", cascade_delete=False)
checklist_steps_orders: list["ChecklistStepsOrder"] = Relationship(back_populates="checklists", cascade_delete=False)
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import uuid
from typing import Optional
import datetime

from support_sphere.models.base import BasePublicSchemaModel
from sqlmodel import Field, Relationship


class ChecklistStepsTemplate(BasePublicSchemaModel, table=True):
class ChecklistStep(BasePublicSchemaModel, table=True):
"""
Represents a template for checklist steps in the 'public' schema under the 'checklist_steps_templates' table.

Expand All @@ -17,14 +18,18 @@ class ChecklistStepsTemplate(BasePublicSchemaModel, table=True):
The title of the checklist step template.
description : str, optional
A detailed description of the checklist step template.
checklist_steps_order : ChecklistStepsOrder, optional
checklist_steps_order : list[ChecklistStepsOrder]
A relationship to the `ChecklistStepsOrder` model, which defines the order of these steps within a checklist.
"""
__tablename__ = "checklist_steps_templates"
__tablename__ = "checklist_steps"

id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
title: str | None = Field(nullable=False)
label: str | None = Field(nullable=False)
description: str | None = Field(nullable=True)
updated_at: datetime.datetime = Field(
default_factory=lambda: datetime.datetime.now(datetime.UTC),
nullable=False
)

checklist_steps_order: Optional["ChecklistStepsOrder"] = Relationship(back_populates="checklist_steps_template",
cascade_delete=False)
checklist_steps_orders: list["ChecklistStepsOrder"] = Relationship(back_populates="checklist_steps",
cascade_delete=True)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import uuid
from typing import Optional
import datetime

from support_sphere.models.base import BasePublicSchemaModel
from sqlmodel import Field, Relationship
Expand Down Expand Up @@ -28,10 +29,14 @@ class ChecklistStepsOrder(BasePublicSchemaModel, table=True):

__tablename__ = "checklist_steps_orders"

checklist_types_id: uuid.UUID | None = Field(primary_key=True, foreign_key="public.checklist_types.id")
checklist_steps_templates_id: uuid.UUID | None = Field(foreign_key="public.checklist_steps_templates.id")
priority: int | None = Field(nullable=False)
version: int | None = Field(nullable=False)
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
checklist_id: uuid.UUID = Field(foreign_key="public.checklists.id", nullable=False)
checklist_step_id: uuid.UUID = Field(foreign_key="public.checklist_steps.id", nullable=False)
priority: int = Field(nullable=False)
updated_at: datetime.datetime = Field(
default_factory=lambda: datetime.datetime.now(datetime.UTC),
nullable=False
)

checklist_steps_template: Optional["ChecklistStepsTemplate"] = Relationship(back_populates="checklist_steps_order", cascade_delete=False)
checklist_type: Optional["ChecklistType"] = Relationship(back_populates="checklist_steps_order", cascade_delete=False)
checklists: list["Checklist"] = Relationship(back_populates="checklist_steps_orders", cascade_delete=False)
checklist_steps: list["ChecklistStep"] = Relationship(back_populates="checklist_steps_orders", cascade_delete=False)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import uuid
from typing import Optional
import datetime

from support_sphere.models.base import BasePublicSchemaModel
from sqlmodel import Field, Relationship


class ChecklistStepsState(BasePublicSchemaModel, table=True):
"""
Represents a template for checklist steps in the 'public' schema under the 'checklist_steps_templates' table.

Attributes
----------
id : uuid
The unique identifier for the checklist step template.
title : str
The title of the checklist step template.
description : str, optional
A detailed description of the checklist step template.
checklist_steps_order : ChecklistStepsOrder, optional
A relationship to the `ChecklistStepsOrder` model, which defines the order of these steps within a checklist.
"""
__tablename__ = "checklist_steps_states"

id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
checklist_steps_order_id: uuid.UUID = Field(foreign_key="public.checklist_steps_orders.id", nullable=False)
user_profile_id: uuid.UUID = Field(foreign_key="public.user_profiles.id", nullable=False)
is_completed: bool = Field(default=False, nullable=False)

checklist_steps_order: "ChecklistStepsOrder" = Relationship(cascade_delete=False)
user_profile: Optional["UserProfile"] = Relationship(back_populates="checklist_steps_state", cascade_delete=False)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import uuid
from typing import Optional

from support_sphere.models.base import BasePublicSchemaModel
from sqlmodel import Field, Relationship


class Frequency(BasePublicSchemaModel, table=True):
"""
Represents a frequency in the 'public' schema under the 'checklist_frequency' table.

Attributes
----------
id : uuid
The unique identifier for the frequency.
name : str
num_days : int
The number of days between recurrences.
checklists: list[Checklists]
A relationship to the `Checklist` model, representing the checklists that can have this frequency.
"""

__tablename__ = "frequency"

id: uuid.UUID | None = Field(default_factory=uuid.uuid4, primary_key=True)
name: str | None = Field(nullable=False)
num_days: int | None = Field(nullable=False)

checklists: list["Checklist"] = Relationship(back_populates="frequency", cascade_delete=False)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sqlmodel import Field, Relationship


class UserChecklist(BasePublicSchemaModel, table=True):
class UserChecklists(BasePublicSchemaModel, table=True):

"""
Represents a checklist associated with a user in the 'public' schema under the 'user_checklists' table.
Expand All @@ -25,23 +25,18 @@ class UserChecklist(BasePublicSchemaModel, table=True):
The due date for the checklist completion.
last_completed_version : int, optional
The version number of the checklist that was last completed by the user.
checklist_type : ChecklistType, optional
A relationship to the `ChecklistType` model, representing the type of the checklist.
user_profile : UserProfile, optional
A relationship to the `UserProfile` model, representing the user who owns the checklist.
user_checklist_state : UserChecklistState, optional
A relationship to the `UserChecklistState` model, representing the current state of the checklist.
checklists : list[Checklist]
A relationship to the `Checklist` model, representing the checklist.
user_profile : UserProfile
A relationship to the `UserProfile` model, representing the user who owns the checklists.
"""

__tablename__ = "user_checklists"

id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
user_id: uuid.UUID | None = Field(foreign_key="public.user_profiles.id", nullable=False)
checklist_type_id: uuid.UUID = Field(foreign_key="public.checklist_types.id", nullable=False)
due_date: datetime = Field(nullable=True)
last_completed_version: int | None = Field(nullable=False)

checklist_type: Optional["ChecklistType"] = Relationship(back_populates="user_checklists", cascade_delete=False)
user_profile: Optional["UserProfile"] = Relationship(back_populates="user_checklists", cascade_delete=False)
user_checklist_state: Optional["UserChecklistState"] = Relationship(back_populates="user_checklist",
cascade_delete=False)
checklist_id: uuid.UUID = Field(foreign_key="public.checklists.id", nullable=False)
user_profile_id: uuid.UUID = Field(foreign_key="public.user_profiles.id", nullable=False)
completed_at: datetime | None = Field(nullable=True)

checklists: list["Checklist"] = Relationship(back_populates="user_checklists", cascade_delete=False)
user_profile: "UserProfile" = Relationship(back_populates="user_checklists", cascade_delete=False)
Loading