The backend for the project formerly known as signet, now known as beignet.
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

55 linhas
1.4 KiB

  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. }