The backend for the project formerly known as signet, now known as beignet.
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

47 righe
778 B

  1. package endpoints
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. . "github.com/imosed/signet/data"
  6. )
  7. type CreateQueueRequest struct {
  8. Name string `json:"name"`
  9. }
  10. type CreateQueueResponse struct {
  11. ID uint `json:"id"`
  12. }
  13. func CreateQueue(w http.ResponseWriter, r *http.Request) {
  14. var req CreateQueueRequest
  15. err := json.NewDecoder(r.Body).Decode(&req)
  16. if err != nil {
  17. panic("Could not decode body")
  18. }
  19. var specificQueue Queue
  20. Db.Table("queues").First(&specificQueue, "name = ?", req.Name)
  21. var resp CreateQueueResponse
  22. if specificQueue.ID != 0 {
  23. resp.ID = specificQueue.ID
  24. } else {
  25. queue := Queue{
  26. Name: req.Name,
  27. }
  28. Db.Create(&queue)
  29. resp.ID = queue.ID
  30. }
  31. err = json.NewEncoder(w).Encode(resp)
  32. if err != nil {
  33. panic("Could not deliver response")
  34. }
  35. }