Improvement: Add PATCH Support to PullRequestController (SZ-33)
rk@tigase.net opened 2 weeks ago

Problem

The current PUT /api/pullrequests/{id} endpoint expects a full PullRequest object. This causes:

  • Risk of null values overwriting non-nullable fields like status
  • Clients being forced to send unchanged or immutable fields (e.g. source, author)
  • Redundant payloads and boilerplate in tests
  • Poor ergonomics for UI and API consumers

Goal

Introduce a PATCH /api/pullrequests/{id} endpoint that:

  • Accepts a lightweight DTO (PullRequestUpdateDto) with only mutable fields
  • Performs a partial update by merging changes into the existing DB entity
  • Prevents mutation of critical fields like id, author, source, target, issue, etc.
  • Returns the updated PullRequest object

Example Request

PATCH /api/pullrequests/42
Content-Type: application/json

{
  "title": "Fix typo in title",
  "description": "Clarify PR scope"
}

Acceptance Criteria

  •  Define PullRequestUpdateDto with fields:
    • String title
    • String description
    • (Possibly) PullRequestStatus status
  •  Add new endpoint in controller:
    @PatchMapping("/{id}")
    public ResponseEntity<PullRequest> patchPullRequest(...)
    
  •  Implement patch logic: load entity from DB, apply non-null fields from DTO, and persist
  •  Validate that protected fields (e.g. author, source) remain unchanged
  •  Add unit tests to verify:
    • Title-only patch
    • Description-only patch
    • Empty patch (no-op)
    • Invalid patch (e.g. null title when required)

Notes

This improvement avoids bloated update logic in tests and UI flows, and brings the API closer to best practices for partial updates.

issue 1 of 1
Type
Improvement
Priority
Normal
Assignee
Version
1.0
Sprints
n/a
Customer
n/a
Issue Votes (0)
Watchers (3)
Reference
SZ-33
Please wait...
Page is in error, reload to recover