Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions broker/api/api-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (a *ApiHandler) GetEvents(w http.ResponseWriter, r *http.Request, params oa
}
resp.About.Count = fullCount
for _, event := range eventList {
resp.Items = append(resp.Items, toApiEvent(event))
resp.Items = append(resp.Items, ToApiEvent(event, event.IllTransactionID, nil))
}
writeJsonResponse(w, resp)
}
Expand Down Expand Up @@ -666,15 +666,16 @@ func addNotFoundError(w http.ResponseWriter) {
_ = json.NewEncoder(w).Encode(resp)
}

func toApiEvent(event events.Event) oapi.Event {
func ToApiEvent(event events.Event, illId string, prId *string) oapi.Event {
api := oapi.Event{
Id: event.ID,
Timestamp: event.Timestamp.Time,
IllTransactionID: event.IllTransactionID,
IllTransactionID: illId,
EventType: string(event.EventType),
EventName: string(event.EventName),
EventStatus: string(event.EventStatus),
ParentID: toString(event.ParentID),
PatronRequestID: prId,
}
eventData := utils.Must(common.StructToMap(event.EventData))
api.EventData = &eventData
Expand Down
2 changes: 1 addition & 1 deletion broker/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func Init(ctx context.Context) (Context, error) {
workflowManager := service.CreateWorkflowManager(eventBus, illRepo, service.WorkflowConfig{})
lmsCreator := lms.NewLmsCreator(illRepo, dirAdapter)
prActionService := prservice.CreatePatronRequestActionService(prRepo, eventBus, &iso18626Handler, lmsCreator)
prApiHandler := prapi.NewPrApiHandler(prRepo, eventBus, common.NewTenant(TENANT_TO_SYMBOL), API_PAGE_SIZE)
prApiHandler := prapi.NewPrApiHandler(prRepo, eventBus, eventRepo, common.NewTenant(TENANT_TO_SYMBOL), API_PAGE_SIZE)

sseBroker := api.NewSseBroker(appCtx, common.NewTenant(TENANT_TO_SYMBOL))

Expand Down
12 changes: 12 additions & 0 deletions broker/events/eventrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type EventRepo interface {
GetIllTransactionEvents(ctx common.ExtendedContext, id string) ([]Event, int64, error)
DeleteEventsByIllTransaction(ctx common.ExtendedContext, illTransId string) error
GetLatestRequestEventByAction(ctx common.ExtendedContext, illTransId string, action string) (Event, error)
GetPatronRequestEvents(ctx common.ExtendedContext, id string) ([]Event, error)
}

type PgEventRepo struct {
Expand Down Expand Up @@ -91,6 +92,17 @@ func (r *PgEventRepo) GetIllTransactionEvents(ctx common.ExtendedContext, id str
return events, fullCount, err
}

func (r *PgEventRepo) GetPatronRequestEvents(ctx common.ExtendedContext, id string) ([]Event, error) {
rows, err := r.queries.GetPatronRequestEvents(ctx, r.GetConnOrTx(), id)
var events []Event
if err == nil {
for _, r := range rows {
events = append(events, r.Event)
}
}
return events, err
}

func (r *PgEventRepo) DeleteEventsByIllTransaction(ctx common.ExtendedContext, illTransId string) error {
return r.queries.DeleteEventsByIllTransaction(ctx, r.GetConnOrTx(), illTransId)
}
Expand Down
40 changes: 40 additions & 0 deletions broker/oapi/open-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ components:
illTransactionID:
type: string
description: ID of the ILL transaction (if applicable)
patronRequestID:
type: string
description: ID of the Patron request (if applicable)
eventType:
type: string
description: Type of the event
Expand Down Expand Up @@ -1167,6 +1170,43 @@ paths:
schema:
$ref: '#/components/schemas/Error'

/patron_requests/{id}/events:
get:
summary: Retrieve patron request related events
parameters:
- in: path
name: id
schema:
type: string
required: true
description: ID of the patron request
- $ref: '#/components/parameters/Tenant'
- $ref: '#/components/parameters/Side'
- $ref: '#/components/parameters/Symbol'
tags:
- patron-requests-api
responses:
'200':
description: Successful retrieval of patron request events
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Event'
'400':
description: Bad Request. Invalid query parameters.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: Internal Server Error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'

/sse/events:
get:
summary: Subscribe to real-time notifications. Notification is send out every time when ISO18626 message is sent out
Expand Down
40 changes: 39 additions & 1 deletion broker/patron_request/api/api-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/indexdata/crosslink/broker/api"
"github.com/indexdata/crosslink/broker/common"
"github.com/indexdata/crosslink/broker/events"
"github.com/indexdata/crosslink/broker/oapi"
pr_db "github.com/indexdata/crosslink/broker/patron_request/db"
"github.com/indexdata/crosslink/broker/patron_request/proapi"
prservice "github.com/indexdata/crosslink/broker/patron_request/service"
Expand All @@ -29,15 +30,18 @@ type PatronRequestApiHandler struct {
limitDefault int32
prRepo pr_db.PrRepo
eventBus events.EventBus
eventRepo events.EventRepo
actionMappingService prservice.ActionMappingService
tenant common.Tenant
}

func NewPrApiHandler(prRepo pr_db.PrRepo, eventBus events.EventBus, tenant common.Tenant, limitDefault int32) PatronRequestApiHandler {
func NewPrApiHandler(prRepo pr_db.PrRepo, eventBus events.EventBus,
eventRepo events.EventRepo, tenant common.Tenant, limitDefault int32) PatronRequestApiHandler {
return PatronRequestApiHandler{
limitDefault: limitDefault,
prRepo: prRepo,
eventBus: eventBus,
eventRepo: eventRepo,
actionMappingService: prservice.ActionMappingService{},
tenant: tenant,
}
Expand Down Expand Up @@ -380,6 +384,40 @@ func (a *PatronRequestApiHandler) ConfirmActionProcess(ctx common.ExtendedContex
}
}

func (a *PatronRequestApiHandler) GetPatronRequestsIdEvents(w http.ResponseWriter, r *http.Request, id string, params proapi.GetPatronRequestsIdEventsParams) {
symbol, err := api.GetSymbolForRequest(r, a.tenant, params.XOkapiTenant, params.Symbol)
logParams := map[string]string{"method": "GetPatronRequestsIdEvents", "id": id, "symbol": symbol}
if params.Side != nil {
logParams["side"] = *params.Side
}
ctx := common.CreateExtCtxWithArgs(context.Background(), &common.LoggerArgs{Other: logParams})

if err != nil {
addBadRequestError(ctx, w, err)
return
}
pr, err := a.getPatronRequestById(ctx, id, params.Side, symbol)
if err != nil {
addInternalError(ctx, w, err)
return
}
if pr == nil {
addNotFoundError(w)
return
}
events, err := a.eventRepo.GetPatronRequestEvents(ctx, pr.ID)
if err != nil {
addInternalError(ctx, w, err)
return
}

var responseItems []oapi.Event
for _, event := range events {
responseItems = append(responseItems, api.ToApiEvent(event, "", &event.PatronRequestID))
}
writeJsonResponse(w, responseItems)
}

func writeJsonResponse(w http.ResponseWriter, resp any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
Expand Down
Loading
Loading