Just one function to get items for patron request#447
Merged
adamdickmeiss merged 2 commits intomainfrom Mar 11, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR consolidates patron-request item retrieval into a single helper used by both borrowing- and lending-side actions, and updates tests to match the new error strings.
Changes:
- Replace separate item-fetching helpers with a shared
getItemsmethod in the patron request action service. - Update action handlers to call the shared
getItemsmethod. - Adjust unit test expectations for updated error/cause messages.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| broker/patron_request/service/action.go | Unifies item lookup logic via getItems and updates borrowing/lending action paths to use it. |
| broker/patron_request/service/action_test.go | Updates assertions for revised error cause strings from the unified item lookup. |
Comments suppressed due to low confidence (3)
broker/patron_request/service/action.go:686
getItemslogs "multiple items found... using the first one", but the function returns the fullitemsslice unchanged and callers likeshipLenderRequestalso use all items (viaencodeItemsNote(items)). This warning is misleading and can create unnecessary noise in logs; either actually truncate toitems[:1](if only one is supported) or adjust/remove the warning and let the specific callers decide what to do with multiple items.
if len(items) > 1 {
ctx.Logger().Warn("multiple items found for patron request, using the first one", "itemCount", len(items))
}
return items, nil
broker/patron_request/service/action.go:685
getItems(and several call sites) rely onitems[0], butGetItemsByPrIddoes not specify anORDER BY(seebroker/sqlc/pr_query.sql), so the "first" item is nondeterministic when multiple rows exist. To make behavior stable, sort the returned slice (e.g., bycreated_at/id) before using index 0, or update the query to order deterministically.
func (a *PatronRequestActionService) getItems(ctx common.ExtendedContext, pr pr_db.PatronRequest) ([]pr_db.Item, error) {
items, err := a.prRepo.GetItemsByPrId(ctx, pr.ID)
if err != nil {
return nil, fmt.Errorf("failed to get items: %w", err)
}
if len(items) == 0 {
return nil, fmt.Errorf("no items found for patron request")
}
if len(items) > 1 {
ctx.Logger().Warn("multiple items found for patron request, using the first one", "itemCount", len(items))
}
broker/patron_request/service/action.go:685
- The warning for multiple items doesn't include the patron request identifier, which makes it hard to correlate in logs. Consider adding
prId(and potentially the barcodes/count) as structured fields on the warning log entry.
ctx.Logger().Warn("multiple items found for patron request, using the first one", "itemCount", len(items))
}
Co-authored-by: Copilot <[email protected]>
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.
Both sides.