fix
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"apskel-pos-be/internal/constants"
|
||||
"apskel-pos-be/internal/contract"
|
||||
"apskel-pos-be/internal/logger"
|
||||
"apskel-pos-be/internal/models"
|
||||
"apskel-pos-be/internal/service"
|
||||
"apskel-pos-be/internal/util"
|
||||
"net/http"
|
||||
@@ -28,7 +27,7 @@ func (h *ProductRecipeHandler) Create(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
contextInfo := appcontext.FromGinContext(ctx)
|
||||
|
||||
var request models.CreateProductRecipeRequest
|
||||
var request contract.CreateProductRecipeRequest
|
||||
if err := c.ShouldBindJSON(&request); err != nil {
|
||||
logger.FromContext(ctx).WithError(err).Error("ProductRecipeHandler::Create -> request binding failed")
|
||||
validationResponseError := contract.NewResponseError(constants.MissingFieldErrorCode, constants.RequestEntity, err.Error())
|
||||
@@ -75,6 +74,7 @@ func (h *ProductRecipeHandler) GetByProductID(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
contextInfo := appcontext.FromGinContext(ctx)
|
||||
|
||||
// Parse product ID from URL parameter
|
||||
productIDStr := c.Param("product_id")
|
||||
productID, err := uuid.Parse(productIDStr)
|
||||
if err != nil {
|
||||
@@ -84,10 +84,9 @@ func (h *ProductRecipeHandler) GetByProductID(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Check if variant_id is provided
|
||||
variantIDStr := c.Query("variant_id")
|
||||
// Parse optional variant ID from query parameter
|
||||
var variantID *uuid.UUID
|
||||
if variantIDStr != "" {
|
||||
if variantIDStr := c.Query("variant_id"); variantIDStr != "" {
|
||||
parsed, err := uuid.Parse(variantIDStr)
|
||||
if err != nil {
|
||||
logger.FromContext(ctx).WithError(err).Error("ProductRecipeHandler::GetByProductID -> Invalid variant ID")
|
||||
@@ -98,15 +97,14 @@ func (h *ProductRecipeHandler) GetByProductID(c *gin.Context) {
|
||||
variantID = &parsed
|
||||
}
|
||||
|
||||
var recipes []*models.ProductRecipeResponse
|
||||
if variantIDStr != "" {
|
||||
// Get by product and variant ID
|
||||
recipes, err = h.productRecipeService.GetByProductAndVariantID(ctx, productID, variantID, contextInfo.OrganizationID)
|
||||
} else {
|
||||
// Get by product ID only
|
||||
recipes, err = h.productRecipeService.GetByProductID(ctx, productID, contextInfo.OrganizationID)
|
||||
// Create request object
|
||||
request := &contract.GetProductRecipeByProductIDRequest{
|
||||
ProductID: productID,
|
||||
VariantID: variantID,
|
||||
}
|
||||
|
||||
// Call service
|
||||
recipes, err := h.productRecipeService.GetByProductID(ctx, request, contextInfo.OrganizationID)
|
||||
if err != nil {
|
||||
logger.FromContext(ctx).WithError(err).Error("ProductRecipeHandler::GetByProductID -> Failed to get product recipes")
|
||||
validationResponseError := contract.NewResponseError(constants.InternalServerErrorCode, constants.RequestEntity, err.Error())
|
||||
@@ -154,7 +152,7 @@ func (h *ProductRecipeHandler) Update(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var request models.UpdateProductRecipeRequest
|
||||
var request contract.UpdateProductRecipeRequest
|
||||
if err := c.ShouldBindJSON(&request); err != nil {
|
||||
logger.FromContext(ctx).WithError(err).Error("ProductRecipeHandler::Update -> request binding failed")
|
||||
validationResponseError := contract.NewResponseError(constants.MissingFieldErrorCode, constants.RequestEntity, err.Error())
|
||||
@@ -204,10 +202,7 @@ func (h *ProductRecipeHandler) BulkCreate(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
contextInfo := appcontext.FromGinContext(ctx)
|
||||
|
||||
var request struct {
|
||||
Recipes []models.CreateProductRecipeRequest `json:"recipes" validate:"required,min=1"`
|
||||
}
|
||||
|
||||
var request contract.BulkCreateProductRecipeRequest
|
||||
if err := c.ShouldBindJSON(&request); err != nil {
|
||||
logger.FromContext(ctx).WithError(err).Error("ProductRecipeHandler::BulkCreate -> request binding failed")
|
||||
validationResponseError := contract.NewResponseError(constants.MissingFieldErrorCode, constants.RequestEntity, err.Error())
|
||||
@@ -215,7 +210,7 @@ func (h *ProductRecipeHandler) BulkCreate(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
recipes, err := h.productRecipeService.BulkCreate(ctx, contextInfo.OrganizationID, request.Recipes)
|
||||
recipes, err := h.productRecipeService.BulkCreate(ctx, contextInfo.OrganizationID, &request)
|
||||
if err != nil {
|
||||
logger.FromContext(ctx).WithError(err).Error("ProductRecipeHandler::BulkCreate -> Failed to bulk create product recipes")
|
||||
validationResponseError := contract.NewResponseError(constants.InternalServerErrorCode, constants.RequestEntity, err.Error())
|
||||
|
||||
Reference in New Issue
Block a user