Merge branch 'fix/param-master-product' into 'development'

fix: add include_all param in get all master product

See merge request mbugroup/lti-api!363
This commit is contained in:
Adnan Zahir
2026-03-09 00:51:39 +07:00
3 changed files with 12 additions and 3 deletions
@@ -38,6 +38,14 @@ func (u *ProductController) GetAll(c *fiber.Ctx) error {
query.IsDepletion = &value
}
if includeAllParam := c.Query("include_all", ""); includeAllParam != "" {
value, err := strconv.ParseBool(includeAllParam)
if err != nil {
return fiber.NewError(fiber.StatusBadRequest, "invalid include_all value")
}
query.IncludeAll = &value
}
if query.Page < 1 || query.Limit < 1 {
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
}
@@ -229,9 +229,9 @@ func (s productService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity
products, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB {
db = s.withRelations(db)
// Depletion master products are system products and often stored with is_visible = false.
// When requested explicitly via is_depletion=true, include hidden records.
if params.IsDepletion == nil || !*params.IsDepletion {
// Default: show only visible products.
// include_all=true can be used to fetch all records (including hidden/system products).
if params.IncludeAll == nil || !*params.IncludeAll {
db = db.Where("is_visible = ?", true)
}
if params.Search != "" {
@@ -45,4 +45,5 @@ type Query struct {
Search string `query:"search" validate:"omitempty,max=50"`
ProductCategoryID int `query:"product_category_id" validate:"omitempty,number,min=1"`
IsDepletion *bool `query:"is_depletion" validate:"omitempty"`
IncludeAll *bool `query:"include_all" validate:"omitempty"`
}