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.0 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package endpoints
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. . "github.com/imosed/signet/data"
  6. "github.com/rs/zerolog/log"
  7. )
  8. type QueueMember struct {
  9. ID uint `json:"id"`
  10. Asset string `json:"asset"`
  11. Order int `json:"order"`
  12. }
  13. type GetQueueMembersRequest struct {
  14. ID uint `json:"id"`
  15. }
  16. type GetQueueMembersResponse struct {
  17. Members []QueueMember `json:"members"`
  18. }
  19. func GetQueueMembers(w http.ResponseWriter, r *http.Request) {
  20. var req GetQueueMembersRequest
  21. err := json.NewDecoder(r.Body).Decode(&req)
  22. if err != nil {
  23. log.Error().Err(err).Msg("Could not decode body in GetQueueMembers call")
  24. return
  25. }
  26. var members []QueueMember
  27. Db.Table("queue_orders qo").Select("rf.id, asset, qo.order").
  28. Where("queue_id = ?", req.ID).
  29. Joins("inner join reward_funds rf on qo.reward_fund_id = rf.id").
  30. Order("qo.order").
  31. Scan(&members)
  32. var resp GetQueueMembersResponse
  33. resp.Members = members
  34. err = json.NewEncoder(w).Encode(resp)
  35. if err != nil {
  36. log.Error().Err(err).Msg("Could not deliver response in GetQueueMembers call")
  37. }
  38. }