The backend for the project formerly known as signet, now known as beignet.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

46 rindas
777 B

  1. package endpoints
  2. import (
  3. "encoding/json"
  4. . "github.com/imosed/signet/data"
  5. "net/http"
  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. }