|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package endpoints
-
- import (
- "encoding/json"
- "net/http"
-
- "github.com/imosed/signet/auth"
- . "github.com/imosed/signet/data"
- "github.com/rs/zerolog/log"
- )
-
- type QueueMember struct {
- ID uint `json:"id"`
- Asset string `json:"asset"`
- Order int `json:"order"`
- }
-
- type GetQueueMembersRequest struct {
- ID uint `json:"id"`
- }
-
- type GetQueueMembersResponse struct {
- Members []QueueMember `json:"members"`
- }
-
- func GetQueueMembers(w http.ResponseWriter, r *http.Request) {
- var req GetQueueMembersRequest
- err := json.NewDecoder(r.Body).Decode(&req)
- if err != nil {
- log.Error().Err(err).Msg("Could not decode body in GetQueueMembers 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 request to GetQueueMembers")
- }
-
- if claims == nil {
- w.WriteHeader(401)
- return
- }
- if claims.Privileges > Admin {
- w.WriteHeader(403)
- return
- }
-
- var members []QueueMember
- Db.Table("queue_orders qo").Select("rf.id, asset, qo.order").
- Where("queue_id = ?", req.ID).
- Joins("inner join reward_funds rf on qo.reward_fund_id = rf.id").
- Order("qo.order").
- Scan(&members)
-
- var resp GetQueueMembersResponse
- resp.Members = members
-
- err = json.NewEncoder(w).Encode(resp)
- if err != nil {
- log.Error().Err(err).Msg("Could not deliver response in GetQueueMembers call")
- }
- }
|