Skip to content

Implement PATCH method for partial updates #342

@nanotaboada

Description

@nanotaboada

Problem

The API supports PUT for player updates, which requires sending the complete player payload even when only one or two fields need to change. A PATCH endpoint would allow callers to update specific fields without providing the entire resource.

Proposed Solution

Add PATCH /players/squadNumber/{squadNumber:int} for partial updates.

  • All fields are patchable except SquadNumber (natural key, present in the URL path) and Id (UUID surrogate key).
  • Only the fields present in the request body are updated; absent fields retain their current values.
  • If the request body includes SquadNumber or Id, the endpoint returns 400 Bad Request.

Suggested Approach

  1. Model — Add PlayerPatchRequestModel in Models/ with all patchable fields nullable (e.g. string?, bool?). Exclude SquadNumber and Id.
  2. Validator — Add PlayerPatchRequestModelValidator with a "Patch" rule set in Validators/. Only validate fields that are present (non-null). Register via AddValidatorsFromAssemblyContaining.
  3. Mapping — Add a PlayerPatchRequestModel → Player profile in PlayerMappingProfile, configured to ignore null source values.
  4. Service — Add PatchAsync(int squadNumber, PlayerPatchRequestModel model) to IPlayerService and PlayerService. Reuse RetrieveBySquadNumberAsync.
  5. Controller — Add [HttpPatch("squadNumber/{squadNumber:int}")] action. Check that the body does not contain SquadNumber or Id; return 400 if present. Return 404 if not found. Return 204 No Content on success.
  6. Tests — Add unit tests to PlayerControllerTests and PlayerServiceTests following existing naming conventions.

Acceptance Criteria

  • PATCH /players/squadNumber/{squadNumber:int} is implemented
  • All fields except SquadNumber and Id are patchable
  • Fields absent from the request body are left unchanged
  • Returns 204 No Content on success
  • Returns 400 Bad Request (RFC 9457) if the body contains SquadNumber or Id
  • Returns 400 Bad Request (RFC 9457) on field validation failure
  • Returns 404 Not Found (RFC 9457) when no player has that squad number
  • Cache is invalidated after a successful patch (if applicable)
  • Unit tests added for controller and service layers
  • All existing tests continue to pass
  • CHANGELOG.md updated

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    dotnetPull requests that update .NET codeenhancementNew feature or requestpriority:mediumPlanned enhancement. Queue for upcoming work.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions