From 80dd56f46dac2f9d326dff64a7c268353c2e62f1 Mon Sep 17 00:00:00 2001 From: Janis Saldabols Date: Tue, 3 Mar 2026 18:33:46 +0200 Subject: [PATCH 1/5] CROSSLINK-210 Add more search parameters --- broker/migrations/019_add_attention_field.down.sql | 1 + broker/migrations/019_add_attention_field.up.sql | 1 + broker/oapi/open-api.yaml | 4 ++++ broker/patron_request/api/api-handler.go | 1 + broker/patron_request/db/prcql.go | 1 + broker/sqlc/pr_query.sql | 7 ++++--- broker/sqlc/pr_schema.sql | 3 ++- broker/test/patron_request/api/api-handler_test.go | 1 + 8 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 broker/migrations/019_add_attention_field.down.sql create mode 100644 broker/migrations/019_add_attention_field.up.sql diff --git a/broker/migrations/019_add_attention_field.down.sql b/broker/migrations/019_add_attention_field.down.sql new file mode 100644 index 00000000..e4eef687 --- /dev/null +++ b/broker/migrations/019_add_attention_field.down.sql @@ -0,0 +1 @@ +ALTER TABLE patron_request DROP COLUMN needs_attention; \ No newline at end of file diff --git a/broker/migrations/019_add_attention_field.up.sql b/broker/migrations/019_add_attention_field.up.sql new file mode 100644 index 00000000..b31927ee --- /dev/null +++ b/broker/migrations/019_add_attention_field.up.sql @@ -0,0 +1 @@ +ALTER TABLE patron_request ADD COLUMN needs_attention BOOLEAN NOT NULL DEFAULT false; \ No newline at end of file diff --git a/broker/oapi/open-api.yaml b/broker/oapi/open-api.yaml index b15d2b9e..3e2831f7 100644 --- a/broker/oapi/open-api.yaml +++ b/broker/oapi/open-api.yaml @@ -465,12 +465,16 @@ components: requesterRequestId: type: string description: Requester patron request ID + needsAttention: + type: boolean + description: Indicates if the request needs attention required: - id - timestamp - state - side - illRequest + - needsAttention PatronRequests: type: object required: diff --git a/broker/patron_request/api/api-handler.go b/broker/patron_request/api/api-handler.go index 6bed3168..17736e4d 100644 --- a/broker/patron_request/api/api-handler.go +++ b/broker/patron_request/api/api-handler.go @@ -546,6 +546,7 @@ func toApiPatronRequest(request pr_db.PatronRequest, illRequest iso18626.Request SupplierSymbol: toString(request.SupplierSymbol), IllRequest: utils.Must(common.StructToMap(illRequest)), RequesterRequestId: toString(request.RequesterReqID), + NeedsAttention: request.NeedsAttention, } } diff --git a/broker/patron_request/db/prcql.go b/broker/patron_request/db/prcql.go index 3d7e194f..953e87f2 100644 --- a/broker/patron_request/db/prcql.go +++ b/broker/patron_request/db/prcql.go @@ -86,6 +86,7 @@ func (q *Queries) ListPatronRequestsCql(ctx context.Context, db DBTX, arg ListPa &i.PatronRequest.SupplierSymbol, &i.PatronRequest.Tenant, &i.PatronRequest.RequesterReqID, + &i.PatronRequest.NeedsAttention, &i.FullCount, ); err != nil { return nil, err diff --git a/broker/sqlc/pr_query.sql b/broker/sqlc/pr_query.sql index 5b9322bb..a2de28cd 100644 --- a/broker/sqlc/pr_query.sql +++ b/broker/sqlc/pr_query.sql @@ -20,13 +20,14 @@ SET timestamp = $2, requester_symbol = $7, supplier_symbol = $8, tenant = $9, - requester_req_id = $10 + requester_req_id = $10, + needs_attention = $11 WHERE id = $1 RETURNING sqlc.embed(patron_request); -- name: CreatePatronRequest :one -INSERT INTO patron_request (id, timestamp, ill_request, state, side, patron, requester_symbol, supplier_symbol, tenant, requester_req_id) -VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) +INSERT INTO patron_request (id, timestamp, ill_request, state, side, patron, requester_symbol, supplier_symbol, tenant, requester_req_id, needs_attention) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING sqlc.embed(patron_request); -- name: DeletePatronRequest :exec diff --git a/broker/sqlc/pr_schema.sql b/broker/sqlc/pr_schema.sql index 75dcd698..e614c5ce 100644 --- a/broker/sqlc/pr_schema.sql +++ b/broker/sqlc/pr_schema.sql @@ -9,7 +9,8 @@ CREATE TABLE patron_request requester_symbol VARCHAR, supplier_symbol VARCHAR, tenant VARCHAR, - requester_req_id VARCHAR + requester_req_id VARCHAR, + needs_attention BOOLEAN NOT NULL DEFAULT false ); CREATE OR REPLACE FUNCTION get_next_hrid(prefix VARCHAR) RETURNS VARCHAR AS $$ diff --git a/broker/test/patron_request/api/api-handler_test.go b/broker/test/patron_request/api/api-handler_test.go index 11258e80..9e0e0e51 100644 --- a/broker/test/patron_request/api/api-handler_test.go +++ b/broker/test/patron_request/api/api-handler_test.go @@ -130,6 +130,7 @@ func TestCrud(t *testing.T) { assert.Equal(t, *newPr.RequesterSymbol, *foundPr.RequesterSymbol) assert.Equal(t, *newPr.SupplierSymbol, *foundPr.SupplierSymbol) assert.Equal(t, *newPr.Patron, *foundPr.Patron) + assert.Equal(t, false, foundPr.NeedsAttention) respBytes = httpRequest(t, "POST", basePath, newPrBytes, 400) assert.Contains(t, string(respBytes), "a patron request with this ID already exists") From fe98b2d06c50bc775e466e4b8444eb5e7f4a3ebe Mon Sep 17 00:00:00 2001 From: Janis Saldabols Date: Thu, 5 Mar 2026 12:24:31 +0200 Subject: [PATCH 2/5] CROSSLINK-210 Add search criteria --- .../019_add_attention_field.down.sql | 4 +- .../migrations/019_add_attention_field.up.sql | 25 +++++++++- broker/oapi/open-api.yaml | 5 ++ broker/patron_request/api/api-handler.go | 1 + broker/patron_request/db/prcql.go | 48 ++++++++++++++----- broker/patron_request/db/prrepo.go | 19 ++++++-- broker/patron_request/service/action_test.go | 2 +- .../patron_request/service/message-handler.go | 4 +- broker/sqlc/pr_query.sql | 6 +-- broker/sqlc/pr_schema.sql | 23 +++++++++ .../patron_request/api/api-handler_test.go | 4 +- 11 files changed, 116 insertions(+), 25 deletions(-) diff --git a/broker/migrations/019_add_attention_field.down.sql b/broker/migrations/019_add_attention_field.down.sql index e4eef687..a20f2b40 100644 --- a/broker/migrations/019_add_attention_field.down.sql +++ b/broker/migrations/019_add_attention_field.down.sql @@ -1 +1,3 @@ -ALTER TABLE patron_request DROP COLUMN needs_attention; \ No newline at end of file +ALTER TABLE patron_request DROP COLUMN needs_attention; + +DROP VIEW patron_request_search_view ; \ No newline at end of file diff --git a/broker/migrations/019_add_attention_field.up.sql b/broker/migrations/019_add_attention_field.up.sql index b31927ee..7b02ef46 100644 --- a/broker/migrations/019_add_attention_field.up.sql +++ b/broker/migrations/019_add_attention_field.up.sql @@ -1 +1,24 @@ -ALTER TABLE patron_request ADD COLUMN needs_attention BOOLEAN NOT NULL DEFAULT false; \ No newline at end of file +ALTER TABLE patron_request ADD COLUMN needs_attention BOOLEAN NOT NULL DEFAULT false; + +CREATE OR REPLACE VIEW patron_request_search_view AS +SELECT + pr.*, + EXISTS ( + SELECT 1 + FROM notification n + WHERE n.pr_id = pr.id + ) AS has_notification, + EXISTS ( + SELECT 1 + FROM notification n + WHERE n.pr_id = pr.id and cost is not null + ) AS has_cost, + EXISTS ( + SELECT 1 + FROM notification n + WHERE n.pr_id = pr.id and acknowledged_at is null + ) AS has_unreaded_not, + pr.ill_request -> 'serviceInfo' ->> 'serviceType' AS service_type, + pr.ill_request -> 'serviceInfo' -> 'serviceLevel' ->> '#text' AS service_level, + (pr.ill_request -> 'serviceInfo' ->> 'needBeforeDate')::timestamptz AS needed_at +FROM patron_request pr; \ No newline at end of file diff --git a/broker/oapi/open-api.yaml b/broker/oapi/open-api.yaml index 3e2831f7..788f611a 100644 --- a/broker/oapi/open-api.yaml +++ b/broker/oapi/open-api.yaml @@ -1119,6 +1119,11 @@ paths: /patron_requests: get: summary: Retrieve patron requests + description: | + Use this endpoint to retrieve patron requests. + Query parameter cql can be used to filter the results. + With cql you can use these fields state, side, requester_symbol, supplier_symbol, needs_attention, + has_notification, has_cost, has_unreaded_notification, service_type, service_level, created_at, needed_at. tags: - patron-requests-api parameters: diff --git a/broker/patron_request/api/api-handler.go b/broker/patron_request/api/api-handler.go index 17736e4d..83f68f69 100644 --- a/broker/patron_request/api/api-handler.go +++ b/broker/patron_request/api/api-handler.go @@ -594,6 +594,7 @@ func (a *PatronRequestApiHandler) toDbPatronRequest(ctx common.ExtendedContext, SupplierSymbol: getDbText(request.SupplierSymbol), IllRequest: illRequest, Tenant: getDbText(tenant), + RequesterReqID: getDbText(&id), }, nil } diff --git a/broker/patron_request/db/prcql.go b/broker/patron_request/db/prcql.go index 953e87f2..be4da909 100644 --- a/broker/patron_request/db/prcql.go +++ b/broker/patron_request/db/prcql.go @@ -36,6 +36,30 @@ func handlePatronRequestsQuery(cqlString string, noBaseArgs int) (pgcql.Query, e f = pgcql.NewFieldString().WithExact() def.AddField("supplier_symbol", f) + f = pgcql.NewFieldString().WithExact() + def.AddField("needs_attention", f) + + f = pgcql.NewFieldString().WithExact() + def.AddField("has_notification", f) + + f = pgcql.NewFieldString().WithExact() + def.AddField("has_cost", f) + + f = pgcql.NewFieldString().WithExact() + def.AddField("has_unreaded_notification", f) + + f = pgcql.NewFieldString().WithExact() + def.AddField("service_type", f) + + f = pgcql.NewFieldString().WithExact() + def.AddField("service_level", f) + + nf := pgcql.NewFieldDate().WithColumn("timestamp") + def.AddField("created_at", nf) + + nf = pgcql.NewFieldDate() + def.AddField("needed_at", nf) + var parser cql.Parser query, err := parser.Parse(cqlString) if err != nil { @@ -49,7 +73,7 @@ func (q *Queries) ListPatronRequestsCql(ctx context.Context, db DBTX, arg ListPa if cqlString == nil { return q.ListPatronRequests(ctx, db, arg) } - noBaseArgs := 2 // weh have two base arguments: limit and offset + noBaseArgs := 2 // we have two base arguments: limit and offset res, err := handlePatronRequestsQuery(*cqlString, noBaseArgs) if err != nil { return nil, err @@ -76,17 +100,17 @@ func (q *Queries) ListPatronRequestsCql(ctx context.Context, db DBTX, arg ListPa for rows.Next() { var i ListPatronRequestsRow if err := rows.Scan( - &i.PatronRequest.ID, - &i.PatronRequest.Timestamp, - &i.PatronRequest.IllRequest, - &i.PatronRequest.State, - &i.PatronRequest.Side, - &i.PatronRequest.Patron, - &i.PatronRequest.RequesterSymbol, - &i.PatronRequest.SupplierSymbol, - &i.PatronRequest.Tenant, - &i.PatronRequest.RequesterReqID, - &i.PatronRequest.NeedsAttention, + &i.ID, + &i.Timestamp, + &i.IllRequest, + &i.State, + &i.Side, + &i.Patron, + &i.RequesterSymbol, + &i.SupplierSymbol, + &i.Tenant, + &i.RequesterReqID, + &i.NeedsAttention, &i.FullCount, ); err != nil { return nil, err diff --git a/broker/patron_request/db/prrepo.go b/broker/patron_request/db/prrepo.go index c59220e0..26ef4ece 100644 --- a/broker/patron_request/db/prrepo.go +++ b/broker/patron_request/db/prrepo.go @@ -15,7 +15,7 @@ type PrRepo interface { UpdatePatronRequest(ctx common.ExtendedContext, params UpdatePatronRequestParams) (PatronRequest, error) CreatePatronRequest(ctx common.ExtendedContext, params CreatePatronRequestParams) (PatronRequest, error) DeletePatronRequest(ctx common.ExtendedContext, id string) error - GetPatronRequestBySupplierSymbolAndRequesterReqId(ctx common.ExtendedContext, supplierSymbol string, requesterReId string) (PatronRequest, error) + GetPatronRequestBySupplierSymbolAndRequesterReqId(ctx common.ExtendedContext, supplierSymbol string, requesterReId string, side PatronRequestSide) (PatronRequest, error) GetNextHrid(ctx common.ExtendedContext, prefix string) (string, error) SaveItem(ctx common.ExtendedContext, params SaveItemParams) (Item, error) GetItemById(ctx common.ExtendedContext, id string) (Item, error) @@ -56,7 +56,19 @@ func (r *PgPrRepo) ListPatronRequests(ctx common.ExtendedContext, params ListPat fullCount = rows[0].FullCount for _, r := range rows { fullCount = r.FullCount - list = append(list, r.PatronRequest) + list = append(list, PatronRequest{ + ID: r.ID, + Timestamp: r.Timestamp, + IllRequest: r.IllRequest, + State: PatronRequestState(r.State), + Side: PatronRequestSide(r.Side), + Patron: r.Patron, + RequesterSymbol: r.RequesterSymbol, + SupplierSymbol: r.SupplierSymbol, + Tenant: r.Tenant, + RequesterReqID: r.RequesterReqID, + NeedsAttention: r.NeedsAttention, + }) } } else { params.Limit = 1 @@ -83,7 +95,7 @@ func (r *PgPrRepo) DeletePatronRequest(ctx common.ExtendedContext, id string) er return r.queries.DeletePatronRequest(ctx, r.GetConnOrTx(), id) } -func (r *PgPrRepo) GetPatronRequestBySupplierSymbolAndRequesterReqId(ctx common.ExtendedContext, supplierSymbol string, requesterReId string) (PatronRequest, error) { +func (r *PgPrRepo) GetPatronRequestBySupplierSymbolAndRequesterReqId(ctx common.ExtendedContext, supplierSymbol string, requesterReId string, side PatronRequestSide) (PatronRequest, error) { row, err := r.queries.GetPatronRequestBySupplierSymbolAndRequesterReqId(ctx, r.GetConnOrTx(), GetPatronRequestBySupplierSymbolAndRequesterReqIdParams{ SupplierSymbol: pgtype.Text{ String: supplierSymbol, @@ -93,6 +105,7 @@ func (r *PgPrRepo) GetPatronRequestBySupplierSymbolAndRequesterReqId(ctx common. String: requesterReId, Valid: true, }, + Side: side, }) return row.PatronRequest, err } diff --git a/broker/patron_request/service/action_test.go b/broker/patron_request/service/action_test.go index 70096cab..f9c7fd56 100644 --- a/broker/patron_request/service/action_test.go +++ b/broker/patron_request/service/action_test.go @@ -731,7 +731,7 @@ func (r *MockPrRepo) CreatePatronRequest(ctx common.ExtendedContext, params pr_d return pr_db.PatronRequest(params), nil } -func (r *MockPrRepo) GetPatronRequestBySupplierSymbolAndRequesterReqId(ctx common.ExtendedContext, symbol string, requesterReqId string) (pr_db.PatronRequest, error) { +func (r *MockPrRepo) GetPatronRequestBySupplierSymbolAndRequesterReqId(ctx common.ExtendedContext, symbol string, requesterReqId string, side pr_db.PatronRequestSide) (pr_db.PatronRequest, error) { args := r.Called(symbol, requesterReqId) return args.Get(0).(pr_db.PatronRequest), args.Error(1) } diff --git a/broker/patron_request/service/message-handler.go b/broker/patron_request/service/message-handler.go index bb3d5af6..8d894d7b 100644 --- a/broker/patron_request/service/message-handler.go +++ b/broker/patron_request/service/message-handler.go @@ -123,7 +123,7 @@ func (m *PatronRequestMessageHandler) getPatronRequest(ctx common.ExtendedContex return m.prRepo.GetPatronRequestById(ctx, msg.RequestingAgencyMessage.Header.SupplyingAgencyRequestId) } else { symbol := msg.RequestingAgencyMessage.Header.SupplyingAgencyId.AgencyIdType.Text + ":" + msg.RequestingAgencyMessage.Header.SupplyingAgencyId.AgencyIdValue - return m.prRepo.GetPatronRequestBySupplierSymbolAndRequesterReqId(ctx, symbol, msg.RequestingAgencyMessage.Header.RequestingAgencyRequestId) + return m.prRepo.GetPatronRequestBySupplierSymbolAndRequesterReqId(ctx, symbol, msg.RequestingAgencyMessage.Header.RequestingAgencyRequestId, SideLending) } } else if msg.Request != nil { return m.prRepo.GetPatronRequestById(ctx, msg.Request.Header.RequestingAgencyRequestId) @@ -292,7 +292,7 @@ func (m *PatronRequestMessageHandler) handleRequestMessage(ctx common.ExtendedCo } supplierSymbol := request.Header.SupplyingAgencyId.AgencyIdType.Text + ":" + request.Header.SupplyingAgencyId.AgencyIdValue requesterSymbol := request.Header.RequestingAgencyId.AgencyIdType.Text + ":" + request.Header.RequestingAgencyId.AgencyIdValue - _, err := m.prRepo.GetPatronRequestBySupplierSymbolAndRequesterReqId(ctx, supplierSymbol, raRequestId) + _, err := m.prRepo.GetPatronRequestBySupplierSymbolAndRequesterReqId(ctx, supplierSymbol, raRequestId, SideLending) if err != nil { if !errors.Is(err, pgx.ErrNoRows) { return createRequestResponse(request, iso18626.TypeMessageStatusERROR, &iso18626.ErrorData{ diff --git a/broker/sqlc/pr_query.sql b/broker/sqlc/pr_query.sql index a2de28cd..fa161294 100644 --- a/broker/sqlc/pr_query.sql +++ b/broker/sqlc/pr_query.sql @@ -5,8 +5,8 @@ WHERE id = $1 LIMIT 1; -- name: ListPatronRequests :many -SELECT sqlc.embed(patron_request), COUNT(*) OVER () as full_count -FROM patron_request +SELECT id, timestamp, ill_request, state, side, patron, requester_symbol, supplier_symbol, tenant, requester_req_id, needs_attention, COUNT(*) OVER () as full_count +FROM patron_request_search_view ORDER BY timestamp LIMIT $1 OFFSET $2; @@ -39,7 +39,7 @@ WHERE id = $1; -- params: supplier_symbol string, requester_req_id string SELECT sqlc.embed(patron_request) FROM patron_request -WHERE supplier_symbol = $1 AND requester_req_id = $2 +WHERE supplier_symbol = $1 AND requester_req_id = $2 AND side = $3 LIMIT 1; -- name: GetNextHrid :one diff --git a/broker/sqlc/pr_schema.sql b/broker/sqlc/pr_schema.sql index e614c5ce..8eec2ed2 100644 --- a/broker/sqlc/pr_schema.sql +++ b/broker/sqlc/pr_schema.sql @@ -46,3 +46,26 @@ CREATE TABLE notification created_at TIMESTAMP NOT NULL DEFAULT now(), acknowledged_at TIMESTAMP ); + +CREATE OR REPLACE VIEW patron_request_search_view AS +SELECT + pr.*, + EXISTS ( + SELECT 1 + FROM notification n + WHERE n.pr_id = pr.id + ) AS has_notification, + EXISTS ( + SELECT 1 + FROM notification n + WHERE n.pr_id = pr.id and cost is not null + ) AS has_cost, + EXISTS ( + SELECT 1 + FROM notification n + WHERE n.pr_id = pr.id and acknowledged_at is null + ) AS has_unreaded_not, + pr.ill_request -> 'serviceInfo' ->> 'serviceType' AS service_type, + pr.ill_request -> 'serviceInfo' -> 'serviceLevel' ->> '#text' AS service_level, + (pr.ill_request -> 'serviceInfo' ->> 'needBeforeDate')::timestamptz AS needed_at +FROM patron_request pr; \ No newline at end of file diff --git a/broker/test/patron_request/api/api-handler_test.go b/broker/test/patron_request/api/api-handler_test.go index 9e0e0e51..3e5b090f 100644 --- a/broker/test/patron_request/api/api-handler_test.go +++ b/broker/test/patron_request/api/api-handler_test.go @@ -267,10 +267,10 @@ func TestActionsToCompleteState(t *testing.T) { // Find supplier patron request test.WaitForPredicateToBeTrue(func() bool { - supPr, _ := prRepo.GetPatronRequestBySupplierSymbolAndRequesterReqId(appCtx, supplierSymbol, foundPr.Id) + supPr, _ := prRepo.GetPatronRequestBySupplierSymbolAndRequesterReqId(appCtx, supplierSymbol, foundPr.Id, prservice.SideLending) return supPr.ID != "" }) - supPr, err := prRepo.GetPatronRequestBySupplierSymbolAndRequesterReqId(appCtx, supplierSymbol, foundPr.Id) + supPr, err := prRepo.GetPatronRequestBySupplierSymbolAndRequesterReqId(appCtx, supplierSymbol, foundPr.Id, prservice.SideLending) assert.NoError(t, err) assert.NotNil(t, supPr.ID) From 4cbc7a09505b2a7de4919985b3183cb092f46744 Mon Sep 17 00:00:00 2001 From: Janis Saldabols Date: Thu, 5 Mar 2026 16:54:17 +0200 Subject: [PATCH 3/5] CROSSLINK-210 Add search criteria --- broker/migrations/019_add_attention_field.down.sql | 4 ++-- broker/migrations/019_add_attention_field.up.sql | 2 +- broker/patron_request/service/action_test.go | 2 +- .../patron_request/service/message-handler_test.go | 14 +++++++------- broker/sqlc/pr_query.sql | 2 +- broker/sqlc/pr_schema.sql | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/broker/migrations/019_add_attention_field.down.sql b/broker/migrations/019_add_attention_field.down.sql index a20f2b40..a32fa42a 100644 --- a/broker/migrations/019_add_attention_field.down.sql +++ b/broker/migrations/019_add_attention_field.down.sql @@ -1,3 +1,3 @@ -ALTER TABLE patron_request DROP COLUMN needs_attention; +DROP VIEW patron_request_search_view ; -DROP VIEW patron_request_search_view ; \ No newline at end of file +ALTER TABLE patron_request DROP COLUMN needs_attention; \ No newline at end of file diff --git a/broker/migrations/019_add_attention_field.up.sql b/broker/migrations/019_add_attention_field.up.sql index 7b02ef46..d05a9042 100644 --- a/broker/migrations/019_add_attention_field.up.sql +++ b/broker/migrations/019_add_attention_field.up.sql @@ -17,7 +17,7 @@ SELECT SELECT 1 FROM notification n WHERE n.pr_id = pr.id and acknowledged_at is null - ) AS has_unreaded_not, + ) AS has_unreaded_notification, pr.ill_request -> 'serviceInfo' ->> 'serviceType' AS service_type, pr.ill_request -> 'serviceInfo' -> 'serviceLevel' ->> '#text' AS service_level, (pr.ill_request -> 'serviceInfo' ->> 'needBeforeDate')::timestamptz AS needed_at diff --git a/broker/patron_request/service/action_test.go b/broker/patron_request/service/action_test.go index f9c7fd56..055aa9e0 100644 --- a/broker/patron_request/service/action_test.go +++ b/broker/patron_request/service/action_test.go @@ -732,7 +732,7 @@ func (r *MockPrRepo) CreatePatronRequest(ctx common.ExtendedContext, params pr_d } func (r *MockPrRepo) GetPatronRequestBySupplierSymbolAndRequesterReqId(ctx common.ExtendedContext, symbol string, requesterReqId string, side pr_db.PatronRequestSide) (pr_db.PatronRequest, error) { - args := r.Called(symbol, requesterReqId) + args := r.Called(symbol, requesterReqId, side) return args.Get(0).(pr_db.PatronRequest), args.Error(1) } diff --git a/broker/patron_request/service/message-handler_test.go b/broker/patron_request/service/message-handler_test.go index 88f06b4c..69b7adee 100644 --- a/broker/patron_request/service/message-handler_test.go +++ b/broker/patron_request/service/message-handler_test.go @@ -19,7 +19,7 @@ func TestGetPatronRequest(t *testing.T) { mockPrRepo := new(MockPrRepo) mockPrRepo.On("GetPatronRequestById", "req-id-1").Return(pr_db.PatronRequest{ID: "req-id-1"}, nil) mockPrRepo.On("GetPatronRequestById", "sam-id-1").Return(pr_db.PatronRequest{ID: "sam-id-1"}, nil) - mockPrRepo.On("GetPatronRequestBySupplierSymbolAndRequesterReqId", "ISIL:SUP1", "req-id-1").Return(pr_db.PatronRequest{ID: "sam-id-1"}, nil) + mockPrRepo.On("GetPatronRequestBySupplierSymbolAndRequesterReqId", "ISIL:SUP1", "req-id-1", SideLending).Return(pr_db.PatronRequest{ID: "sam-id-1"}, nil) handler := CreatePatronRequestMessageHandler(mockPrRepo, *new(events.EventRepo), *new(ill_db.IllRepo), *new(events.EventBus)) msg := iso18626.ISO18626Message{ @@ -581,7 +581,7 @@ func TestHandleRequestMessage(t *testing.T) { mockPrRepo := new(MockPrRepo) mockEventBus := new(MockEventBus) mockAutoActionRunner := &MockAutoActionRunner{} - mockPrRepo.On("GetPatronRequestBySupplierSymbolAndRequesterReqId", "ISIL:SUP1", "req-id-1").Return(pr_db.PatronRequest{}, pgx.ErrNoRows) + mockPrRepo.On("GetPatronRequestBySupplierSymbolAndRequesterReqId", "ISIL:SUP1", "req-id-1", SideLending).Return(pr_db.PatronRequest{}, pgx.ErrNoRows) handler := CreatePatronRequestMessageHandler(mockPrRepo, *new(events.EventRepo), *new(ill_db.IllRepo), mockEventBus) handler.SetAutoActionRunner(mockAutoActionRunner) @@ -614,7 +614,7 @@ func TestHandleRequestMessageAutoActionError(t *testing.T) { mockPrRepo := new(MockPrRepo) mockEventBus := new(MockEventBus) mockAutoActionRunner := &MockAutoActionRunner{err: errors.New("auto action failed")} - mockPrRepo.On("GetPatronRequestBySupplierSymbolAndRequesterReqId", "ISIL:SUP1", "req-id-1").Return(pr_db.PatronRequest{}, pgx.ErrNoRows) + mockPrRepo.On("GetPatronRequestBySupplierSymbolAndRequesterReqId", "ISIL:SUP1", "req-id-1", SideLending).Return(pr_db.PatronRequest{}, pgx.ErrNoRows) handler := CreatePatronRequestMessageHandler(mockPrRepo, *new(events.EventRepo), *new(ill_db.IllRepo), mockEventBus) handler.SetAutoActionRunner(mockAutoActionRunner) @@ -640,7 +640,7 @@ func TestHandleRequestMessageAutoActionError(t *testing.T) { func TestHandleRequestMessageMissingRequestId(t *testing.T) { mockPrRepo := new(MockPrRepo) mockEventBus := new(MockEventBus) - mockPrRepo.On("GetPatronRequestBySupplierSymbolAndRequesterReqId", "ISIL:SUP1", "req-id-1").Return(pr_db.PatronRequest{}, pgx.ErrNoRows) + mockPrRepo.On("GetPatronRequestBySupplierSymbolAndRequesterReqId", "ISIL:SUP1", "req-id-1", SideLending).Return(pr_db.PatronRequest{}, pgx.ErrNoRows) handler := CreatePatronRequestMessageHandler(mockPrRepo, *new(events.EventRepo), *new(ill_db.IllRepo), mockEventBus) status, resp, err := handler.handleRequestMessage(appCtx, iso18626.Request{ @@ -669,7 +669,7 @@ func TestHandleRequestMessageMissingRequestId(t *testing.T) { func TestHandleRequestMessageExistingRequest(t *testing.T) { mockPrRepo := new(MockPrRepo) mockEventBus := new(MockEventBus) - mockPrRepo.On("GetPatronRequestBySupplierSymbolAndRequesterReqId", "ISIL:SUP1", "req-id-1").Return(pr_db.PatronRequest{}, nil) + mockPrRepo.On("GetPatronRequestBySupplierSymbolAndRequesterReqId", "ISIL:SUP1", "req-id-1", SideLending).Return(pr_db.PatronRequest{}, nil) handler := CreatePatronRequestMessageHandler(mockPrRepo, *new(events.EventRepo), *new(ill_db.IllRepo), mockEventBus) status, resp, err := handler.handleRequestMessage(appCtx, iso18626.Request{ @@ -698,7 +698,7 @@ func TestHandleRequestMessageExistingRequest(t *testing.T) { func TestHandleRequestMessageSearchDbError(t *testing.T) { mockPrRepo := new(MockPrRepo) mockEventBus := new(MockEventBus) - mockPrRepo.On("GetPatronRequestBySupplierSymbolAndRequesterReqId", "ISIL:SUP1", "req-id-1").Return(pr_db.PatronRequest{}, errors.New("db error")) + mockPrRepo.On("GetPatronRequestBySupplierSymbolAndRequesterReqId", "ISIL:SUP1", "req-id-1", SideLending).Return(pr_db.PatronRequest{}, errors.New("db error")) handler := CreatePatronRequestMessageHandler(mockPrRepo, *new(events.EventRepo), *new(ill_db.IllRepo), mockEventBus) status, resp, err := handler.handleRequestMessage(appCtx, iso18626.Request{ @@ -727,7 +727,7 @@ func TestHandleRequestMessageSearchDbError(t *testing.T) { func TestHandleRequestMessageSaveError(t *testing.T) { mockPrRepo := new(MockPrRepo) mockEventBus := new(MockEventBus) - mockPrRepo.On("GetPatronRequestBySupplierSymbolAndRequesterReqId", "ISIL:SUP1", "error").Return(pr_db.PatronRequest{}, pgx.ErrNoRows) + mockPrRepo.On("GetPatronRequestBySupplierSymbolAndRequesterReqId", "ISIL:SUP1", "error", SideLending).Return(pr_db.PatronRequest{}, pgx.ErrNoRows) handler := CreatePatronRequestMessageHandler(mockPrRepo, *new(events.EventRepo), *new(ill_db.IllRepo), mockEventBus) status, resp, err := handler.handleRequestMessage(appCtx, iso18626.Request{ diff --git a/broker/sqlc/pr_query.sql b/broker/sqlc/pr_query.sql index fa161294..2c976947 100644 --- a/broker/sqlc/pr_query.sql +++ b/broker/sqlc/pr_query.sql @@ -36,7 +36,7 @@ FROM patron_request WHERE id = $1; -- name: GetPatronRequestBySupplierSymbolAndRequesterReqId :one --- params: supplier_symbol string, requester_req_id string +-- params: supplier_symbol string, requester_req_id string, side string SELECT sqlc.embed(patron_request) FROM patron_request WHERE supplier_symbol = $1 AND requester_req_id = $2 AND side = $3 diff --git a/broker/sqlc/pr_schema.sql b/broker/sqlc/pr_schema.sql index 8eec2ed2..3e1b8cfd 100644 --- a/broker/sqlc/pr_schema.sql +++ b/broker/sqlc/pr_schema.sql @@ -64,7 +64,7 @@ SELECT SELECT 1 FROM notification n WHERE n.pr_id = pr.id and acknowledged_at is null - ) AS has_unreaded_not, + ) AS has_unreaded_notification, pr.ill_request -> 'serviceInfo' ->> 'serviceType' AS service_type, pr.ill_request -> 'serviceInfo' -> 'serviceLevel' ->> '#text' AS service_level, (pr.ill_request -> 'serviceInfo' ->> 'needBeforeDate')::timestamptz AS needed_at From aed026cf4de3fec0c539573c654ffe0f42db1b6a Mon Sep 17 00:00:00 2001 From: Janis Saldabols Date: Fri, 6 Mar 2026 12:11:05 +0200 Subject: [PATCH 4/5] CROSSLINK-210 Fix spelling --- broker/migrations/019_add_attention_field.up.sql | 2 +- broker/oapi/open-api.yaml | 2 +- broker/patron_request/db/prcql.go | 2 +- broker/sqlc/pr_schema.sql | 2 +- go.work.sum | 12 ++++++++++++ 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/broker/migrations/019_add_attention_field.up.sql b/broker/migrations/019_add_attention_field.up.sql index d05a9042..87fbd83e 100644 --- a/broker/migrations/019_add_attention_field.up.sql +++ b/broker/migrations/019_add_attention_field.up.sql @@ -17,7 +17,7 @@ SELECT SELECT 1 FROM notification n WHERE n.pr_id = pr.id and acknowledged_at is null - ) AS has_unreaded_notification, + ) AS has_unread_notification, pr.ill_request -> 'serviceInfo' ->> 'serviceType' AS service_type, pr.ill_request -> 'serviceInfo' -> 'serviceLevel' ->> '#text' AS service_level, (pr.ill_request -> 'serviceInfo' ->> 'needBeforeDate')::timestamptz AS needed_at diff --git a/broker/oapi/open-api.yaml b/broker/oapi/open-api.yaml index 788f611a..17f016cd 100644 --- a/broker/oapi/open-api.yaml +++ b/broker/oapi/open-api.yaml @@ -1123,7 +1123,7 @@ paths: Use this endpoint to retrieve patron requests. Query parameter cql can be used to filter the results. With cql you can use these fields state, side, requester_symbol, supplier_symbol, needs_attention, - has_notification, has_cost, has_unreaded_notification, service_type, service_level, created_at, needed_at. + has_notification, has_cost, has_unread_notification, service_type, service_level, created_at, needed_at. tags: - patron-requests-api parameters: diff --git a/broker/patron_request/db/prcql.go b/broker/patron_request/db/prcql.go index be4da909..541eb460 100644 --- a/broker/patron_request/db/prcql.go +++ b/broker/patron_request/db/prcql.go @@ -46,7 +46,7 @@ func handlePatronRequestsQuery(cqlString string, noBaseArgs int) (pgcql.Query, e def.AddField("has_cost", f) f = pgcql.NewFieldString().WithExact() - def.AddField("has_unreaded_notification", f) + def.AddField("has_unread_notification", f) f = pgcql.NewFieldString().WithExact() def.AddField("service_type", f) diff --git a/broker/sqlc/pr_schema.sql b/broker/sqlc/pr_schema.sql index 3e1b8cfd..cb3f4801 100644 --- a/broker/sqlc/pr_schema.sql +++ b/broker/sqlc/pr_schema.sql @@ -64,7 +64,7 @@ SELECT SELECT 1 FROM notification n WHERE n.pr_id = pr.id and acknowledged_at is null - ) AS has_unreaded_notification, + ) AS has_unread_notification, pr.ill_request -> 'serviceInfo' ->> 'serviceType' AS service_type, pr.ill_request -> 'serviceInfo' -> 'serviceLevel' ->> '#text' AS service_level, (pr.ill_request -> 'serviceInfo' ->> 'needBeforeDate')::timestamptz AS needed_at diff --git a/go.work.sum b/go.work.sum index 5f35cd3f..e0f01fc9 100644 --- a/go.work.sum +++ b/go.work.sum @@ -408,7 +408,9 @@ github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1 github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= github.com/bytedance/sonic v1.10.0-rc3 h1:uNSnscRapXTwUgTyOF0GVljYD08p9X/Lbr9MweSV3V0= github.com/bytedance/sonic v1.10.0-rc3/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= +github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= +github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= @@ -433,7 +435,9 @@ github.com/cilium/ebpf v0.9.1/go.mod h1:+OhNOIXx/Fnu1IE8bJz2dzOA+VSfyTfdNUVdlQnx github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004 h1:lkAMpLVBDaj17e85keuznYcH5rqI438v41pKcBl4ZxQ= github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 h1:F1EaeKL/ta07PY/k9Os/UFtwERei2/XzGemhpGnBKNg= github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80= +github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50 h1:DBmgJDC9dTfkVyGgipamEh2BpGYxScCH1TOF1LL1cXc= github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50/go.mod h1:5e1+Vvlzido69INQaVO6d87Qn543Xr6nooe9Kz7oBFM= @@ -561,6 +565,7 @@ github.com/gabriel-vasile/mimetype v1.4.1 h1:TRWk7se+TOjCYgRth7+1/OYLNiRNIotknkF github.com/gabriel-vasile/mimetype v1.4.1/go.mod h1:05Vi0w3Y9c/lNvJOdmIwvrrAhX3rYhfQQCaf9VJcv7M= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -568,6 +573,7 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= +github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ= github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= github.com/go-jose/go-jose/v3 v3.0.3 h1:fFKWeig/irsp7XD2zBxvnmA/XaRWp5V3CBsZXJF7G7k= github.com/go-jose/go-jose/v3 v3.0.3/go.mod h1:5b+7YgP7ZICgJDBdfjZaIt+H/9L9T/YQrVfLAMboGkQ= @@ -587,6 +593,7 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.14.1 h1:9c50NUPC30zyuKprjL3vNZ0m5oG+jU0zvx4AqHGnv4k= github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= @@ -789,6 +796,7 @@ github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBF github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= @@ -805,6 +813,7 @@ github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0 github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/lestrrat-go/backoff/v2 v2.0.8 h1:oNb5E5isby2kiro9AgdHLv5N5tint1AnDVVf2E2un5A= github.com/lestrrat-go/backoff/v2 v2.0.8/go.mod h1:rHP/q/r9aT27n24JQLa7JhSQZCKBBOiM/uP402WwN8Y= @@ -928,6 +937,7 @@ github.com/package-url/packageurl-go v0.1.1-0.20220428063043-89078438f170 h1:DiL github.com/package-url/packageurl-go v0.1.1-0.20220428063043-89078438f170/go.mod h1:uQd4a7Rh3ZsVg5j0lNyAfyxIeGde9yrlhjF78GzeW0c= github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0= github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= @@ -1150,6 +1160,7 @@ go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.4.0 h1:A8WCeEWhLwPBKNbFi5Wv5UTCBx5zzubnXDlMOFAzFMc= golang.org/x/arch v0.4.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -1249,6 +1260,7 @@ golang.org/x/telemetry v0.0.0-20250908211612-aef8a434d053 h1:dHQOQddU4YHS5gY33/6 golang.org/x/telemetry v0.0.0-20250908211612-aef8a434d053/go.mod h1:+nZKN+XVh4LCiA9DV3ywrzN4gumyCnKjau3NGb9SGoE= golang.org/x/telemetry v0.0.0-20251008203120-078029d740a8 h1:LvzTn0GQhWuvKH/kVRS3R3bVAsdQWI7hvfLHGgh9+lU= golang.org/x/telemetry v0.0.0-20251008203120-078029d740a8/go.mod h1:Pi4ztBfryZoJEkyFTI5/Ocsu2jXyDr6iSdgJiYE/uwE= +golang.org/x/telemetry v0.0.0-20260109210033-bd525da824e2 h1:O1cMQHRfwNpDfDJerqRoE2oD+AFlyid87D40L/OkkJo= golang.org/x/telemetry v0.0.0-20260109210033-bd525da824e2/go.mod h1:b7fPSJ0pKZ3ccUh8gnTONJxhn3c/PS6tyzQvyqw4iA8= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= From 5d4d45a1e03a1af451ad644f59fbd46eb5e0c496 Mon Sep 17 00:00:00 2001 From: Janis Saldabols Date: Fri, 6 Mar 2026 16:47:36 +0200 Subject: [PATCH 5/5] CROSSLINK-210 Add needs attention when action failed --- broker/patron_request/service/action.go | 16 ++++++ broker/patron_request/service/action_test.go | 57 ++++++++++---------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/broker/patron_request/service/action.go b/broker/patron_request/service/action.go index ed48239b..408a49ea 100644 --- a/broker/patron_request/service/action.go +++ b/broker/patron_request/service/action.go @@ -120,6 +120,9 @@ func (a *PatronRequestActionService) finalizeActionExecution(ctx common.Extended } } + if execResult.outcome == ActionOutcomeFailure { + a.setNeedsAttention(ctx, updatedPr) + } return execResult.status, execResult.result } @@ -607,6 +610,19 @@ func (a *PatronRequestActionService) checkSupplyingResponse(status events.EventS return actionExecutionResult{status: events.EventStatusSuccess, result: nil, outcome: ActionOutcomeSuccess, pr: pr} } +func (a *PatronRequestActionService) setNeedsAttention(ctx common.ExtendedContext, pr pr_db.PatronRequest) { + prToUpdate, err := a.prRepo.GetPatronRequestById(ctx, pr.ID) + if err != nil { + ctx.Logger().Error("failed to read patron request", "error", err) + return + } + prToUpdate.NeedsAttention = true + _, err = a.prRepo.UpdatePatronRequest(ctx, pr_db.UpdatePatronRequestParams(prToUpdate)) + if err != nil { + ctx.Logger().Error("failed to update patron request", "error", err) + } +} + type ResponseCaptureWriter struct { IllMessage *iso18626.ISO18626Message StatusCode int diff --git a/broker/patron_request/service/action_test.go b/broker/patron_request/service/action_test.go index 37126d34..fb1f4205 100644 --- a/broker/patron_request/service/action_test.go +++ b/broker/patron_request/service/action_test.go @@ -115,12 +115,13 @@ func TestHandleBorrowingActionMissingRequesterSymbol(t *testing.T) { lmsCreator.On("GetAdapter", "ISIL:x").Return(lms.CreateLmsAdapterMockOK(), nil) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), new(handler.Iso18626Handler), lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{State: BorrowerStateNew, Side: SideBorrowing, Tenant: pgtype.Text{Valid: true, String: "testlib"}, IllRequest: illRequest}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, State: BorrowerStateNew, Side: SideBorrowing, Tenant: pgtype.Text{Valid: true, String: "testlib"}, IllRequest: illRequest}, nil) status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &actionValidate}}}) assert.Equal(t, events.EventStatusError, status) assert.Equal(t, "missing requester symbol", resultData.EventError.Message) + assert.True(t, mockPrRepo.savedPr.NeedsAttention) } func TestHandleInvokeActionValidateOK(t *testing.T) { @@ -129,7 +130,7 @@ func TestHandleInvokeActionValidateOK(t *testing.T) { lmsCreator.On("GetAdapter", "ISIL:x").Return(lms.CreateLmsAdapterMockOK(), nil) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), new(handler.Iso18626Handler), lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:x"}, State: BorrowerStateNew, Side: SideBorrowing, Tenant: pgtype.Text{Valid: true, String: "testlib"}}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:x"}, State: BorrowerStateNew, Side: SideBorrowing, Tenant: pgtype.Text{Valid: true, String: "testlib"}}, nil) status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &actionValidate}}}) @@ -144,7 +145,7 @@ func TestHandleInvokeActionValidateGetAdapterFailed(t *testing.T) { lmsCreator.On("GetAdapter", "ISIL:x").Return(lms.CreateLmsAdapterMockOK(), assert.AnError) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), new(handler.Iso18626Handler), lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:x"}, State: BorrowerStateNew, Side: SideBorrowing, Tenant: pgtype.Text{Valid: true, String: "testlib"}, IllRequest: illRequest}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:x"}, State: BorrowerStateNew, Side: SideBorrowing, Tenant: pgtype.Text{Valid: true, String: "testlib"}, IllRequest: illRequest}, nil) status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &actionValidate}}}) @@ -159,7 +160,7 @@ func TestHandleInvokeActionValidateLookupFailed(t *testing.T) { lmsCreator.On("GetAdapter", "ISIL:REC1").Return(createLmsAdapterMockFail(), nil) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), new(handler.Iso18626Handler), lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}, State: BorrowerStateNew, Side: SideBorrowing, Tenant: pgtype.Text{Valid: true, String: "testlib"}}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}, State: BorrowerStateNew, Side: SideBorrowing, Tenant: pgtype.Text{Valid: true, String: "testlib"}}, nil) status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &actionValidate}}}) @@ -174,7 +175,7 @@ func TestHandleInvokeActionSendRequest(t *testing.T) { mockIso18626Handler := new(MockIso18626Handler) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: BorrowerStateValidated, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: BorrowerStateValidated, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}}, nil) action := BorrowerActionSendRequest status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -205,7 +206,7 @@ func TestHandleInvokeActionReceiveOK(t *testing.T) { lmsCreator.On("GetAdapter", "ISIL:REC1").Return(lms.CreateLmsAdapterMockOK(), nil) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: BorrowerStateShipped, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}, SupplierSymbol: pgtype.Text{Valid: true, String: "ISIL:SUP1"}}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: BorrowerStateShipped, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}, SupplierSymbol: pgtype.Text{Valid: true, String: "ISIL:SUP1"}}, nil) action := BorrowerActionReceive status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) assert.Equal(t, events.EventStatusSuccess, status) @@ -221,7 +222,7 @@ func TestHandleInvokeActionReceiveAcceptItemFailed(t *testing.T) { prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") action := BorrowerActionReceive - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: BorrowerStateShipped, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}, SupplierSymbol: pgtype.Text{Valid: true, String: "ISIL:SUP1"}}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: BorrowerStateShipped, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}, SupplierSymbol: pgtype.Text{Valid: true, String: "ISIL:SUP1"}}, nil) status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -235,7 +236,7 @@ func TestHandleInvokeActionCheckOutOK(t *testing.T) { lmsCreator.On("GetAdapter", "ISIL:REC1").Return(lms.CreateLmsAdapterMockOK(), nil) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), new(handler.Iso18626Handler), lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, Patron: pgtype.Text{Valid: true, String: "patron1"}, State: BorrowerStateReceived, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, Patron: pgtype.Text{Valid: true, String: "patron1"}, State: BorrowerStateReceived, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}}, nil) action := BorrowerActionCheckOut status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -250,7 +251,7 @@ func TestHandleInvokeActionCheckOutFails(t *testing.T) { lmsCreator.On("GetAdapter", "ISIL:REC1").Return(createLmsAdapterMockFail(), nil) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), new(handler.Iso18626Handler), lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: BorrowerStateReceived, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: BorrowerStateReceived, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}}, nil) action := BorrowerActionCheckOut status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) assert.Equal(t, events.EventStatusError, status) @@ -263,7 +264,7 @@ func TestHandleInvokeActionCheckInOK(t *testing.T) { lmsCreator.On("GetAdapter", "ISIL:REC1").Return(lms.CreateLmsAdapterMockOK(), nil) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), new(handler.Iso18626Handler), lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: BorrowerStateCheckedOut, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: BorrowerStateCheckedOut, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}}, nil) action := BorrowerActionCheckIn status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -278,7 +279,7 @@ func TestHandleInvokeActionCheckInFails(t *testing.T) { lmsCreator.On("GetAdapter", "ISIL:REC1").Return(createLmsAdapterMockFail(), nil) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), new(handler.Iso18626Handler), lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: BorrowerStateCheckedOut, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: BorrowerStateCheckedOut, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}}, nil) action := BorrowerActionCheckIn status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) assert.Equal(t, events.EventStatusError, status) @@ -292,7 +293,7 @@ func TestHandleInvokeActionShipReturnOK(t *testing.T) { lmsCreator.On("GetAdapter", "ISIL:REC1").Return(lms.CreateLmsAdapterMockOK(), nil) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: BorrowerStateCheckedIn, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}, SupplierSymbol: pgtype.Text{Valid: true, String: "ISIL:SUP1"}}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: BorrowerStateCheckedIn, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}, SupplierSymbol: pgtype.Text{Valid: true, String: "ISIL:SUP1"}}, nil) action := BorrowerActionShipReturn status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -308,7 +309,7 @@ func TestHandleInvokeActionShipReturnFails(t *testing.T) { mockIso18626Handler := new(MockIso18626Handler) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: BorrowerStateCheckedIn, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}, SupplierSymbol: pgtype.Text{Valid: true, String: "ISIL:SUP1"}}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: BorrowerStateCheckedIn, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}, SupplierSymbol: pgtype.Text{Valid: true, String: "ISIL:SUP1"}}, nil) action := BorrowerActionShipReturn status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -323,7 +324,7 @@ func TestHandleInvokeActionCancelRequest(t *testing.T) { mockIso18626Handler := new(MockIso18626Handler) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: BorrowerStateWillSupply, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}, SupplierSymbol: pgtype.Text{Valid: true, String: "ISIL:SUP1"}}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: BorrowerStateWillSupply, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}, SupplierSymbol: pgtype.Text{Valid: true, String: "ISIL:SUP1"}}, nil) action := BorrowerActionCancelRequest status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -339,7 +340,7 @@ func TestHandleInvokeActionAcceptCondition(t *testing.T) { mockIso18626Handler := new(MockIso18626Handler) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: BorrowerStateConditionPending, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}, SupplierSymbol: pgtype.Text{Valid: true, String: "ISIL:SUP1"}}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: BorrowerStateConditionPending, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}, SupplierSymbol: pgtype.Text{Valid: true, String: "ISIL:SUP1"}}, nil) action := BorrowerActionAcceptCondition status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -355,7 +356,7 @@ func TestHandleInvokeActionRejectCondition(t *testing.T) { mockIso18626Handler := new(MockIso18626Handler) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: BorrowerStateConditionPending, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}, SupplierSymbol: pgtype.Text{Valid: true, String: "ISIL:SUP1"}}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: BorrowerStateConditionPending, Side: SideBorrowing, RequesterSymbol: pgtype.Text{Valid: true, String: "ISIL:REC1"}, SupplierSymbol: pgtype.Text{Valid: true, String: "ISIL:SUP1"}}, nil) action := BorrowerActionRejectCondition status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -441,7 +442,7 @@ func TestHandleInvokeLenderActionNoSupplierSymbol(t *testing.T) { lmsCreator := new(MockLmsCreator) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), new(handler.Iso18626Handler), lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: LenderStateNew, Side: SideLending}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: LenderStateNew, Side: SideLending}, nil) status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &actionValidate}}}) @@ -456,7 +457,7 @@ func TestHandleInvokeLenderActionNoLms(t *testing.T) { prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), new(handler.Iso18626Handler), lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: LenderStateNew, Side: SideLending, SupplierSymbol: pgtype.Text{Valid: true, String: "ISIL:SUP1"}}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: LenderStateNew, Side: SideLending, SupplierSymbol: pgtype.Text{Valid: true, String: "ISIL:SUP1"}}, nil) status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &actionValidate}}}) @@ -512,7 +513,7 @@ func TestHandleInvokeLenderActionWillSupplyOK(t *testing.T) { mockIso18626Handler := new(MockIso18626Handler) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: LenderStateValidated, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: LenderStateValidated, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) action := LenderActionWillSupply status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -529,7 +530,7 @@ func TestHandleInvokeLenderActionWillSupplyNcipFailed(t *testing.T) { prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: LenderStateValidated, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: LenderStateValidated, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) action := LenderActionWillSupply status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -544,7 +545,7 @@ func TestHandleInvokeLenderActionCannotSupply(t *testing.T) { mockIso18626Handler := new(MockIso18626Handler) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: LenderStateValidated, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: LenderStateValidated, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) action := LenderActionCannotSupply status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -560,7 +561,7 @@ func TestHandleInvokeLenderActionAddCondition(t *testing.T) { mockIso18626Handler := new(MockIso18626Handler) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: LenderStateValidated, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: LenderStateValidated, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) action := LenderActionAddCondition status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -577,7 +578,7 @@ func TestHandleInvokeLenderActionShipOK(t *testing.T) { mockIso18626Handler := new(MockIso18626Handler) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: LenderStateWillSupply, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: LenderStateWillSupply, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) action := LenderActionShip status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -594,7 +595,7 @@ func TestHandleInvokeLenderActionShipLmsFailed(t *testing.T) { mockIso18626Handler := new(MockIso18626Handler) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: LenderStateWillSupply, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: LenderStateWillSupply, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) action := LenderActionShip status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -610,7 +611,7 @@ func TestHandleInvokeLenderActionMarkReceivedOK(t *testing.T) { mockIso18626Handler := new(MockIso18626Handler) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: LenderStateShippedReturn, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: LenderStateShippedReturn, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) action := LenderActionMarkReceived status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -626,7 +627,7 @@ func TestHandleInvokeLenderActionMarkReceivedLmsFailed(t *testing.T) { mockIso18626Handler := new(MockIso18626Handler) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: LenderStateShippedReturn, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: LenderStateShippedReturn, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) action := LenderActionMarkReceived status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -641,7 +642,7 @@ func TestHandleInvokeLenderActionMarkCancelled(t *testing.T) { mockIso18626Handler := new(MockIso18626Handler) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: LenderStateCancelRequested, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: LenderStateCancelRequested, Side: SideLending, SupplierSymbol: getDbText("ISIL:SUP1"), RequesterSymbol: getDbText("ISIL:REQ1")}, nil) action := LenderActionMarkCancelled status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}}) @@ -658,7 +659,7 @@ func TestHandleInvokeLenderActionMarkCancelledMissingRequesterSymbol(t *testing. mockIso18626Handler := new(MockIso18626Handler) prAction := CreatePatronRequestActionService(mockPrRepo, *new(events.EventBus), mockIso18626Handler, lmsCreator) illRequest := []byte("{\"request\": {}}") - mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{IllRequest: illRequest, State: LenderStateCancelRequested, Side: SideLending, RequesterSymbol: pgtype.Text{Valid: false, String: ""}, SupplierSymbol: getDbText("ISIL:SUP1")}, nil) + mockPrRepo.On("GetPatronRequestById", patronRequestId).Return(pr_db.PatronRequest{ID: patronRequestId, IllRequest: illRequest, State: LenderStateCancelRequested, Side: SideLending, RequesterSymbol: pgtype.Text{Valid: false, String: ""}, SupplierSymbol: getDbText("ISIL:SUP1")}, nil) action := LenderActionMarkCancelled status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}})