The backend for the project formerly known as signet, now known as beignet.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 regels
894 B

  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 CreateQueueRequest struct {
  9. Name string `json:"name"`
  10. }
  11. type CreateQueueResponse struct {
  12. ID uint `json:"id"`
  13. }
  14. func CreateQueue(w http.ResponseWriter, r *http.Request) {
  15. var req CreateQueueRequest
  16. err := json.NewDecoder(r.Body).Decode(&req)
  17. if err != nil {
  18. log.Error().Err(err).Msg("Could not decode body in CreateQueue call")
  19. return
  20. }
  21. var specificQueue Queue
  22. Db.Table("queues").First(&specificQueue, "name = ?", req.Name)
  23. var resp CreateQueueResponse
  24. if specificQueue.ID != 0 {
  25. resp.ID = specificQueue.ID
  26. } else {
  27. queue := Queue{
  28. Name: req.Name,
  29. }
  30. Db.Create(&queue)
  31. resp.ID = queue.ID
  32. }
  33. err = json.NewEncoder(w).Encode(resp)
  34. if err != nil {
  35. log.Error().Err(err).Msg("Could not deliver response in CreateQueue call")
  36. }
  37. }