Skip to content

Commit 600d19e

Browse files
CROSSLINK-120 pagination (#191)
OpenAPI clean up. Refers to more common schemas Peers: CQL syntax error returns 400 (was 500). All API calls returning lists are returning resultInfo structure and they accept limit, offset query parameters. next, prev link for /ill_transactions. TODO: /peers does not include links yet. Pagination needs fixing for CQL.
1 parent 1c90cb2 commit 600d19e

File tree

10 files changed

+667
-411
lines changed

10 files changed

+667
-411
lines changed

broker/api/api-handler.go

Lines changed: 199 additions & 99 deletions
Large diffs are not rendered by default.

broker/events/eventrepo.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ type EventRepo interface {
1414
UpdateEventStatus(ctx extctx.ExtendedContext, params UpdateEventStatusParams) error
1515
GetEvent(ctx extctx.ExtendedContext, id string) (Event, error)
1616
Notify(ctx extctx.ExtendedContext, eventId string, signal Signal) error
17-
GetIllTransactionEvents(ctx extctx.ExtendedContext, illTransactionId string) ([]Event, error)
18-
ListEvents(ctx extctx.ExtendedContext) ([]Event, error)
17+
GetIllTransactionEvents(ctx extctx.ExtendedContext, params GetIllTransactionEventsParams) ([]Event, int64, error)
1918
DeleteEventsByIllTransaction(ctx extctx.ExtendedContext, illTransId string) error
2019
}
2120

@@ -61,26 +60,17 @@ func (r *PgEventRepo) Notify(ctx extctx.ExtendedContext, eventId string, signal
6160
return err
6261
}
6362

64-
func (r *PgEventRepo) GetIllTransactionEvents(ctx extctx.ExtendedContext, illTransactionId string) ([]Event, error) {
63+
func (r *PgEventRepo) GetIllTransactionEvents(ctx extctx.ExtendedContext, illTransactionId GetIllTransactionEventsParams) ([]Event, int64, error) {
6564
rows, err := r.queries.GetIllTransactionEvents(ctx, r.GetConnOrTx(), illTransactionId)
6665
var events []Event
66+
var fullCount int64
6767
if err == nil {
6868
for _, r := range rows {
69+
fullCount = r.FullCount
6970
events = append(events, r.Event)
7071
}
7172
}
72-
return events, err
73-
}
74-
75-
func (r *PgEventRepo) ListEvents(ctx extctx.ExtendedContext) ([]Event, error) {
76-
rows, err := r.queries.ListEvents(ctx, r.GetConnOrTx())
77-
var events []Event
78-
if err == nil {
79-
for _, r := range rows {
80-
events = append(events, r.Event)
81-
}
82-
}
83-
return events, err
73+
return events, fullCount, err
8474
}
8575

8676
func (r *PgEventRepo) DeleteEventsByIllTransaction(ctx extctx.ExtendedContext, illTransId string) error {

broker/ill_db/illrepo.go

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ type IllRepo interface {
2020
GetIllTransactionByRequesterRequestIdForUpdate(ctx extctx.ExtendedContext, requesterRequestID pgtype.Text) (IllTransaction, error)
2121
GetIllTransactionById(ctx extctx.ExtendedContext, id string) (IllTransaction, error)
2222
GetIllTransactionByIdForUpdate(ctx extctx.ExtendedContext, id string) (IllTransaction, error)
23-
ListIllTransactions(ctx extctx.ExtendedContext) ([]IllTransaction, error)
23+
ListIllTransactions(ctx extctx.ExtendedContext, params ListIllTransactionsParams) ([]IllTransaction, int64, error)
24+
GetIllTransactionsByRequesterSymbol(ctx extctx.ExtendedContext, params GetIllTransactionsByRequesterSymbolParams) ([]IllTransaction, int64, error)
2425
DeleteIllTransaction(ctx extctx.ExtendedContext, id string) error
2526
SavePeer(ctx extctx.ExtendedContext, params SavePeerParams) (Peer, error)
2627
GetPeerById(ctx extctx.ExtendedContext, id string) (Peer, error)
2728
GetPeerBySymbol(ctx extctx.ExtendedContext, symbol string) (Peer, error)
28-
ListPeers(ctx extctx.ExtendedContext) ([]Peer, error)
29+
ListPeers(ctx extctx.ExtendedContext, params ListPeersParams) ([]Peer, int64, error)
2930
DeletePeer(ctx extctx.ExtendedContext, id string) error
3031
SaveLocatedSupplier(ctx extctx.ExtendedContext, params SaveLocatedSupplierParams) (LocatedSupplier, error)
3132
GetLocatedSupplierByIllTransactionAndStatus(ctx extctx.ExtendedContext, params GetLocatedSupplierByIllTransactionAndStatusParams) ([]LocatedSupplier, error)
32-
GetLocatedSupplierByIllTransition(ctx extctx.ExtendedContext, illTransactionID string) ([]LocatedSupplier, error)
33-
ListLocatedSuppliers(ctx extctx.ExtendedContext) ([]LocatedSupplier, error)
33+
GetLocatedSupplierByIllTransaction(ctx extctx.ExtendedContext, params GetLocatedSupplierByIllTransactionParams) ([]LocatedSupplier, int64, error)
3434
GetLocatedSupplierByIllTransactionAndStatusForUpdate(ctx extctx.ExtendedContext, params GetLocatedSupplierByIllTransactionAndStatusForUpdateParams) ([]LocatedSupplier, error)
3535
GetLocatedSupplierByIllTransactionAndSupplierForUpdate(ctx extctx.ExtendedContext, params GetLocatedSupplierByIllTransactionAndSupplierForUpdateParams) (LocatedSupplier, error)
3636
GetSelectedSupplierForIllTransaction(ctx extctx.ExtendedContext, illTransId string) (LocatedSupplier, error)
@@ -86,15 +86,40 @@ func (r *PgIllRepo) GetIllTransactionByIdForUpdate(ctx extctx.ExtendedContext, i
8686
return row.IllTransaction, err
8787
}
8888

89-
func (r *PgIllRepo) ListIllTransactions(ctx extctx.ExtendedContext) ([]IllTransaction, error) {
90-
rows, err := r.queries.ListIllTransactions(ctx, r.GetConnOrTx())
89+
func (r *PgIllRepo) ListIllTransactions(ctx extctx.ExtendedContext, params ListIllTransactionsParams) ([]IllTransaction, int64, error) {
90+
rows, err := r.queries.ListIllTransactions(ctx, r.GetConnOrTx(), params)
9191
var transactions []IllTransaction
92+
var fullCount int64
93+
if err == nil {
94+
if len(rows) > 0 {
95+
fullCount = rows[0].FullCount
96+
for _, r := range rows {
97+
fullCount = r.FullCount
98+
transactions = append(transactions, r.IllTransaction)
99+
}
100+
} else {
101+
params.Limit = 1
102+
params.Offset = 0
103+
rows, err = r.queries.ListIllTransactions(ctx, r.GetConnOrTx(), params)
104+
if err == nil && len(rows) > 0 {
105+
fullCount = rows[0].FullCount
106+
}
107+
}
108+
}
109+
return transactions, fullCount, err
110+
}
111+
112+
func (r *PgIllRepo) GetIllTransactionsByRequesterSymbol(ctx extctx.ExtendedContext, params GetIllTransactionsByRequesterSymbolParams) ([]IllTransaction, int64, error) {
113+
rows, err := r.queries.GetIllTransactionsByRequesterSymbol(ctx, r.GetConnOrTx(), params)
114+
var transactions []IllTransaction
115+
var fullCount int64
92116
if err == nil {
93117
for _, r := range rows {
118+
fullCount = r.FullCount
94119
transactions = append(transactions, r.IllTransaction)
95120
}
96121
}
97-
return transactions, err
122+
return transactions, fullCount, err
98123
}
99124

100125
func (r *PgIllRepo) DeleteIllTransaction(ctx extctx.ExtendedContext, id string) error {
@@ -111,15 +136,17 @@ func (r *PgIllRepo) GetPeerBySymbol(ctx extctx.ExtendedContext, symbol string) (
111136
return row.Peer, err
112137
}
113138

114-
func (r *PgIllRepo) ListPeers(ctx extctx.ExtendedContext) ([]Peer, error) {
115-
rows, err := r.queries.ListPeers(ctx, r.GetConnOrTx())
139+
func (r *PgIllRepo) ListPeers(ctx extctx.ExtendedContext, params ListPeersParams) ([]Peer, int64, error) {
140+
rows, err := r.queries.ListPeers(ctx, r.GetConnOrTx(), params)
116141
var peers []Peer
142+
var fullCount int64
117143
if err == nil {
118144
for _, r := range rows {
145+
fullCount = r.FullCount
119146
peers = append(peers, r.Peer)
120147
}
121148
}
122-
return peers, err
149+
return peers, fullCount, err
123150
}
124151

125152
func (r *PgIllRepo) GetLocatedSupplierByIllTransactionAndStatus(ctx extctx.ExtendedContext, params GetLocatedSupplierByIllTransactionAndStatusParams) ([]LocatedSupplier, error) {
@@ -163,25 +190,17 @@ func (r *PgIllRepo) GetLocatedSupplierByIllTransactionAndSupplierForUpdate(ctx e
163190
return row.LocatedSupplier, err
164191
}
165192

166-
func (r *PgIllRepo) GetLocatedSupplierByIllTransition(ctx extctx.ExtendedContext, illTransactionID string) ([]LocatedSupplier, error) {
167-
rows, err := r.queries.GetLocatedSupplierByIllTransition(ctx, r.GetConnOrTx(), illTransactionID)
193+
func (r *PgIllRepo) GetLocatedSupplierByIllTransaction(ctx extctx.ExtendedContext, params GetLocatedSupplierByIllTransactionParams) ([]LocatedSupplier, int64, error) {
194+
rows, err := r.queries.GetLocatedSupplierByIllTransaction(ctx, r.GetConnOrTx(), params)
168195
var suppliers []LocatedSupplier
196+
var fullCount int64
169197
if err == nil {
170198
for _, r := range rows {
199+
fullCount = r.FullCount
171200
suppliers = append(suppliers, r.LocatedSupplier)
172201
}
173202
}
174-
return suppliers, err
175-
}
176-
func (r *PgIllRepo) ListLocatedSuppliers(ctx extctx.ExtendedContext) ([]LocatedSupplier, error) {
177-
rows, err := r.queries.ListLocatedSuppliers(ctx, r.GetConnOrTx())
178-
var suppliers []LocatedSupplier
179-
if err == nil {
180-
for _, r := range rows {
181-
suppliers = append(suppliers, r.LocatedSupplier)
182-
}
183-
}
184-
return suppliers, err
203+
return suppliers, fullCount, err
185204
}
186205

187206
func (r *PgIllRepo) GetSelectedSupplierForIllTransaction(ctx extctx.ExtendedContext, illTransId string) (LocatedSupplier, error) {

0 commit comments

Comments
 (0)