mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
fix(BE): improve product and warehouse existence check in adjustment service
This commit is contained in:
@@ -83,7 +83,7 @@ func (s *adjustmentService) Adjustment(c *fiber.Ctx, req *validation.Create) (*e
|
|||||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to validate product")
|
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to validate product")
|
||||||
}
|
}
|
||||||
if !isProductExist {
|
if !isProductExist {
|
||||||
return nil, fiber.NewError(fiber.StatusBadRequest, "Product not found")
|
return nil, fiber.NewError(fiber.StatusNotFound, "Product not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
isWarehouseExist, err := s.WarehouseRepo.IdExists(c.Context(), uint(req.WarehouseID))
|
isWarehouseExist, err := s.WarehouseRepo.IdExists(c.Context(), uint(req.WarehouseID))
|
||||||
@@ -92,7 +92,7 @@ func (s *adjustmentService) Adjustment(c *fiber.Ctx, req *validation.Create) (*e
|
|||||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to validate warehouse")
|
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to validate warehouse")
|
||||||
}
|
}
|
||||||
if !isWarehouseExist {
|
if !isWarehouseExist {
|
||||||
return nil, fiber.NewError(fiber.StatusBadRequest, "Warehouse not found")
|
return nil, fiber.NewError(fiber.StatusNotFound, "Warehouse not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Quantity <= 0 {
|
if req.Quantity <= 0 {
|
||||||
@@ -187,6 +187,24 @@ func (s *adjustmentService) AdjustmentHistory(c *fiber.Ctx, query *validation.Qu
|
|||||||
|
|
||||||
offset := (query.Page - 1) * query.Limit
|
offset := (query.Page - 1) * query.Limit
|
||||||
|
|
||||||
|
isWarehousesExist, err := s.WarehouseRepo.IdExists(c.Context(), uint(query.WarehouseID))
|
||||||
|
if err != nil {
|
||||||
|
s.Log.Errorf("Failed to check warehouse existence: %+v", err)
|
||||||
|
return nil, 0, fiber.NewError(fiber.StatusInternalServerError, "Failed to validate warehouse")
|
||||||
|
}
|
||||||
|
if query.WarehouseID > 0 && !isWarehousesExist {
|
||||||
|
return nil, 0, fiber.NewError(fiber.StatusNotFound, "Warehouse not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
isProductsExist, err := s.ProductRepo.IdExists(c.Context(), uint(query.ProductID))
|
||||||
|
if err != nil {
|
||||||
|
s.Log.Errorf("Failed to check product existence: %+v", err)
|
||||||
|
return nil, 0, fiber.NewError(fiber.StatusInternalServerError, "Failed to validate product")
|
||||||
|
}
|
||||||
|
if query.ProductID > 0 && !isProductsExist {
|
||||||
|
return nil, 0, fiber.NewError(fiber.StatusNotFound, "Product not found")
|
||||||
|
}
|
||||||
|
|
||||||
stockLogs, total, err := s.StockLogsRepository.GetAll(c.Context(), offset, query.Limit, func(db *gorm.DB) *gorm.DB {
|
stockLogs, total, err := s.StockLogsRepository.GetAll(c.Context(), offset, query.Limit, func(db *gorm.DB) *gorm.DB {
|
||||||
|
|
||||||
db = s.withRelations(db)
|
db = s.withRelations(db)
|
||||||
|
|||||||
@@ -72,6 +72,11 @@ func (s productWarehouseService) GetAll(c *fiber.Ctx, params *validation.Query)
|
|||||||
s.Log.Errorf("Failed to get productWarehouses: %+v", err)
|
s.Log.Errorf("Failed to get productWarehouses: %+v", err)
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(productWarehouses) == 0 {
|
||||||
|
return nil, 0, fiber.NewError(fiber.StatusNotFound, "ProductWarehouses not found")
|
||||||
|
}
|
||||||
|
|
||||||
return productWarehouses, total, nil
|
return productWarehouses, total, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user