func OpenTab(c *gin.Context) { json := struct { WaitStaff string `json:"waitstaff" binding:"required"` }{} if err := c.BindJSON(&json); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } openTabCmd := cafe.NewOpenTab(1, json.WaitStaff) cafe.Send(cafe.OpenTabTopic, openTabCmd) c.JSON(http.StatusAccepted, gin.H{"tabID": openTabCmd.ID.String()}) }
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, "") }
drinks = []cafe.OrderedItem{} drinks = append(drinks, cafe.NewOrderedItem(1, "Patron", true, 5.00)) drinks = append(drinks, cafe.NewOrderedItem(2, "Scotch", true, 3.50)) food = []cafe.OrderedItem{} food = append(food, cafe.NewOrderedItem(1, "Steak", false, 15.00)) food = append(food, cafe.NewOrderedItem(2, "Burger", false, 8.00)) }) AfterEach(func() { stopAllTestConsumers() }) Describe("todoList Group", func() { BeforeEach(func() { cafe.Send(cafe.OpenTabTopic, openTabCmd) cafe.Send(cafe.PlaceOrderTopic, cafe.NewPlaceOrder(tabID, append(food, drinks...))) f := func() int { return len(ChefTodoList) } Eventually(f).ShouldNot(BeZero()) }) It("creates a new group", func() { Expect(getTodoListGroup(tabID).Items).To(HaveLen(2)) }) Describe("with created group", func() { It("Removes an item", func() { cafe.Send(cafe.MarkFoodPreparedTopic, cafe.NewMarkFoodPrepared(tabID, food[0:1])) f := func() int { group := getTodoListGroup(tabID) if group == nil {