The backend for the project formerly known as signet, now known as beignet.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

analytics.go 1.7 KiB

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