Esempio n. 1
0
func PlaceOrder(c *gin.Context) {
	json := struct {
		TabID       string `json:"tabID" binding:"required"`
		MenuNumbers []int  `json:"items" binding:"required"`
	}{}

	if err := c.BindJSON(&json); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}

	order := []cafe.OrderedItem{}

	for _, menuNumber := range json.MenuNumbers {
		order = append(order, food[menuNumber])
	}

	cafe.Send(cafe.PlaceOrderTopic, cafe.NewPlaceOrder(uuid.Parse(json.TabID), order))
	c.String(http.StatusAccepted, "")
}
Esempio n. 2
0
		response := struct {
			TabID string `json:"tabID" binding:"required"`
		}{}
		json.Unmarshal(w.Body.Bytes(), &response)
		tabID = response.TabID

		json := fmt.Sprintf(`{"tabID":"%s","items":[0,1]}`, tabID)
		w = performRequest(router, "POST", "/placeorder", json)
		Expect(w.Code).To(Equal(http.StatusAccepted))

	})

	It("returns the chef todo list ", func() {
		time.Sleep(time.Millisecond * 2)

		w := performRequest(router, "GET", "/cheftodolist", "")

		res := ChefTodoListResponse{}
		json.Unmarshal(w.Body.Bytes(), &res)

		Expect(w.Code).To(Equal(http.StatusOK))
		Expect(uuid.Parse(res.Tabs[0].TabID)).ToNot(BeNil())
		Expect(res.Tabs[0].Items[0].MenuNumber).To(Equal(0))
		Expect(res.Tabs[0].Items[0].Description).To(Equal("Steak"))
		Expect(res.Tabs[0].Items[1].MenuNumber).To(Equal(1))
		Expect(res.Tabs[0].Items[1].Description).To(Equal("Burger"))

	})
})