func ChefTodoList(c *gin.Context) { r := ChefTodoListResponse{} for _, todoList := range cheftodos.ChefTodoList { t := Tab{TabID: todoList.TabID.String()} for _, item := range todoList.Items { t.Items = append(t.Items, Item{MenuNumber: item.MenuNumber, Description: item.Description}) } r.Tabs = append(r.Tabs, t) } c.JSON(http.StatusOK, r) }
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, "") }