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.

analytics.go 1.9 KiB

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