Skip to content

Implement PATCH method for partial updates #318

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} for partial updates (following the existing PUT and DELETE URL convention in this repo).

  • 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. DTO — Add PlayerPatchDTO in the models package with all patchable fields as nullable (e.g. String, Boolean). Exclude squadNumber and id. Annotate with @JsonInclude(JsonInclude.Include.NON_NULL) so absent fields serialize cleanly.
  2. Service — Add boolean patch(Integer squadNumber, PlayerPatchDTO dto) in PlayersService. Retrieve the existing player, apply only the non-null fields from the DTO, then persist.
  3. Controller — Add @PatchMapping("/players/{squadNumber}") in PlayersController. Check for forbidden fields (squadNumber, id) → 400. Look up player → 404 if missing. Return ResponseEntity<Void> with HttpStatus.NO_CONTENT on success.
  4. Tests — Add unit tests following existing naming conventions.

Acceptance Criteria

  • PATCH /players/{squadNumber} 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 if the body contains squadNumber or id
  • Returns 400 Bad Request on field validation failure
  • Returns 404 Not Found when no player has that squad number
  • Tests added following existing naming conventions
  • All existing tests continue to pass
  • CHANGELOG.md updated

References

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestjavaPull requests that update Java codepriority:mediumPlanned enhancement. Queue for upcoming work.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions