feat(M06): Add Department and UserDepartment models, seed 12 DMH departments, and enable department-level permissions
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class DepartmentBase(BaseModel):
|
||||
code: str = Field(..., max_length=30, description="Unique department code, e.g. ADMISSION, IPD, OPD")
|
||||
name: str = Field(..., max_length=100, description="Department full name")
|
||||
description: Optional[str] = Field(None, description="Department purpose / scope")
|
||||
is_active: bool = True
|
||||
|
||||
|
||||
class DepartmentCreate(BaseModel):
|
||||
code: str = Field(..., max_length=30)
|
||||
name: str = Field(..., max_length=100)
|
||||
description: Optional[str] = None
|
||||
|
||||
|
||||
class DepartmentUpdate(BaseModel):
|
||||
code: Optional[str] = Field(None, max_length=30)
|
||||
name: Optional[str] = Field(None, max_length=100)
|
||||
description: Optional[str] = None
|
||||
is_active: Optional[bool] = None
|
||||
|
||||
|
||||
class DepartmentMemberResponse(BaseModel):
|
||||
user_id: int
|
||||
username: str
|
||||
full_name: Optional[str] = None
|
||||
email: str
|
||||
role: str
|
||||
is_head: bool
|
||||
joined_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class DepartmentResponse(DepartmentBase):
|
||||
id: int
|
||||
member_count: int = 0
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class DepartmentWithMembersResponse(DepartmentResponse):
|
||||
members: List[DepartmentMemberResponse] = Field(default_factory=list)
|
||||
|
||||
|
||||
class UserDepartmentCreate(BaseModel):
|
||||
user_id: int
|
||||
is_head: bool = False
|
||||
|
||||
|
||||
class UserDepartmentResponse(BaseModel):
|
||||
id: int
|
||||
user_id: int
|
||||
department_id: int
|
||||
is_head: bool
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
Reference in New Issue
Block a user