|
|
|
@ -9,7 +9,7 @@ import (
|
|
|
|
|
"git.vdhsn.com/barretthousen/barretthousen/src/lib/kernel"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var ErrDuplicateAuctionImported = errors.New("this auction's fingerprint matches one that has already been imported")
|
|
|
|
|
var ErrDuplicateAuctionImported = errors.New("another auction with the same fingerprint exists")
|
|
|
|
|
|
|
|
|
|
type (
|
|
|
|
|
Usecase struct {
|
|
|
|
@ -17,7 +17,7 @@ type (
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Storage interface {
|
|
|
|
|
GetUpcoming(context.Context, UpcomingQuery) ([]Auction, int64, error)
|
|
|
|
|
GetUpcoming(context.Context, UpcomingQuery) ([]Auction, int64, int64, error)
|
|
|
|
|
CreateUpcoming(context.Context, Auction) (string, error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -40,12 +40,13 @@ type (
|
|
|
|
|
UpcomingResults struct {
|
|
|
|
|
Page int
|
|
|
|
|
Total int64
|
|
|
|
|
Found int64
|
|
|
|
|
Results []Auction
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (d *Usecase) GetUpcoming(ctx context.Context, q UpcomingQuery) (results UpcomingResults, err error) {
|
|
|
|
|
if results.Results, results.Total, err = d.Storage.GetUpcoming(ctx, q); err != nil {
|
|
|
|
|
if results.Results, results.Total, results.Found, err = d.Storage.GetUpcoming(ctx, q); err != nil {
|
|
|
|
|
err = fmt.Errorf("could not get upcoming from storage: %w", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -53,19 +54,20 @@ func (d *Usecase) GetUpcoming(ctx context.Context, q UpcomingQuery) (results Upc
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: tests
|
|
|
|
|
func (d *Usecase) ImportAuction(ctx context.Context, in ImportAuctionMessage) (event AuctionCreated, err error) {
|
|
|
|
|
if in.Fingerprint, err = d.Storage.CreateUpcoming(ctx, in.Auction); err != nil && !errors.Is(err, ErrDuplicateAuctionImported) {
|
|
|
|
|
err = fmt.Errorf("could not import auction: %w", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Duplicates aren't an error, instead let the requester know
|
|
|
|
|
err = nil
|
|
|
|
|
event = AuctionCreated{
|
|
|
|
|
Auction: in.Auction,
|
|
|
|
|
Duplicate: errors.Is(err, ErrDuplicateAuctionImported),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = nil
|
|
|
|
|
|
|
|
|
|
status := "✅"
|
|
|
|
|
if event.Duplicate {
|
|
|
|
|
status = "🚫"
|
|
|
|
|