phase-1: data model, auth, permissions, masters, settings, seed
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
from .auth import LoginRequest, TokenResponse, UserOut
|
||||
from .masters import (
|
||||
CategoryCreate,
|
||||
CategoryOut,
|
||||
CategoryUpdate,
|
||||
DepartmentCreate,
|
||||
DepartmentOut,
|
||||
DepartmentUpdate,
|
||||
LocationCreate,
|
||||
LocationOut,
|
||||
LocationUpdate,
|
||||
PaginatedOut,
|
||||
UserCreate,
|
||||
UserListOut,
|
||||
UserLookupOut,
|
||||
UserUpdate,
|
||||
VendorCreate,
|
||||
VendorOut,
|
||||
VendorUpdate,
|
||||
)
|
||||
from .settings import DemoDateIn, DemoDateOut, SettingItemOut, SettingsListOut, SettingsUpdateIn
|
||||
|
||||
__all__ = [
|
||||
"LoginRequest",
|
||||
"TokenResponse",
|
||||
"UserOut",
|
||||
"PaginatedOut",
|
||||
"DepartmentCreate",
|
||||
"DepartmentUpdate",
|
||||
"DepartmentOut",
|
||||
"LocationCreate",
|
||||
"LocationUpdate",
|
||||
"LocationOut",
|
||||
"CategoryCreate",
|
||||
"CategoryUpdate",
|
||||
"CategoryOut",
|
||||
"VendorCreate",
|
||||
"VendorUpdate",
|
||||
"VendorOut",
|
||||
"UserCreate",
|
||||
"UserUpdate",
|
||||
"UserListOut",
|
||||
"UserLookupOut",
|
||||
"SettingItemOut",
|
||||
"SettingsListOut",
|
||||
"SettingsUpdateIn",
|
||||
"DemoDateIn",
|
||||
"DemoDateOut",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
|
||||
class LoginRequest(BaseModel):
|
||||
email: str
|
||||
password: str
|
||||
|
||||
|
||||
class UserOut(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
name: str
|
||||
email: str
|
||||
role: str
|
||||
department_id: Optional[int] = None
|
||||
department_name: Optional[str] = None
|
||||
is_active: bool
|
||||
demo_as_of_date: Optional[str] = None
|
||||
|
||||
|
||||
class TokenResponse(BaseModel):
|
||||
access_token: str
|
||||
token_type: str = "bearer"
|
||||
user: UserOut
|
||||
@@ -0,0 +1,159 @@
|
||||
from typing import Generic, Literal, Optional, TypeVar
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
VendorType = Literal["supplier", "service_provider", "calibration_agency", "insurer", "oem"]
|
||||
UserRole = Literal["system_admin", "biomedical", "department_user", "management", "coordinator"]
|
||||
|
||||
|
||||
class PaginatedOut(BaseModel, Generic[T]):
|
||||
items: list[T]
|
||||
total: int
|
||||
|
||||
|
||||
# --- Departments ---
|
||||
class DepartmentCreate(BaseModel):
|
||||
name: str = Field(..., min_length=1, max_length=150)
|
||||
code: str = Field(..., min_length=1, max_length=30)
|
||||
description: Optional[str] = None
|
||||
is_active: bool = True
|
||||
|
||||
|
||||
class DepartmentUpdate(BaseModel):
|
||||
name: Optional[str] = Field(None, min_length=1, max_length=150)
|
||||
code: Optional[str] = Field(None, min_length=1, max_length=30)
|
||||
description: Optional[str] = None
|
||||
is_active: Optional[bool] = None
|
||||
|
||||
|
||||
class DepartmentOut(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
name: str
|
||||
code: str
|
||||
description: Optional[str] = None
|
||||
is_active: bool
|
||||
|
||||
|
||||
# --- Locations ---
|
||||
class LocationCreate(BaseModel):
|
||||
department_id: int
|
||||
name: str = Field(..., min_length=1, max_length=150)
|
||||
floor_wing: Optional[str] = Field(None, max_length=100)
|
||||
is_active: bool = True
|
||||
|
||||
|
||||
class LocationUpdate(BaseModel):
|
||||
department_id: Optional[int] = None
|
||||
name: Optional[str] = Field(None, min_length=1, max_length=150)
|
||||
floor_wing: Optional[str] = Field(None, max_length=100)
|
||||
is_active: Optional[bool] = None
|
||||
|
||||
|
||||
class LocationOut(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
department_id: int
|
||||
department_name: Optional[str] = None
|
||||
name: str
|
||||
floor_wing: Optional[str] = None
|
||||
is_active: bool
|
||||
|
||||
|
||||
# --- Categories ---
|
||||
class CategoryCreate(BaseModel):
|
||||
name: str = Field(..., min_length=1, max_length=150)
|
||||
description: Optional[str] = None
|
||||
is_active: bool = True
|
||||
|
||||
|
||||
class CategoryUpdate(BaseModel):
|
||||
name: Optional[str] = Field(None, min_length=1, max_length=150)
|
||||
description: Optional[str] = None
|
||||
is_active: Optional[bool] = None
|
||||
|
||||
|
||||
class CategoryOut(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
is_active: bool
|
||||
|
||||
|
||||
# --- Vendors ---
|
||||
class VendorCreate(BaseModel):
|
||||
name: str = Field(..., min_length=1, max_length=200)
|
||||
vendor_type: VendorType
|
||||
contact_person: Optional[str] = Field(None, max_length=150)
|
||||
phone: Optional[str] = Field(None, max_length=50)
|
||||
email: Optional[str] = Field(None, max_length=150)
|
||||
address: Optional[str] = None
|
||||
is_active: bool = True
|
||||
|
||||
|
||||
class VendorUpdate(BaseModel):
|
||||
name: Optional[str] = Field(None, min_length=1, max_length=200)
|
||||
vendor_type: Optional[VendorType] = None
|
||||
contact_person: Optional[str] = Field(None, max_length=150)
|
||||
phone: Optional[str] = Field(None, max_length=50)
|
||||
email: Optional[str] = Field(None, max_length=150)
|
||||
address: Optional[str] = None
|
||||
is_active: Optional[bool] = None
|
||||
|
||||
|
||||
class VendorOut(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
name: str
|
||||
vendor_type: str
|
||||
contact_person: Optional[str] = None
|
||||
phone: Optional[str] = None
|
||||
email: Optional[str] = None
|
||||
address: Optional[str] = None
|
||||
is_active: bool
|
||||
|
||||
|
||||
# --- Users ---
|
||||
class UserCreate(BaseModel):
|
||||
name: str = Field(..., min_length=1, max_length=150)
|
||||
email: str = Field(..., min_length=3, max_length=200)
|
||||
password: str = Field(..., min_length=4, max_length=128)
|
||||
role: UserRole
|
||||
department_id: Optional[int] = None
|
||||
is_active: bool = True
|
||||
|
||||
|
||||
class UserUpdate(BaseModel):
|
||||
name: Optional[str] = Field(None, min_length=1, max_length=150)
|
||||
email: Optional[str] = Field(None, min_length=3, max_length=200)
|
||||
password: Optional[str] = Field(None, max_length=128)
|
||||
role: Optional[UserRole] = None
|
||||
department_id: Optional[int] = None
|
||||
is_active: Optional[bool] = None
|
||||
|
||||
|
||||
class UserListOut(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
name: str
|
||||
email: str
|
||||
role: str
|
||||
department_id: Optional[int] = None
|
||||
department_name: Optional[str] = None
|
||||
is_active: bool
|
||||
|
||||
|
||||
class UserLookupOut(BaseModel):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
name: str
|
||||
role: str
|
||||
department_id: Optional[int] = None
|
||||
@@ -0,0 +1,31 @@
|
||||
from typing import Any, Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class SettingItemOut(BaseModel):
|
||||
key: str
|
||||
value: Any
|
||||
type: str
|
||||
label: str
|
||||
description: str
|
||||
default: Any
|
||||
min: Optional[int] = None
|
||||
max: Optional[int] = None
|
||||
options: Optional[list[str]] = None
|
||||
|
||||
|
||||
class SettingsListOut(BaseModel):
|
||||
items: list[SettingItemOut]
|
||||
|
||||
|
||||
class SettingsUpdateIn(BaseModel):
|
||||
values: dict[str, Any]
|
||||
|
||||
|
||||
class DemoDateIn(BaseModel):
|
||||
demo_as_of_date: Optional[str] = None
|
||||
|
||||
|
||||
class DemoDateOut(BaseModel):
|
||||
demo_as_of_date: Optional[str] = None
|
||||
effective_today: str
|
||||
Reference in New Issue
Block a user