diff --git a/internal/modules/master/products/controllers/product.controller.go b/internal/modules/master/products/controllers/product.controller.go index 050dc2d9..82710618 100644 --- a/internal/modules/master/products/controllers/product.controller.go +++ b/internal/modules/master/products/controllers/product.controller.go @@ -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") } diff --git a/internal/modules/master/products/services/product.service.go b/internal/modules/master/products/services/product.service.go index 454b0a93..994318ae 100644 --- a/internal/modules/master/products/services/product.service.go +++ b/internal/modules/master/products/services/product.service.go @@ -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 != "" { diff --git a/internal/modules/master/products/validations/product.validation.go b/internal/modules/master/products/validations/product.validation.go index 4b01e066..c9068e6e 100644 --- a/internal/modules/master/products/validations/product.validation.go +++ b/internal/modules/master/products/validations/product.validation.go @@ -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"` }