Idempotency: honor Idempotency-Key header and apply it to deletes - #91
Merged
Conversation
Write endpoints previously took the idempotency key only from the JSON body's optional idempotency_key field, and delete handlers never passed a key at all — so deletes had no idempotency protection. - Add an idempotencyKey helper that prefers the conventional Idempotency-Key HTTP header and falls back to the body field for backward compatibility (header wins when both are present). - Resolve the key via the helper in all six mutating handlers, and plumb it into DeleteProductCommand/DeleteSellerCommand (fields already existed but were never populated). - Document the header in the OpenAPI spec and README. Fully backward compatible: existing body-key and no-key callers are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
The recently added race-safe idempotency layer (#86) is well-built and correctly placed at the application-service layer, but it had two gaps at the HTTP boundary:
DeleteProductController/DeleteSellerControllerbuilt their commands with onlyIdand never setIdempotencyKey, even though the command structs already had the field. An empty key short-circuitswithIdempotency, so delete replays were never cached.idempotency_key) rather than the conventionalIdempotency-KeyHTTP header — a notable smell for a reference repo people copy into production.This PR closes both gaps. No new infrastructure — the existing
withIdempotencywrapper, repository, table, and command fields are reused as-is.Changes
idempotencyKeyhelper (internal/interface/api/rest/idempotency.go) — prefers theIdempotency-Keyheader, falls back to the request body'sidempotency_keyfield for backward compatibility (header wins when both are present).DeleteProductCommand/DeleteSellerCommand.Idempotency-Keyheader parameter referenced from every write operation, plus an updated description.