The backend for the project formerly known as signet, now known as beignet.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

getrewardfunds.go 1.4 KiB

pirms 2 gadiem
pirms 2 gadiem
pirms 2 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package endpoints
  2. import (
  3. "encoding/json"
  4. . "github.com/imosed/signet/data"
  5. "gorm.io/gorm/clause"
  6. "net/http"
  7. )
  8. func GetRewardFunds(w http.ResponseWriter, r *http.Request) {
  9. var req GetRewardFundsRequest
  10. err := json.NewDecoder(r.Body).Decode(&req)
  11. if err != nil {
  12. panic("Could not decode body")
  13. }
  14. var resp GetRewardFundsResponse
  15. var rewardFunds []RewardFund
  16. Db.Table("reward_funds").Count(&resp.Total)
  17. Db.Preload(clause.Associations).Table("reward_funds").
  18. Select("id", "created_at", "asset", "fund_wallet", "issuer_wallet", "memo", "min_contribution", "amount_available", "title").
  19. Order("created_at desc").
  20. Find(&rewardFunds)
  21. for _, f := range rewardFunds {
  22. resp.RewardFunds = append(resp.RewardFunds, FundInfo{
  23. ID: f.ID,
  24. CreatedAt: f.CreatedAt,
  25. Asset: f.Asset,
  26. FundWallet: f.FundWallet,
  27. IssuerWallet: f.IssuerWallet,
  28. Memo: f.Memo,
  29. AmountAvailable: f.AmountAvailable,
  30. MinContribution: f.MinContribution,
  31. Title: f.Title,
  32. Description: f.Description,
  33. Bonuses: f.Bonuses,
  34. })
  35. }
  36. err = json.NewEncoder(w).Encode(resp)
  37. if err != nil {
  38. panic("Could not deliver response")
  39. }
  40. }
  41. type GetRewardFundsRequest struct {
  42. Offset int `json:"offset"`
  43. }
  44. type GetRewardFundsResponse struct {
  45. RewardFunds []FundInfo `json:"rewardFunds"`
  46. Total int64 `json:"total"`
  47. }