Implement PATCH for pprs
This commit is contained in:
@@ -101,6 +101,39 @@ async def update_ppr(
|
|||||||
return ppr
|
return ppr
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch("/{ppr_id}", response_model=PPR)
|
||||||
|
async def patch_ppr(
|
||||||
|
request: Request,
|
||||||
|
ppr_id: int,
|
||||||
|
ppr_in: PPRUpdate,
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
current_user: User = Depends(get_current_active_user)
|
||||||
|
):
|
||||||
|
"""Partially update a PPR record (only provided fields will be updated)"""
|
||||||
|
db_ppr = crud_ppr.get(db, ppr_id=ppr_id)
|
||||||
|
if not db_ppr:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
|
detail="PPR record not found"
|
||||||
|
)
|
||||||
|
|
||||||
|
# For PATCH, we only update fields that are explicitly provided (not None)
|
||||||
|
ppr = crud_ppr.update(db, db_obj=db_ppr, obj_in=ppr_in)
|
||||||
|
|
||||||
|
# Send real-time update
|
||||||
|
if hasattr(request.app.state, 'connection_manager'):
|
||||||
|
await request.app.state.connection_manager.broadcast({
|
||||||
|
"type": "ppr_updated",
|
||||||
|
"data": {
|
||||||
|
"id": ppr.id,
|
||||||
|
"ac_reg": ppr.ac_reg,
|
||||||
|
"status": ppr.status.value
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return ppr
|
||||||
|
|
||||||
|
|
||||||
@router.patch("/{ppr_id}/status", response_model=PPR)
|
@router.patch("/{ppr_id}/status", response_model=PPR)
|
||||||
async def update_ppr_status(
|
async def update_ppr_status(
|
||||||
request: Request,
|
request: Request,
|
||||||
|
|||||||
Reference in New Issue
Block a user