The backend for the project formerly known as signet, now known as beignet.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

getqueuemembers.go 1.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 QueueMember struct {
  10. ID uint `json:"id"`
  11. Asset string `json:"asset"`
  12. Order int `json:"order"`
  13. }
  14. type GetQueueMembersRequest struct {
  15. ID uint `json:"id"`
  16. }
  17. type GetQueueMembersResponse struct {
  18. Members []QueueMember `json:"members"`
  19. }
  20. func GetQueueMembers(w http.ResponseWriter, r *http.Request) {
  21. var req GetQueueMembersRequest
  22. err := json.NewDecoder(r.Body).Decode(&req)
  23. if err != nil {
  24. log.Error().Err(err).Msg("Could not decode body in GetQueueMembers call")
  25. return
  26. }
  27. var claims *auth.Claims
  28. claims, err = auth.GetUserClaims(r)
  29. if err != nil {
  30. log.Error().Err(err).Msg("Could not get user claims in request to GetQueueMembers")
  31. }
  32. if claims == nil {
  33. w.WriteHeader(401)
  34. return
  35. }
  36. if claims.Privileges > Admin {
  37. w.WriteHeader(403)
  38. return
  39. }
  40. var members []QueueMember
  41. Db.Table("queue_orders qo").Select("rf.id, asset, qo.order").
  42. Where("queue_id = ?", req.ID).
  43. Joins("inner join reward_funds rf on qo.reward_fund_id = rf.id").
  44. Order("qo.order").
  45. Scan(&members)
  46. var resp GetQueueMembersResponse
  47. resp.Members = members
  48. err = json.NewEncoder(w).Encode(resp)
  49. if err != nil {
  50. log.Error().Err(err).Msg("Could not deliver response in GetQueueMembers call")
  51. }
  52. }