Feat[BE] : add avaibility DOC on lookup porject flock API, add note request json on chickin

This commit is contained in:
aguhh18
2025-10-24 09:51:50 +07:00
parent 79b3dd47b8
commit aeeb5a38c1
8 changed files with 137 additions and 96 deletions
@@ -30,6 +30,10 @@ func (u *ProductWarehouseController) GetAll(c *fiber.Ctx) error {
WarehouseId: uint(c.QueryInt("warehouse_id", 0)),
}
if query.Page < 1 || query.Limit < 1 {
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
}
result, totalResults, err := u.ProductWarehouseService.GetAll(c, query)
if err != nil {
return err
@@ -71,5 +75,3 @@ func (u *ProductWarehouseController) GetOne(c *fiber.Ctx) error {
Data: dto.ToProductWarehouseListDTO(*result),
})
}
@@ -49,6 +49,26 @@ func (s productWarehouseService) GetAll(c *fiber.Ctx, params *validation.Query)
return nil, 0, err
}
if params.ProductId > 0 {
isProductExist, err := s.Repository.IsProductExist(c.Context(), params.ProductId)
if err != nil {
return nil, 0, err
}
if !isProductExist {
return nil, 0, fiber.NewError(fiber.StatusNotFound, "Product not found")
}
}
if params.WarehouseId > 0 {
isWarehouseExist, err := s.Repository.IsWarehouseExist(c.Context(), params.WarehouseId)
if err != nil {
return nil, 0, err
}
if !isWarehouseExist {
return nil, 0, fiber.NewError(fiber.StatusNotFound, "Warehouse not found")
}
}
offset := (params.Page - 1) * params.Limit
productWarehouses, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB {