The backend for the project formerly known as signet, now known as beignet.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

  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. Title string `json:"title"`
  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 members []QueueMember
  28. Db.Table("queue_orders qo").Select("rf.id, asset, title, qo.order").
  29. Where("queue_id = ?", req.ID).
  30. Joins("inner join reward_funds rf on qo.reward_fund_id = rf.id").
  31. Order("qo.order").
  32. Scan(&members)
  33. var resp GetQueueMembersResponse
  34. resp.Members = members
  35. err = json.NewEncoder(w).Encode(resp)
  36. if err != nil {
  37. log.Error().Err(err).Msg("Could not deliver response in GetQueueMembers call")
  38. }
  39. }