-
Notifications
You must be signed in to change notification settings - Fork 25
Implement PATCH method for partial updates #461
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or requestpriority:mediumPlanned enhancement. Queue for upcoming work.Planned enhancement. Queue for upcoming work.pythonPull requests that update Python codePull requests that update Python code
Description
Activity
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestpriority:mediumPlanned enhancement. Queue for upcoming work.Planned enhancement. Queue for upcoming work.pythonPull requests that update Python codePull requests that update Python code
Problem
The API supports
PUTfor player updates, which requires sending the complete player payload even when only one or two fields need to change. APATCHendpoint would allow callers to update specific fields without providing the entire resource.Proposed Solution
Add
PATCH /players/squadnumber/{squad_number}for partial updates.squad_number(natural key, present in the URL path) andid(UUID surrogate key).squad_numberorid, the endpoint returns400 Bad Request.Suggested Approach
PlayerPatchRequestModelinmodels/player_model.pywith all patchable fields asOptional[T] = None. Excludesquad_numberandid. Usemodel_config = ConfigDict(extra="forbid")is optional; alternatively, explicitly check for forbidden fields in the route.async def patch_by_squad_number_async(async_session, squad_number, patch_model)inservices/player_service.py. Usepatch_model.model_dump(exclude_unset=True)to get only the provided fields and apply them.@api_router.patch("/players/squadnumber/{squad_number}", status_code=status.HTTP_204_NO_CONTENT)inroutes/player_route.py. Check for forbidden fields →400. Look up player →404if missing. Invalidate cache on success.tests/test_main.pyfollowing the existing naming pattern.Acceptance Criteria
PATCH /players/squadnumber/{squad_number}is implementedsquad_numberandidare patchable204 No Contenton success400 Bad Requestif the body containssquad_numberorid400 Bad Requeston field validation failure404 Not Foundwhen no player has that squad numberCHANGELOG.mdupdatedReferences
exclude_unset