package endpoints import ( "encoding/json" "net/http" "github.com/imosed/signet/auth" . "github.com/imosed/signet/data" "github.com/rs/zerolog/log" ) type CreateQueueRequest struct { Name string `json:"name"` } type CreateQueueResponse struct { ID uint `json:"id"` } func CreateQueue(w http.ResponseWriter, r *http.Request) { var req CreateQueueRequest err := json.NewDecoder(r.Body).Decode(&req) if err != nil { log.Error().Err(err).Msg("Could not decode body in CreateQueue call") return } var claims *auth.Claims claims, err = auth.GetUserClaims(r) if err != nil { log.Error().Err(err).Msg("Could not determine if user is authenticated") return } var resp CreateQueueResponse if claims != nil && claims.Privileges <= Admin { var specificQueue Queue Db.Table("queues").First(&specificQueue, "name = ?", req.Name) if specificQueue.ID != 0 { resp.ID = specificQueue.ID } else { queue := Queue{ Name: req.Name, } Db.Create(&queue) resp.ID = queue.ID } } else { w.WriteHeader(403) return } err = json.NewEncoder(w).Encode(resp) if err != nil { log.Error().Err(err).Msg("Could not deliver response in CreateQueue call") } }