222 lines
5.5 KiB
Go
222 lines
5.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: direct_deposit.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const ApproveDirectDeposit = `-- name: ApproveDirectDeposit :exec
|
|
UPDATE direct_deposits
|
|
SET
|
|
status = 'APPROVED',
|
|
approved_by = $2,
|
|
approved_at = NOW()
|
|
WHERE
|
|
id = $1
|
|
AND status = 'PENDING'
|
|
`
|
|
|
|
type ApproveDirectDepositParams struct {
|
|
ID int64 `json:"id"`
|
|
ApprovedBy pgtype.Int8 `json:"approved_by"`
|
|
}
|
|
|
|
func (q *Queries) ApproveDirectDeposit(ctx context.Context, arg ApproveDirectDepositParams) error {
|
|
_, err := q.db.Exec(ctx, ApproveDirectDeposit, arg.ID, arg.ApprovedBy)
|
|
return err
|
|
}
|
|
|
|
const CountDirectDepositsByStatus = `-- name: CountDirectDepositsByStatus :one
|
|
SELECT COUNT(*)
|
|
FROM direct_deposits
|
|
WHERE status = $1
|
|
`
|
|
|
|
func (q *Queries) CountDirectDepositsByStatus(ctx context.Context, status pgtype.Text) (int64, error) {
|
|
row := q.db.QueryRow(ctx, CountDirectDepositsByStatus, status)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const CreateDirectDeposit = `-- name: CreateDirectDeposit :one
|
|
INSERT INTO direct_deposits (
|
|
customer_id, wallet_id, bank_name, account_number,
|
|
account_holder, amount, reference_number,
|
|
transfer_screenshot, status
|
|
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,'PENDING')
|
|
RETURNING id, customer_id, wallet_id, bank_name, account_number, account_holder, amount, reference_number, transfer_screenshot, status, created_at, approved_by, approved_at, rejection_reason
|
|
`
|
|
|
|
type CreateDirectDepositParams struct {
|
|
CustomerID pgtype.Int8 `json:"customer_id"`
|
|
WalletID pgtype.Int8 `json:"wallet_id"`
|
|
BankName pgtype.Text `json:"bank_name"`
|
|
AccountNumber pgtype.Text `json:"account_number"`
|
|
AccountHolder pgtype.Text `json:"account_holder"`
|
|
Amount pgtype.Numeric `json:"amount"`
|
|
ReferenceNumber pgtype.Text `json:"reference_number"`
|
|
TransferScreenshot pgtype.Text `json:"transfer_screenshot"`
|
|
}
|
|
|
|
func (q *Queries) CreateDirectDeposit(ctx context.Context, arg CreateDirectDepositParams) (DirectDeposit, error) {
|
|
row := q.db.QueryRow(ctx, CreateDirectDeposit,
|
|
arg.CustomerID,
|
|
arg.WalletID,
|
|
arg.BankName,
|
|
arg.AccountNumber,
|
|
arg.AccountHolder,
|
|
arg.Amount,
|
|
arg.ReferenceNumber,
|
|
arg.TransferScreenshot,
|
|
)
|
|
var i DirectDeposit
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CustomerID,
|
|
&i.WalletID,
|
|
&i.BankName,
|
|
&i.AccountNumber,
|
|
&i.AccountHolder,
|
|
&i.Amount,
|
|
&i.ReferenceNumber,
|
|
&i.TransferScreenshot,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.ApprovedBy,
|
|
&i.ApprovedAt,
|
|
&i.RejectionReason,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const DeleteDirectDeposit = `-- name: DeleteDirectDeposit :exec
|
|
DELETE FROM direct_deposits
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteDirectDeposit(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, DeleteDirectDeposit, id)
|
|
return err
|
|
}
|
|
|
|
const GetDirectDepositByID = `-- name: GetDirectDepositByID :one
|
|
SELECT id, customer_id, wallet_id, bank_name, account_number, account_holder, amount, reference_number, transfer_screenshot, status, created_at, approved_by, approved_at, rejection_reason
|
|
FROM direct_deposits
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetDirectDepositByID(ctx context.Context, id int64) (DirectDeposit, error) {
|
|
row := q.db.QueryRow(ctx, GetDirectDepositByID, id)
|
|
var i DirectDeposit
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CustomerID,
|
|
&i.WalletID,
|
|
&i.BankName,
|
|
&i.AccountNumber,
|
|
&i.AccountHolder,
|
|
&i.Amount,
|
|
&i.ReferenceNumber,
|
|
&i.TransferScreenshot,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.ApprovedBy,
|
|
&i.ApprovedAt,
|
|
&i.RejectionReason,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetDirectDepositsByStatus = `-- name: GetDirectDepositsByStatus :many
|
|
SELECT
|
|
id,
|
|
customer_id,
|
|
wallet_id,
|
|
bank_name,
|
|
account_number,
|
|
account_holder,
|
|
amount,
|
|
reference_number,
|
|
transfer_screenshot,
|
|
status,
|
|
created_at,
|
|
approved_by,
|
|
approved_at,
|
|
rejection_reason
|
|
FROM direct_deposits
|
|
WHERE status = $1
|
|
ORDER BY created_at DESC
|
|
LIMIT $2 OFFSET $3
|
|
`
|
|
|
|
type GetDirectDepositsByStatusParams struct {
|
|
Status pgtype.Text `json:"status"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) GetDirectDepositsByStatus(ctx context.Context, arg GetDirectDepositsByStatusParams) ([]DirectDeposit, error) {
|
|
rows, err := q.db.Query(ctx, GetDirectDepositsByStatus, arg.Status, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []DirectDeposit
|
|
for rows.Next() {
|
|
var i DirectDeposit
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CustomerID,
|
|
&i.WalletID,
|
|
&i.BankName,
|
|
&i.AccountNumber,
|
|
&i.AccountHolder,
|
|
&i.Amount,
|
|
&i.ReferenceNumber,
|
|
&i.TransferScreenshot,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.ApprovedBy,
|
|
&i.ApprovedAt,
|
|
&i.RejectionReason,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const RejectDirectDeposit = `-- name: RejectDirectDeposit :exec
|
|
UPDATE direct_deposits
|
|
SET
|
|
status = 'REJECTED',
|
|
approved_by = $2, -- still track the admin who took final action
|
|
approved_at = NOW(),
|
|
rejection_reason = $3
|
|
WHERE
|
|
id = $1
|
|
AND status = 'PENDING'
|
|
`
|
|
|
|
type RejectDirectDepositParams struct {
|
|
ID int64 `json:"id"`
|
|
ApprovedBy pgtype.Int8 `json:"approved_by"`
|
|
RejectionReason pgtype.Text `json:"rejection_reason"`
|
|
}
|
|
|
|
func (q *Queries) RejectDirectDeposit(ctx context.Context, arg RejectDirectDepositParams) error {
|
|
_, err := q.db.Exec(ctx, RejectDirectDeposit, arg.ID, arg.ApprovedBy, arg.RejectionReason)
|
|
return err
|
|
}
|