|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package endpoints
-
- import (
- "encoding/json"
- "net/http"
-
- . "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 specificQueue Queue
- Db.Table("queues").First(&specificQueue, "name = ?", req.Name)
-
- var resp CreateQueueResponse
-
- if specificQueue.ID != 0 {
- resp.ID = specificQueue.ID
- } else {
- queue := Queue{
- Name: req.Name,
- }
-
- Db.Create(&queue)
-
- resp.ID = queue.ID
- }
-
- err = json.NewEncoder(w).Encode(resp)
- if err != nil {
- log.Error().Err(err).Msg("Could not deliver response in CreateQueue call")
- }
- }
|