|
- package endpoints
-
- import (
- "encoding/json"
- "net/http"
-
- "github.com/imosed/signet/auth"
- . "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 claims *auth.Claims
- claims, err = auth.GetUserClaims(r)
- if err != nil {
- log.Error().Err(err).Msg("Could not get user claims in call to EditQueue")
- }
- if claims == nil {
- w.WriteHeader(401)
- return
- }
- if claims.Privileges > Admin {
- w.WriteHeader(403)
- 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")
- }
- }
|