Skip to content

Commit 43fed6f

Browse files
authored
Merge pull request #173 from kbase/xfer-journal-endpoint
Added a transfer record endpoint for querying the journal.
2 parents 8e7ad48 + d36dd24 commit 43fed6f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

services/prototype.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/kbase/dts/config"
2828
"github.com/kbase/dts/databases"
2929
"github.com/kbase/dts/endpoints"
30+
"github.com/kbase/dts/journal"
3031
"github.com/kbase/dts/tasks"
3132
)
3233

@@ -72,6 +73,7 @@ func NewDTSPrototype() (TransferService, error) {
7273
huma.Post(api, "/api/v1/transfers", service.createTransfer)
7374
huma.Get(api, "/api/v1/transfers/{id}", service.getTransferStatus)
7475
huma.Delete(api, "/api/v1/transfers/{id}", service.deleteTransfer)
76+
huma.Get(api, "/api/v1/transfers/records", service.getTransferRecords)
7577

7678
return service, nil
7779
}
@@ -781,6 +783,32 @@ func (service *prototype) deleteTransfer(ctx context.Context,
781783
}, nil
782784
}
783785

786+
type TransferRecordsOutput struct {
787+
Body []journal.Record
788+
}
789+
790+
// handler method for querying the transfer journal over a time period
791+
func (service *prototype) getTransferRecords(ctx context.Context,
792+
input *struct {
793+
Authorization string `header:"authorization" doc:"Authorization header with encoded access token"`
794+
Start time.Time `path:"start" example:"2025-01-02T15:04:05Z07:00" doc:"the start date for the requested transfers"`
795+
End time.Time `path:"end" example:"2025-02-01T11:00:00Z07:00" doc:"the end date for the requested transfers"`
796+
}) (*TransferRecordsOutput, error) {
797+
798+
_, err := authorize(input.Authorization)
799+
if err != nil {
800+
return nil, err
801+
}
802+
803+
records, err := journal.Records(input.Start, input.End)
804+
if err != nil {
805+
return nil, huma.Error404NotFound(err.Error())
806+
}
807+
return &TransferRecordsOutput{
808+
Body: records,
809+
}, nil
810+
}
811+
784812
// returns the uptime for the service in seconds
785813
func (service *prototype) uptime() float64 {
786814
return time.Since(service.StartTime).Seconds()

0 commit comments

Comments
 (0)