POST patron request errors if id already exists#413
Open
adamdickmeiss wants to merge 6 commits intomainfrom
Open
POST patron request errors if id already exists#413adamdickmeiss wants to merge 6 commits intomainfrom
adamdickmeiss wants to merge 6 commits intomainfrom
Conversation
Split SavePatronRequest into {Create,Update}PatronRequest.
There are no cases where we want upsert.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the patron request database operations by splitting the upsert-based SavePatronRequest method into separate CreatePatronRequest and UpdatePatronRequest methods. This provides better control over create vs. update semantics and enables proper error handling for duplicate creation attempts.
Changes:
- Split SQL query from upsert (INSERT ... ON CONFLICT DO UPDATE) into separate UPDATE and INSERT queries
- Updated repository interface and implementation to expose CreatePatronRequest and UpdatePatronRequest methods
- Modified service layer to use UpdatePatronRequest for existing patron requests and CreatePatronRequest for new ones
- Added error handling in POST endpoint to catch and report duplicate patron request creation attempts
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| broker/sqlc/pr_query.sql | Split SavePatronRequest into UpdatePatronRequest and CreatePatronRequest queries, removing ON CONFLICT logic |
| broker/patron_request/db/prrepo.go | Updated interface and implementation to replace SavePatronRequest with separate Update and Create methods |
| broker/patron_request/service/message-handler.go | Changed calls to use CreatePatronRequest for new requests and UpdatePatronRequest for updates |
| broker/patron_request/service/action.go | Updated to use UpdatePatronRequest for state changes |
| broker/patron_request/api/api-handler.go | Added integrity constraint violation handling for duplicate creation attempts |
| broker/patron_request/api/api-handler_test.go | Updated mock implementations and added blank lines for consistency |
| broker/patron_request/service/action_test.go | Updated mock to implement both Create and Update methods separately |
| broker/test/patron_request/db/prrepo_test.go | Updated tests to use CreatePatronRequest |
| broker/test/patron_request/api/api-handler_test.go | Added test case for duplicate POST attempt |
Comments suppressed due to low confidence (1)
broker/patron_request/db/prrepo.go:77
- Missing blank line between function definitions. There should be a blank line between UpdatePatronRequest and CreatePatronRequest functions to maintain consistency with the rest of the codebase.
func (r *PgPrRepo) CreatePatronRequest(ctx common.ExtendedContext, params CreatePatronRequestParams) (PatronRequest, error) {
jakub-id
reviewed
Feb 20, 2026
jakub-id
reviewed
Feb 20, 2026
broker/api/api-handler.go
Outdated
| } | ||
|
|
||
| func toLinkPath(r *http.Request, path string, query string) string { | ||
| func ToLinkPath(r *http.Request, path string, query string) string { |
Contributor
Author
There was a problem hiding this comment.
You got it and I also wondered why there are three common.go in this project now.
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.
https://index-data.atlassian.net/browse/CROSSLINK-216
Split SavePatronRequest into {Create,Update}PatronRequest. There are no cases where we want upsert.