Skip to content

Implement PATCH method for partial updates #41

@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/<squad_number> for partial updates.

  • All fields are patchable except squad_number (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 squad_number or id, the endpoint returns 400 Bad Request.

Suggested Approach

  1. Model — Add PlayerPatchRequest struct in src/models/player.rs with all patchable fields as Option<T>. Exclude squad_number and id.
  2. Service — Add a patch function in src/services/player_service.rs that retrieves the existing player by squad_number and applies only the Some(…) fields.
  3. Route — Add a #[patch("/players/squadnumber/<squad_number>")] handler in src/routes/players.rs. Check for forbidden fields → 400. Look up player → 404 if missing. Return Status::NoContent on success.
  4. Mount — Register the new route in src/main.rs.
  5. Tests — Add integration tests following the existing pattern.

Acceptance Criteria

  • PATCH /players/squadnumber/<squad_number> is implemented
  • All fields except squad_number 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 squad_number 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority:mediumPlanned enhancement. Queue for upcoming work.rustA language empowering everyone to build reliable and efficient software

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions