|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package endpoints
-
- import (
- "encoding/json"
- "net/http"
-
- . "github.com/imosed/signet/data"
- "github.com/rs/zerolog/log"
- )
-
- type AnalyticsFund struct {
- ID int `json:"id"`
- Asset string `json:"asset"`
- MinContribution float64 `json:"minContribution"`
- AmountAvailable float64 `json:"amountAvailable"`
- Memo string `json:"memo"`
- FundWallet string `json:"fundWallet"`
- Raised float64 `json:"raised"`
- }
-
- type NearlyCompleteFundsRequest struct {
- Threshold float32 `json:"threshold"`
- }
-
- type NearlyCompleteFundsResponse struct {
- Funds []AnalyticsFund `json:"funds"`
- }
-
- func NearlyCompleteFunds(w http.ResponseWriter, r *http.Request) {
- var req NearlyCompleteFundsRequest
- err := json.NewDecoder(r.Body).Decode(&req)
- if err != nil {
- log.Error().Err(err).Msg("Could not decode body in NearlyCompleteFunds call")
- return
- }
-
- var resp NearlyCompleteFundsResponse
- Db.Table("contributions").
- Select("rf.id", "asset", "min_contribution", "amount_available", "memo", "fund_wallet", "sum(amount) as raised").
- Joins("inner join reward_funds rf on rf.id = contributions.reward_fund_id").
- Where("rf.amount_available < ?", req.Threshold).
- Scan(&resp.Funds)
- err = json.NewEncoder(w).Encode(resp)
- if err != nil {
- log.Error().Err(err).Msg("Could not deliver response in NearlyCompleteFunds call")
- return
- }
- }
-
- // CompletedFundsRequest TODO: Finish out this for a future release
- type CompletedFundsRequest struct {
- }
-
- type CompletedFundsResponse struct {
- }
-
- func CompletedFunds(w http.ResponseWriter, r *http.Request) {
- var req CompletedFundsRequest
- err := json.NewDecoder(r.Body).Decode(&req)
- if err != nil {
- panic("Could not decode body")
- }
-
- var resp CompletedFundsResponse
-
- err = json.NewEncoder(w).Encode(resp)
- if err != nil {
- panic("Could not deliver response")
- }
- }
|