mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
fix: add include_all param in get all master product
This commit is contained in:
@@ -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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user