The backend for the project formerly known as signet, now known as beignet.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

55 wiersze
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", "amount_goal", "min_contribution", "close_time", "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. AmountGoal: f.AmountGoal,
  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. }