Add Balance and Withdrawal
This commit is contained in:
@@ -20,12 +20,20 @@ func NewTransactionRepository(db *gorm.DB) *TransactionRepository {
|
||||
}
|
||||
|
||||
// Create creates a new transaction in the database.
|
||||
func (r *TransactionRepository) Create(ctx context.Context, transaction *entity.Transaction) (*entity.Transaction, error) {
|
||||
if err := r.db.WithContext(ctx).Create(transaction).Error; err != nil {
|
||||
func (r *TransactionRepository) Create(ctx context.Context, trx *gorm.DB, transaction *entity.Transaction) (*entity.Transaction, error) {
|
||||
// Create the transaction record
|
||||
if err := trx.WithContext(ctx).Create(transaction).Error; err != nil {
|
||||
zap.L().Error("error when creating transaction", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
return r.FindByID(ctx, transaction.ID)
|
||||
|
||||
// Retrieve the created transaction using the same transaction context
|
||||
var createdTransaction entity.Transaction
|
||||
if err := trx.WithContext(ctx).First(&createdTransaction, "id = ?", transaction.ID).Error; err != nil {
|
||||
zap.L().Error("error when fetching newly created transaction", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
return &createdTransaction, nil
|
||||
}
|
||||
|
||||
// Update updates an existing transaction in the database.
|
||||
@@ -126,7 +134,7 @@ func (r *TransactionRepository) GetTransactionList(ctx mycontext.Context, req en
|
||||
var transactions []*entity.TransactionList
|
||||
var total int64
|
||||
|
||||
query := r.db.Table("transaction t").
|
||||
query := r.db.Table("transactions t").
|
||||
Select("t.id, t.transaction_type, t.status, t.created_at, s.name as site_name, p.name as partner_name, t.amount").
|
||||
Joins("left join sites s on t.site_id = s.id").
|
||||
Joins("left join partners p on t.partner_id = p.id").
|
||||
|
||||
Reference in New Issue
Block a user