Compare commits

..
2 Commits
Author SHA1 Message Date
aefril 1d412959d7 Merge pull request 'feat: profit sharing' (#24) from staging into main
Reviewed-on: #24
2026-08-05 12:39:49 +00:00
aefril 7b46da7007 Merge pull request 'staging' (#23) from staging into main
Reviewed-on: #23
2026-07-09 15:43:23 +00:00
6 changed files with 2 additions and 40 deletions
-1
View File
@@ -30,7 +30,6 @@ type ListCategoriesRequest struct {
OrganizationID *uuid.UUID `json:"organization_id,omitempty"`
OutletID *uuid.UUID `json:"outlet_id,omitempty"`
ParentID *uuid.UUID `json:"parent_id,omitempty"`
Type string `json:"type,omitempty" validate:"omitempty,oneof=parent child"`
BusinessType string `json:"business_type,omitempty"`
Search string `json:"search,omitempty"`
Page int `json:"page" validate:"required,min=1"`
-7
View File
@@ -196,13 +196,6 @@ func (h *CategoryHandler) ListCategories(c *gin.Context) {
req.ParentID = &parentID
}
}
// type=parent -> top level categories only
// type=child -> leaf categories (sub categories + top level ones without children)
if categoryType := c.Query("type"); categoryType != "" {
req.Type = categoryType
}
validationError, validationErrorCode := h.categoryValidator.ValidateListCategoriesRequest(req)
if validationError != nil {
logger.FromContext(ctx).WithError(validationError).Error("CategoryHandler::ListCategories -> request validation failed")
@@ -63,21 +63,6 @@ func (r *CategoryRepositoryImpl) Delete(ctx context.Context, id uuid.UUID) error
return r.db.WithContext(ctx).Delete(&entities.Category{}, "id = ?", id).Error
}
// applyCategoryTypeFilter narrows the query by position in the category tree.
// - "parent": top level categories only (no parent of their own)
// - "child": leaf categories — sub categories plus top level categories that
// have no sub categories, i.e. everything a product can be assigned to
func applyCategoryTypeFilter(query *gorm.DB, value interface{}) *gorm.DB {
switch value {
case "parent":
return query.Where("parent_id IS NULL")
case "child":
return query.Where("NOT EXISTS (SELECT 1 FROM categories AS sub WHERE sub.parent_id = categories.id)")
default:
return query
}
}
func (r *CategoryRepositoryImpl) List(ctx context.Context, filters map[string]interface{}, limit, offset int) ([]*entities.Category, int64, error) {
var categories []*entities.Category
var total int64
@@ -92,8 +77,6 @@ func (r *CategoryRepositoryImpl) List(ctx context.Context, filters map[string]in
case "outlet_id":
// Include outlet-specific categories AND global categories (outlet_id IS NULL)
query = query.Where("outlet_id = ? OR outlet_id IS NULL", value)
case "type":
query = applyCategoryTypeFilter(query, value)
default:
query = query.Where(key+" = ?", value)
}
@@ -118,8 +101,6 @@ func (r *CategoryRepositoryImpl) Count(ctx context.Context, filters map[string]i
query = query.Where("name ILIKE ? OR description ILIKE ?", searchValue, searchValue)
case "outlet_id":
query = query.Where("outlet_id = ? OR outlet_id IS NULL", value)
case "type":
query = applyCategoryTypeFilter(query, value)
default:
query = query.Where(key+" = ?", value)
}
+2 -6
View File
@@ -112,9 +112,7 @@ func (r *ProductRepositoryImpl) List(ctx context.Context, filters map[string]int
return nil, 0, err
}
// id is a tie-breaker so LIMIT/OFFSET paging stays stable when several products
// share the same created_at.
err := query.Order("created_at DESC, id DESC").Limit(limit).Offset(offset).Find(&products).Error
err := query.Limit(limit).Offset(offset).Find(&products).Error
return products, total, err
}
@@ -267,8 +265,6 @@ func (r *ProductRepositoryImpl) ListWithOutletPrice(ctx context.Context, filters
return nil, 0, err
}
// Columns are qualified because the outlet join brings a second created_at/id
// into scope. id is a tie-breaker for stable LIMIT/OFFSET paging.
err := query.Order("products.created_at DESC, products.id DESC").Limit(limit).Offset(offset).Find(&products).Error
err := query.Limit(limit).Offset(offset).Find(&products).Error
return products, total, err
}
-3
View File
@@ -94,9 +94,6 @@ func (s *CategoryServiceImpl) ListCategories(ctx context.Context, req *contract.
if req.ParentID != nil {
filters["parent_id"] = *req.ParentID
}
if req.Type != "" {
filters["type"] = req.Type
}
if req.Search != "" {
filters["search"] = req.Search
}
-4
View File
@@ -118,9 +118,5 @@ func (v *CategoryValidatorImpl) ValidateListCategoriesRequest(req *contract.List
}
}
if req.Type != "" && req.Type != "parent" && req.Type != "child" {
return errors.New("type must be either 'parent' or 'child'"), constants.MalformedFieldErrorCode
}
return nil, ""
}