Update with Tx

This commit is contained in:
aditya.siregar
2025-06-28 16:34:19 +07:00
parent 20d1ef5f2a
commit 46b30277ef
3 changed files with 33 additions and 1 deletions
@@ -25,6 +25,7 @@ type InProgressOrderService interface {
type OrderRepository interface {
FindByID(ctx mycontext.Context, id int64) (*entity.Order, error)
FindByIDWithTx(ctx mycontext.Context, id int64, tx *gorm.DB) (*entity.Order, error)
CreateOrder(ctx mycontext.Context, order *entity.Order, tx *gorm.DB) (*entity.Order, error)
CreateOrderItems(ctx mycontext.Context, orderID int64, items []entity.OrderItem, tx *gorm.DB) error
GetListByPartnerID(ctx mycontext.Context, partnerID int64, limit, offset int, status string) ([]*entity.Order, error)
@@ -147,7 +148,7 @@ func (s *inProgressOrderSvc) AddItems(ctx mycontext.Context, orderID int64, newI
return nil, errors.Wrap(err, "failed to add order items")
}
updatedOrder, err := s.repo.FindByID(ctx, existingOrder.ID)
updatedOrder, err := s.repo.FindByIDWithTx(ctx, existingOrder.ID, tx)
if err != nil {
s.trx.Rollback(tx)
return nil, errors.Wrap(err, "failed to fetch updated order")