feat(repository): Refactor Update methods to use Model and Where for better clarity and performance
This commit is contained in:
parent
a526b94e19
commit
1f23b12918
|
|
@ -63,7 +63,10 @@ func (r *categoryRepository) Update(ctx context.Context, tx *gorm.DB, category e
|
||||||
if tx == nil {
|
if tx == nil {
|
||||||
tx = r.db
|
tx = r.db
|
||||||
}
|
}
|
||||||
if err := tx.WithContext(ctx).Save(&category).Error; err != nil {
|
if err := tx.WithContext(ctx).
|
||||||
|
Model(&entities.MCategoryEntity{}).
|
||||||
|
Where("id = ?", category.ID).
|
||||||
|
Updates(category).Error; err != nil {
|
||||||
return category, err
|
return category, err
|
||||||
}
|
}
|
||||||
return category, nil
|
return category, nil
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,10 @@ func (r *productRepository) Update(ctx context.Context, tx *gorm.DB, product ent
|
||||||
if tx == nil {
|
if tx == nil {
|
||||||
tx = r.db
|
tx = r.db
|
||||||
}
|
}
|
||||||
if err := tx.WithContext(ctx).Save(&product).Error; err != nil {
|
if err := tx.WithContext(ctx).
|
||||||
|
Model(&entities.MProductEntity{}).
|
||||||
|
Where("id = ?", product.ID).
|
||||||
|
Updates(product).Error; err != nil {
|
||||||
return product, err
|
return product, err
|
||||||
}
|
}
|
||||||
return product, nil
|
return product, nil
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,10 @@ func (r *uomRepository) Update(ctx context.Context, tx *gorm.DB, uom entities.MU
|
||||||
if tx == nil {
|
if tx == nil {
|
||||||
tx = r.db
|
tx = r.db
|
||||||
}
|
}
|
||||||
if err := tx.WithContext(ctx).Save(&uom).Error; err != nil {
|
if err := tx.WithContext(ctx).
|
||||||
|
Model(&entities.MUomEntity{}).
|
||||||
|
Where("id = ?", uom.ID).
|
||||||
|
Updates(uom).Error; err != nil {
|
||||||
return uom, err
|
return uom, err
|
||||||
}
|
}
|
||||||
return uom, nil
|
return uom, nil
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue