|
|
|
@@ -296,6 +296,68 @@ func (h *SelfOrderHandler) validateCreateOrderRequest(req *contract.SelfOrderCre
|
|
|
|
|
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) {
|
|
|
|
|
users, err := h.userRepo.GetByOrganizationID(ctx, organizationID)
|
|
|
|
|
if err != nil {
|
|
|
|
|