This commit is contained in:
Shubhankar45
2026-10-27 12:03:31 +00:00
parent 2ed3945b5d
commit 4e5e95775d
104 changed files with 5210 additions and 606 deletions
+34 -2
View File
@@ -9,7 +9,7 @@ from app.chemists.schemas import ChemistCreate, ChemistRead, ChemistUpdate
from app.chemists.service import ChemistService
from app.common.enums import Role
from app.database.session import get_db
from app.doctors.schemas import AssignToMR
from app.doctors.schemas import AssignToMR, RejectMaster
from app.users.models import User
router = APIRouter(prefix="/chemists", tags=["chemists"])
@@ -26,9 +26,10 @@ async def list_chemists(
async def create_chemist(
payload: ChemistCreate,
request: Request,
current_user: User = Depends(require_role(Role.ADMIN)),
current_user: User = Depends(require_role(Role.ADMIN, Role.MR)),
db: AsyncSession = Depends(get_db),
) -> Chemist:
"""An Administrator, or an MR within their own headquarters (AM and GM cannot)."""
return await ChemistService(db).create(payload, current_user, client_ip(request))
@@ -60,3 +61,34 @@ async def assign_chemist(
"mr_user_id": assignment.mr_user_id,
"effective_from": assignment.effective_from,
}
@router.get("/requests", response_model=list[ChemistRead])
async def list_chemist_requests(
current_user: User = Depends(get_current_user), db: AsyncSession = Depends(get_db)
) -> list[Chemist]:
"""Chemists an MR added that wait for the Area Manager: an MR sees their own (with any
rejected and why), an Area Manager what waits for them, the administrator and GM all."""
return await ChemistService(db).requests_for(current_user)
@router.post("/{chemist_id}/approve", response_model=ChemistRead)
async def approve_chemist(
chemist_id: uuid.UUID,
request: Request,
current_user: User = Depends(require_role(Role.AM, Role.ADMIN)),
db: AsyncSession = Depends(get_db),
) -> Chemist:
"""The Area Manager of its headquarters adds it to the list, assigned to the MR who asked."""
return await ChemistService(db).review(chemist_id, True, None, current_user, client_ip(request))
@router.post("/{chemist_id}/reject", response_model=ChemistRead)
async def reject_chemist(
chemist_id: uuid.UUID,
payload: RejectMaster,
request: Request,
current_user: User = Depends(require_role(Role.AM, Role.ADMIN)),
db: AsyncSession = Depends(get_db),
) -> Chemist:
return await ChemistService(db).review(chemist_id, False, payload.reason, current_user, client_ip(request))