The backend for the project formerly known as signet, now known as beignet.
Você não pode selecionar mais de 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.

71 linhas
1.8 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("contributions").
  32. Select("rf.id", "asset", "min_contribution", "amount_available", "memo", "fund_wallet", "sum(amount) as raised").
  33. Joins("inner join reward_funds rf on rf.id = contributions.reward_fund_id").
  34. Where("rf.amount_available < ?", req.Threshold).
  35. Scan(&resp.Funds)
  36. err = json.NewEncoder(w).Encode(resp)
  37. if err != nil {
  38. log.Error().Err(err).Msg("Could not deliver response in NearlyCompleteFunds call")
  39. return
  40. }
  41. }
  42. // CompletedFundsRequest TODO: Finish out this for a future release
  43. type CompletedFundsRequest struct {
  44. }
  45. type CompletedFundsResponse struct {
  46. }
  47. func CompletedFunds(w http.ResponseWriter, r *http.Request) {
  48. var req CompletedFundsRequest
  49. err := json.NewDecoder(r.Body).Decode(&req)
  50. if err != nil {
  51. panic("Could not decode body")
  52. }
  53. var resp CompletedFundsResponse
  54. err = json.NewEncoder(w).Encode(resp)
  55. if err != nil {
  56. panic("Could not deliver response")
  57. }
  58. }