self-order+notification #5
@ -52,3 +52,18 @@ type SelfOrderCreateOrderItem struct {
|
|||||||
Quantity int `json:"quantity" validate:"required,min=1"`
|
Quantity int `json:"quantity" validate:"required,min=1"`
|
||||||
Notes *string `json:"notes,omitempty"`
|
Notes *string `json:"notes,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SelfOrderListCategoriesRequest struct {
|
||||||
|
TableID uuid.UUID `form:"table_id" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SelfOrderCategoryItem struct {
|
||||||
|
ID uuid.UUID `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description *string `json:"description,omitempty"`
|
||||||
|
Order int `json:"order"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SelfOrderListCategoriesResponse struct {
|
||||||
|
Categories []SelfOrderCategoryItem `json:"categories"`
|
||||||
|
}
|
||||||
|
|||||||
@ -296,6 +296,68 @@ func (h *SelfOrderHandler) validateCreateOrderRequest(req *contract.SelfOrderCre
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *SelfOrderHandler) ListCategories(c *gin.Context) {
|
||||||
|
ctx := c.Request.Context()
|
||||||
|
|
||||||
|
var req contract.SelfOrderListCategoriesRequest
|
||||||
|
if err := c.ShouldBindQuery(&req); err != nil {
|
||||||
|
logger.FromContext(ctx).WithError(err).Error("SelfOrderHandler::ListCategories -> query binding failed")
|
||||||
|
util.HandleResponse(c.Writer, c.Request, contract.BuildErrorResponse([]*contract.ResponseError{
|
||||||
|
contract.NewResponseError(constants.MissingFieldErrorCode, constants.RequestEntity, err.Error()),
|
||||||
|
}), "SelfOrderHandler::ListCategories")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.TableID == uuid.Nil {
|
||||||
|
util.HandleResponse(c.Writer, c.Request, contract.BuildErrorResponse([]*contract.ResponseError{
|
||||||
|
contract.NewResponseError(constants.MissingFieldErrorCode, constants.RequestEntity, "table_id is required"),
|
||||||
|
}), "SelfOrderHandler::ListCategories")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
table, err := h.tableRepo.GetByID(ctx, req.TableID)
|
||||||
|
if err != nil {
|
||||||
|
logger.FromContext(ctx).WithError(err).Error("SelfOrderHandler::ListCategories -> table not found")
|
||||||
|
util.HandleResponse(c.Writer, c.Request, contract.BuildErrorResponse([]*contract.ResponseError{
|
||||||
|
contract.NewResponseError(constants.NotFoundErrorCode, constants.TableEntity, "table not found"),
|
||||||
|
}), "SelfOrderHandler::ListCategories")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
catResp := h.categoryService.ListCategories(ctx, &contract.ListCategoriesRequest{
|
||||||
|
OrganizationID: &table.OrganizationID,
|
||||||
|
Page: 1,
|
||||||
|
Limit: 100,
|
||||||
|
})
|
||||||
|
if catResp.HasErrors() {
|
||||||
|
logger.FromContext(ctx).WithError(catResp.GetErrors()[0]).Error("SelfOrderHandler::ListCategories -> failed to list categories")
|
||||||
|
util.HandleResponse(c.Writer, c.Request, catResp, "SelfOrderHandler::ListCategories")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
catList, ok := catResp.Data.(*contract.ListCategoriesResponse)
|
||||||
|
if !ok {
|
||||||
|
util.HandleResponse(c.Writer, c.Request, contract.BuildErrorResponse([]*contract.ResponseError{
|
||||||
|
contract.NewResponseError(constants.InternalServerErrorCode, constants.CategoryServiceEntity, "unexpected categories response type"),
|
||||||
|
}), "SelfOrderHandler::ListCategories")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
items := make([]contract.SelfOrderCategoryItem, 0, len(catList.Categories))
|
||||||
|
for _, cat := range catList.Categories {
|
||||||
|
items = append(items, contract.SelfOrderCategoryItem{
|
||||||
|
ID: cat.ID,
|
||||||
|
Name: cat.Name,
|
||||||
|
Description: cat.Description,
|
||||||
|
Order: cat.Order,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
util.HandleResponse(c.Writer, c.Request, contract.BuildSuccessResponse(&contract.SelfOrderListCategoriesResponse{
|
||||||
|
Categories: items,
|
||||||
|
}), "SelfOrderHandler::ListCategories")
|
||||||
|
}
|
||||||
|
|
||||||
func (h *SelfOrderHandler) resolveOrgUser(ctx context.Context, organizationID uuid.UUID) (uuid.UUID, error) {
|
func (h *SelfOrderHandler) resolveOrgUser(ctx context.Context, organizationID uuid.UUID) (uuid.UUID, error) {
|
||||||
users, err := h.userRepo.GetByOrganizationID(ctx, organizationID)
|
users, err := h.userRepo.GetByOrganizationID(ctx, organizationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -149,6 +149,7 @@ func (r *Router) addAppRoutes(rg *gin.Engine) {
|
|||||||
|
|
||||||
selfOrder := v1.Group("/self-order")
|
selfOrder := v1.Group("/self-order")
|
||||||
{
|
{
|
||||||
|
selfOrder.GET("/categories", r.selfOrderHandler.ListCategories)
|
||||||
selfOrder.POST("/menu", r.selfOrderHandler.GetMenu)
|
selfOrder.POST("/menu", r.selfOrderHandler.GetMenu)
|
||||||
selfOrder.POST("/order", r.selfOrderHandler.CreateOrder)
|
selfOrder.POST("/order", r.selfOrderHandler.CreateOrder)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user