feat(loyalty): EnakPoint & EnakCoin #32
@@ -188,17 +188,20 @@ func (r *walletRepository) CreateTransaction(ctx context.Context, walletTx *enti
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *walletRepository) GetTransactionByIdempotencyKey(ctx context.Context, key string) (*entities.WalletTransaction, error) {
|
func (r *walletRepository) GetTransactionByIdempotencyKey(ctx context.Context, key string) (*entities.WalletTransaction, error) {
|
||||||
var walletTx entities.WalletTransaction
|
// Find rather than First: a new key is the normal case, and First would log every
|
||||||
|
// one of them as a "record not found" error.
|
||||||
|
var walletTxs []entities.WalletTransaction
|
||||||
err := DBFromContext(ctx, r.db).WithContext(ctx).
|
err := DBFromContext(ctx, r.db).WithContext(ctx).
|
||||||
Where("idempotency_key = ?", key).
|
Where("idempotency_key = ?", key).
|
||||||
First(&walletTx).Error
|
Limit(1).
|
||||||
|
Find(&walletTxs).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("failed to get wallet transaction by idempotency key: %w", err)
|
return nil, fmt.Errorf("failed to get wallet transaction by idempotency key: %w", err)
|
||||||
}
|
}
|
||||||
return &walletTx, nil
|
if len(walletTxs) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return &walletTxs[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *walletRepository) CreateLot(ctx context.Context, lot *entities.WalletLot) error {
|
func (r *walletRepository) CreateLot(ctx context.Context, lot *entities.WalletLot) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user