The backend for the project formerly known as signet, now known as beignet.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package endpoints
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "github.com/imosed/signet/auth"
  6. . "github.com/imosed/signet/data"
  7. "github.com/rs/zerolog/log"
  8. )
  9. type FundOrder struct {
  10. ID int `json:"id"`
  11. Asset string `json:"asset"`
  12. Order int `json:"order"`
  13. }
  14. type EditQueueRequest struct {
  15. QueueID int `json:"queueID"`
  16. FundOrders []FundOrder `json:"fundOrders"`
  17. }
  18. func EditQueue(w http.ResponseWriter, r *http.Request) {
  19. var req EditQueueRequest
  20. err := json.NewDecoder(r.Body).Decode(&req)
  21. if err != nil {
  22. log.Error().Err(err).Msg("Could not decode body in EditQueue call")
  23. return
  24. }
  25. var claims *auth.Claims
  26. claims, err = auth.GetUserClaims(r)
  27. if err != nil {
  28. log.Error().Err(err).Msg("Could not get user claims in call to EditQueue")
  29. }
  30. if claims == nil {
  31. w.WriteHeader(401)
  32. return
  33. }
  34. if claims.Privileges > Admin {
  35. w.WriteHeader(403)
  36. return
  37. }
  38. var resp SuccessResponse
  39. for _, qo := range req.FundOrders {
  40. Db.Table("queue_orders").
  41. Where("reward_fund_id = ? and queue_id = ?", qo.ID, req.QueueID).
  42. Update("order", qo.Order)
  43. }
  44. err = json.NewEncoder(w).Encode(resp)
  45. if err != nil {
  46. log.Error().Err(err).Msg("Could not deliver response in EditQueue call")
  47. }
  48. }