feat: profit sharing

This commit is contained in:
Efril
2026-08-05 19:28:38 +07:00
parent 2b80c92caa
commit b9ac97178f
26 changed files with 1378 additions and 4 deletions
+7 -3
View File
@@ -7,6 +7,7 @@ import (
"github.com/google/uuid"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type CategoryRepositoryImpl struct {
@@ -25,7 +26,7 @@ func (r *CategoryRepositoryImpl) Create(ctx context.Context, category *entities.
func (r *CategoryRepositoryImpl) GetByID(ctx context.Context, id uuid.UUID) (*entities.Category, error) {
var category entities.Category
err := r.db.WithContext(ctx).First(&category, "id = ?", id).Error
err := r.db.WithContext(ctx).Preload("Parent").First(&category, "id = ?", id).Error
if err != nil {
return nil, err
}
@@ -54,7 +55,8 @@ func (r *CategoryRepositoryImpl) GetByBusinessType(ctx context.Context, business
}
func (r *CategoryRepositoryImpl) Update(ctx context.Context, category *entities.Category) error {
return r.db.WithContext(ctx).Save(category).Error
// Omit associations so a preloaded Parent is not upserted back over parent_id
return r.db.WithContext(ctx).Omit(clause.Associations).Save(category).Error
}
func (r *CategoryRepositoryImpl) Delete(ctx context.Context, id uuid.UUID) error {
@@ -84,7 +86,7 @@ func (r *CategoryRepositoryImpl) List(ctx context.Context, filters map[string]in
return nil, 0, err
}
err := query.Order("\"order\" ASC").Limit(limit).Offset(offset).Find(&categories).Error
err := query.Preload("Parent").Order("\"order\" ASC").Limit(limit).Offset(offset).Find(&categories).Error
return categories, total, err
}
@@ -97,6 +99,8 @@ func (r *CategoryRepositoryImpl) Count(ctx context.Context, filters map[string]i
case "search":
searchValue := "%" + value.(string) + "%"
query = query.Where("name ILIKE ? OR description ILIKE ?", searchValue, searchValue)
case "outlet_id":
query = query.Where("outlet_id = ? OR outlet_id IS NULL", value)
default:
query = query.Where(key+" = ?", value)
}