From 7b791e7865c3064097a413542b768c2a9a998eeb Mon Sep 17 00:00:00 2001 From: Brian Ginsburg Date: Tue, 3 Dec 2024 20:45:13 -0800 Subject: [PATCH] feat: Add GetResourceOfferByAddress method --- pkg/solver/store/db/db.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/solver/store/db/db.go b/pkg/solver/store/db/db.go index 223818d2..3a7a9a68 100644 --- a/pkg/solver/store/db/db.go +++ b/pkg/solver/store/db/db.go @@ -168,8 +168,18 @@ func (store *SolverStoreDatabase) GetResourceOffer(id string) (*data.ResourceOff } func (store *SolverStoreDatabase) GetResourceOfferByAddress(address string) (*data.ResourceOfferContainer, error) { - resourceOffer := &data.ResourceOfferContainer{} - return resourceOffer, nil + var record ResourceOffer + result := store.db.Where("resource_provider = ?", address).First(&record) + + if result.Error != nil { + if errors.Is(result.Error, gorm.ErrRecordNotFound) { + return nil, nil + } + return nil, result.Error + } + + resourceOffer := record.Attributes.Data() + return &resourceOffer, nil } func (store *SolverStoreDatabase) GetDeal(id string) (*data.DealContainer, error) {