Skip to content

POST patron request errors if id already exists#413

Open
adamdickmeiss wants to merge 6 commits intomainfrom
CROSSLINK-126-patron-request-improvements
Open

POST patron request errors if id already exists#413
adamdickmeiss wants to merge 6 commits intomainfrom
CROSSLINK-126-patron-request-improvements

Conversation

@adamdickmeiss
Copy link
Contributor

@adamdickmeiss adamdickmeiss commented Feb 19, 2026

https://index-data.atlassian.net/browse/CROSSLINK-216

Split SavePatronRequest into {Create,Update}PatronRequest. There are no cases where we want upsert.

Split SavePatronRequest into {Create,Update}PatronRequest.
There are no cases where we want upsert.
Copilot AI review requested due to automatic review settings February 19, 2026 17:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

}

func toLinkPath(r *http.Request, path string, query string) string {
func ToLinkPath(r *http.Request, path string, query string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamdickmeiss why not move it to common?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You got it and I also wondered why there are three common.go in this project now.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments