The backend for the project formerly known as signet, now known as beignet.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

70 řádky
1.7 KiB

  1. package endpoints
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. . "github.com/imosed/signet/data"
  6. "github.com/rs/zerolog/log"
  7. )
  8. type AnalyticsFund struct {
  9. ID int `json:"id"`
  10. Asset string `json:"asset"`
  11. MinContribution float64 `json:"minContribution"`
  12. AmountAvailable float64 `json:"amountAvailable"`
  13. Memo string `json:"memo"`
  14. FundWallet string `json:"fundWallet"`
  15. Raised float64 `json:"raised"`
  16. }
  17. type NearlyCompleteFundsRequest struct {
  18. Threshold float32 `json:"threshold"`
  19. }
  20. type NearlyCompleteFundsResponse struct {
  21. Funds []AnalyticsFund `json:"funds"`
  22. }
  23. func NearlyCompleteFunds(w http.ResponseWriter, r *http.Request) {
  24. var req NearlyCompleteFundsRequest
  25. err := json.NewDecoder(r.Body).Decode(&req)
  26. if err != nil {
  27. log.Error().Err(err).Msg("Could not decode body in NearlyCompleteFunds call")
  28. return
  29. }
  30. var resp NearlyCompleteFundsResponse
  31. Db.Table("reward_funds").
  32. Select("id", "asset", "min_contribution", "amount_available", "memo", "fund_wallet").
  33. Where("amount_available < ?", req.Threshold).
  34. Scan(&resp.Funds)
  35. err = json.NewEncoder(w).Encode(resp)
  36. if err != nil {
  37. log.Error().Err(err).Msg("Could not deliver response in NearlyCompleteFunds call")
  38. return
  39. }
  40. }
  41. // CompletedFundsRequest TODO: Finish out this for a future release
  42. type CompletedFundsRequest struct {
  43. }
  44. type CompletedFundsResponse struct {
  45. }
  46. func CompletedFunds(w http.ResponseWriter, r *http.Request) {
  47. var req CompletedFundsRequest
  48. err := json.NewDecoder(r.Body).Decode(&req)
  49. if err != nil {
  50. panic("Could not decode body")
  51. }
  52. var resp CompletedFundsResponse
  53. err = json.NewEncoder(w).Encode(resp)
  54. if err != nil {
  55. panic("Could not deliver response")
  56. }
  57. }