160 lines
4.3 KiB
Python
160 lines
4.3 KiB
Python
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
|