2024-11-13 21:10:13 +00:00
|
|
|
package repository
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
e "mic-wallet/server/repository/entities"
|
|
|
|
)
|
|
|
|
|
|
|
|
type IBlocksRepository interface {
|
2024-11-24 14:04:52 +00:00
|
|
|
AddBLock(ctx context.Context, opts *e.Block) (err error)
|
|
|
|
|
2024-11-13 21:10:13 +00:00
|
|
|
GetBlock(ctx context.Context, id int64) (block *e.Block, err error)
|
|
|
|
GetBlockByHash(ctx context.Context, hash string) (block *e.Block, err error)
|
2024-11-24 14:04:52 +00:00
|
|
|
|
|
|
|
GetBlockWithTxs(ctx context.Context, id int64) (block *e.BlockWithTransactions, err error)
|
|
|
|
GetBlockWithTxsByHash(ctx context.Context, hash string) (block *e.BlockWithTransactions, err error)
|
2024-11-13 21:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ITransactionsRepository interface {
|
2024-11-24 14:04:52 +00:00
|
|
|
AddTransaction(ctx context.Context, opts *e.NewTransactionOpts) (transaction *e.Transaction, err error)
|
|
|
|
AddTransactions(ctx context.Context, opts []*e.NewTransactionOpts) (err error)
|
|
|
|
|
|
|
|
GetTransaction(ctx context.Context, hash string) (tx *e.Transaction, err error)
|
2024-11-13 21:10:13 +00:00
|
|
|
GetUserIncomingTransactions(
|
2024-11-24 14:04:52 +00:00
|
|
|
ctx context.Context, userPubKey string, orderAsc bool, limit int, offset int) ([]*e.Transaction, error)
|
2024-11-13 21:10:13 +00:00
|
|
|
GetUserOutcomingTransactions(
|
2024-11-24 14:04:52 +00:00
|
|
|
ctx context.Context, userPubKey string, orderAsc bool, limit int, offset int) ([]*e.Transaction, error)
|
2024-11-13 21:10:13 +00:00
|
|
|
GetUserTransactions(
|
2024-11-24 14:04:52 +00:00
|
|
|
ctx context.Context, userPubKey string, orderAsc bool, limit int, offset int) ([]*e.Transaction, error)
|
2024-11-13 21:10:13 +00:00
|
|
|
GetTransactions(
|
2024-11-24 14:04:52 +00:00
|
|
|
ctx context.Context, orderAsc bool, limit int, offset int) ([]*e.Transaction, error)
|
2024-11-13 21:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Repository struct {
|
|
|
|
ITransactionsRepository
|
|
|
|
IBlocksRepository
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRepository(db *pgxpool.Pool) *Repository {
|
|
|
|
return &Repository{
|
|
|
|
ITransactionsRepository: &TransactionRepository{DB: db},
|
|
|
|
IBlocksRepository: &BlocksRepository{DB: db},
|
|
|
|
}
|
|
|
|
}
|