Skip to content

Commit

Permalink
feat: Add GetResourceOffers method
Browse files Browse the repository at this point in the history
  • Loading branch information
bgins committed Dec 4, 2024
1 parent 7b791e7 commit 164e8ac
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion pkg/solver/store/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,32 @@ func (store *SolverStoreDatabase) GetJobOffers(query store.GetJobOffersQuery) ([
}

func (store *SolverStoreDatabase) GetResourceOffers(query store.GetResourceOffersQuery) ([]data.ResourceOfferContainer, error) {
resourceOffers := []data.ResourceOfferContainer{}
q := store.db.Where([]ResourceOffer{})

// Apply filters
if query.ResourceProvider != "" {
q = q.Where("resource_provider = ?", query.ResourceProvider)
}
if query.NotMatched {
q = q.Where("deal_id = ''")
}
if query.Active {
q = q.Where("state IN (?)", []uint8{
data.GetAgreementStateIndex("DealNegotiating"),
data.GetAgreementStateIndex("DealAgreed"),
})
}

var records []ResourceOffer
if err := q.Find(&records).Error; err != nil {
return nil, err
}

resourceOffers := make([]data.ResourceOfferContainer, len(records))
for i, record := range records {
resourceOffers[i] = record.Attributes.Data()
}

return resourceOffers, nil
}

Expand Down

0 comments on commit 164e8ac

Please sign in to comment.