소스 검색

Add some admin functions

master
Jared 1 년 전
부모
커밋
baddac2672
4개의 변경된 파일115개의 추가작업 그리고 0개의 파일을 삭제
  1. +71
    -0
      endpoints/analytics.go
  2. +41
    -0
      endpoints/editqueue.go
  3. +1
    -0
      endpoints/getqueuemembers.go
  4. +2
    -0
      main.go

+ 71
- 0
endpoints/analytics.go 파일 보기

@@ -0,0 +1,71 @@
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").
Group("asset, rf.id, min_contribution, amount_available, memo, fund_wallet").
Having("sum(amount) between (rf.amount_available * ?) and rf.amount_available", req.Threshold/100).
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")
}
}

+ 41
- 0
endpoints/editqueue.go 파일 보기

@@ -0,0 +1,41 @@
package endpoints

import (
"encoding/json"
"net/http"

. "github.com/imosed/signet/data"
"github.com/rs/zerolog/log"
)

type FundOrder struct {
ID int `json:"id"`
Asset string `json:"asset"`
Order int `json:"order"`
}

type EditQueueRequest struct {
QueueID int `json:"queueID"`
FundOrders []FundOrder `json:"fundOrders"`
}

func EditQueue(w http.ResponseWriter, r *http.Request) {
var req EditQueueRequest
err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
log.Error().Err(err).Msg("Could not decode body in EditQueue call")
return
}

var resp SuccessResponse
for _, qo := range req.FundOrders {
Db.Table("queue_orders").
Where("reward_fund_id = ? and queue_id = ?", qo.ID, req.QueueID).
Update("order", qo.Order)
}

err = json.NewEncoder(w).Encode(resp)
if err != nil {
log.Error().Err(err).Msg("Could not deliver response in EditQueue call")
}
}

+ 1
- 0
endpoints/getqueuemembers.go 파일 보기

@@ -35,6 +35,7 @@ func GetQueueMembers(w http.ResponseWriter, r *http.Request) {
Db.Table("queue_orders qo").Select("rf.id, asset, title, qo.order").
Where("queue_id = ?", req.ID).
Joins("inner join reward_funds rf on qo.reward_fund_id = rf.id").
Order("qo.order").
Scan(&members)

var resp GetQueueMembersResponse


+ 2
- 0
main.go 파일 보기

@@ -37,6 +37,7 @@ func main() {
router.HandleFunc("/CreateQueue", endpoints.CreateQueue)
router.HandleFunc("/GetQueues", endpoints.GetQueues)
router.HandleFunc("/GetQueueMembers", endpoints.GetQueueMembers)
router.HandleFunc("/EditQueue", endpoints.EditQueue)
router.HandleFunc("/CreateRewardFund", endpoints.CreateRewardFund)
router.HandleFunc("/CloseRewardFund", endpoints.CloseRewardFund)
// router.HandleFunc("/SubmitFund", endpoints.SubmitFund)
@@ -45,6 +46,7 @@ func main() {
router.HandleFunc("/ContributorStream", endpoints.ContributorStream)
router.HandleFunc("/Login", endpoints.Login)
router.HandleFunc("/Register", endpoints.Register)
router.HandleFunc("/NearlyCompleteFunds", endpoints.NearlyCompleteFunds)
router.HandleFunc("/EscalatePrivileges", endpoints.EscalatePrivileges)
router.HandleFunc("/UsersExist", endpoints.UsersExist)



불러오는 중...
취소
저장