The backend for the project formerly known as signet, now known as beignet.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

49 行
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. }