diff --git a/internal/data/repoimpl/order.go b/internal/data/repoimpl/order.go index ee81006..ef949d6 100644 --- a/internal/data/repoimpl/order.go +++ b/internal/data/repoimpl/order.go @@ -2,6 +2,7 @@ package repoimpl import ( "context" + "fmt" "gorm.io/gorm" "time" "unicode/utf8" @@ -86,7 +87,7 @@ func (p *OrderRepoImpl) GetByOutBizNo(ctx context.Context, t vo.OrderType, outBi tx := p.DB(ctx).Where(model.Order{Type: t.GetValue(), OutBizNo: outBizNo}).Find(&info) if tx.Error != nil { - return nil, tx.Error + return nil, fmt.Errorf("db fail %w", tx.Error) } if tx.RowsAffected == 0 { @@ -102,7 +103,7 @@ func (p *OrderRepoImpl) GetByID(ctx context.Context, id uint64) (*bo.OrderBo, er tx := p.DB(ctx).Where(model.Order{ID: id}).Find(&info) if tx.Error != nil { - return nil, tx.Error + return nil, fmt.Errorf("db fail %w", tx.Error) } if tx.RowsAffected == 0 { @@ -118,7 +119,7 @@ func (p *OrderRepoImpl) GetByOrderNo(ctx context.Context, orderNo string) (*bo.O tx := p.DB(ctx).Where(model.Order{OrderNo: orderNo}).Find(&info) if tx.Error != nil { - return nil, tx.Error + return nil, fmt.Errorf("db fail %w", tx.Error) } if tx.RowsAffected == 0 { @@ -134,7 +135,7 @@ func (p *OrderRepoImpl) GetByMBV(ctx context.Context, merchantNo, batchNo, vouch tx := p.DB(ctx).Where(model.Order{MerchantNo: merchantNo, BatchNo: batchNo, VoucherNo: voucherNo}).Find(&info) if tx.Error != nil { - return nil, tx.Error + return nil, fmt.Errorf("db fail %w", tx.Error) } if tx.RowsAffected == 0 { @@ -147,7 +148,7 @@ func (p *OrderRepoImpl) GetByMBV(ctx context.Context, merchantNo, batchNo, vouch func (p *OrderRepoImpl) Ing(ctx context.Context, id uint64) error { now := time.Now() - res := p.db.DB(ctx). + tx := p.db.DB(ctx). Where(model.Order{ ID: id, Status: vo.OrderStatusWait.GetValue(), @@ -157,8 +158,8 @@ func (p *OrderRepoImpl) Ing(ctx context.Context, id uint64) error { UpdateTime: &now, }) - if res.Error != nil { - return res.Error + if tx.Error != nil { + return fmt.Errorf("db fail %w", tx.Error) } return nil @@ -167,7 +168,7 @@ func (p *OrderRepoImpl) Ing(ctx context.Context, id uint64) error { func (p *OrderRepoImpl) Success(ctx context.Context, id uint64, voucherNo string) error { now := time.Now() - res := p.db.DB(ctx). + tx := p.db.DB(ctx). Where(model.Order{ ID: id, Status: vo.OrderStatusIng.GetValue(), @@ -179,8 +180,8 @@ func (p *OrderRepoImpl) Success(ctx context.Context, id uint64, voucherNo string UpdateTime: &now, }) - if res.Error != nil { - return res.Error + if tx.Error != nil { + return fmt.Errorf("db fail %w", tx.Error) } return nil @@ -189,7 +190,7 @@ func (p *OrderRepoImpl) Success(ctx context.Context, id uint64, voucherNo string func (p *OrderRepoImpl) Available(ctx context.Context, id uint64) error { now := time.Now() - res := p.db.DB(ctx). + tx := p.db.DB(ctx). Where(model.Order{ ID: id, Status: vo.OrderStatusUse.GetValue(), @@ -200,8 +201,8 @@ func (p *OrderRepoImpl) Available(ctx context.Context, id uint64) error { UpdateTime: &now, }) - if res.Error != nil { - return res.Error + if tx.Error != nil { + return fmt.Errorf("db fail %w", tx.Error) } return nil @@ -217,7 +218,7 @@ func (p *OrderRepoImpl) Fail(ctx context.Context, id uint64, remark string) erro } } - res := p.db.DB(ctx). + tx := p.db.DB(ctx). Where(model.Order{ ID: id, }). @@ -227,8 +228,8 @@ func (p *OrderRepoImpl) Fail(ctx context.Context, id uint64, remark string) erro UpdateTime: &now, }) - if res.Error != nil { - return res.Error + if tx.Error != nil { + return fmt.Errorf("db fail %w", tx.Error) } return nil @@ -237,7 +238,7 @@ func (p *OrderRepoImpl) Fail(ctx context.Context, id uint64, remark string) erro func (p *OrderRepoImpl) Used(ctx context.Context, id uint64) error { now := time.Now() - res := p.db.DB(ctx). + tx := p.db.DB(ctx). Where(model.Order{ ID: id, }). @@ -247,8 +248,8 @@ func (p *OrderRepoImpl) Used(ctx context.Context, id uint64) error { UpdateTime: &now, }) - if res.Error != nil { - return res.Error + if tx.Error != nil { + return fmt.Errorf("db fail %w", tx.Error) } return nil @@ -257,7 +258,7 @@ func (p *OrderRepoImpl) Used(ctx context.Context, id uint64) error { func (p *OrderRepoImpl) Expired(ctx context.Context, id uint64) error { now := time.Now() - res := p.db.DB(ctx). + tx := p.db.DB(ctx). Where(model.Order{ ID: id, }). @@ -266,8 +267,8 @@ func (p *OrderRepoImpl) Expired(ctx context.Context, id uint64) error { UpdateTime: &now, }) - if res.Error != nil { - return res.Error + if tx.Error != nil { + return fmt.Errorf("db fail %w", tx.Error) } return nil diff --git a/internal/data/repoimpl/product.go b/internal/data/repoimpl/product.go index ca95f27..2ebbde1 100644 --- a/internal/data/repoimpl/product.go +++ b/internal/data/repoimpl/product.go @@ -2,6 +2,7 @@ package repoimpl import ( "context" + "fmt" "gorm.io/gorm" err2 "voucher/api/err" "voucher/internal/biz/bo" @@ -31,7 +32,7 @@ func (r *ProductRepoImpl) GetByPNO(ctx context.Context, PNO string) (*bo.Product tx := r.DB(ctx).Where(model.Product{ProductNo: PNO}).Find(&item) if tx.Error != nil { - return nil, tx.Error + return nil, fmt.Errorf("db fail %w", tx.Error) } if tx.RowsAffected == 0 {