add product ingredients
This commit is contained in:
@@ -254,3 +254,25 @@ func (h *IngredientUnitConverterHandler) ConvertUnit(c *gin.Context) {
|
||||
util.HandleResponse(c.Writer, c.Request, converterResponse, "IngredientUnitConverterHandler::ConvertUnit")
|
||||
}
|
||||
|
||||
func (h *IngredientUnitConverterHandler) GetUnitsByIngredientID(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
contextInfo := appcontext.FromGinContext(ctx)
|
||||
|
||||
ingredientIDStr := c.Param("ingredient_id")
|
||||
ingredientID, err := uuid.Parse(ingredientIDStr)
|
||||
if err != nil {
|
||||
logger.FromContext(ctx).WithError(err).Error("IngredientUnitConverterHandler::GetUnitsByIngredientID -> Invalid ingredient ID")
|
||||
validationResponseError := contract.NewResponseError(constants.MalformedFieldErrorCode, constants.RequestEntity, "Invalid ingredient ID")
|
||||
util.HandleResponse(c.Writer, c.Request, contract.BuildErrorResponse([]*contract.ResponseError{validationResponseError}), "IngredientUnitConverterHandler::GetUnitsByIngredientID")
|
||||
return
|
||||
}
|
||||
|
||||
unitsResponse := h.converterService.GetUnitsByIngredientID(ctx, contextInfo, ingredientID)
|
||||
if unitsResponse.HasErrors() {
|
||||
errorResp := unitsResponse.GetErrors()[0]
|
||||
logger.FromContext(ctx).WithError(errorResp).Error("IngredientUnitConverterHandler::GetUnitsByIngredientID -> Failed to get units for ingredient from service")
|
||||
}
|
||||
|
||||
util.HandleResponse(c.Writer, c.Request, unitsResponse, "IngredientUnitConverterHandler::GetUnitsByIngredientID")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user