package endpoints import ( "encoding/json" . "github.com/imosed/signet/data" "gorm.io/gorm/clause" "net/http" ) func GetRewardFunds(w http.ResponseWriter, r *http.Request) { var req GetRewardFundsRequest err := json.NewDecoder(r.Body).Decode(&req) if err != nil { panic("Could not decode body") } var resp GetRewardFundsResponse var rewardFunds []RewardFund Db.Table("reward_funds").Count(&resp.Total) Db.Preload(clause.Associations).Table("reward_funds"). Select("id", "created_at", "asset", "fund_wallet", "issuer_wallet", "memo", "min_contribution", "amount_available", "title"). Order("created_at desc"). Find(&rewardFunds) for _, f := range rewardFunds { resp.RewardFunds = append(resp.RewardFunds, FundInfo{ ID: f.ID, CreatedAt: f.CreatedAt, Asset: f.Asset, FundWallet: f.FundWallet, IssuerWallet: f.IssuerWallet, Memo: f.Memo, AmountAvailable: f.AmountAvailable, MinContribution: f.MinContribution, Title: f.Title, Description: f.Description, Bonuses: f.Bonuses, }) } err = json.NewEncoder(w).Encode(resp) if err != nil { panic("Could not deliver response") } } type GetRewardFundsRequest struct { Offset int `json:"offset"` } type GetRewardFundsResponse struct { RewardFunds []FundInfo `json:"rewardFunds"` Total int64 `json:"total"` }