micw/server/repository/repo.go
2024-11-24 15:04:52 +01:00

45 lines
1.6 KiB
Go

package repository
import (
"context"
"github.com/jackc/pgx/v5/pgxpool"
e "mic-wallet/server/repository/entities"
)
type IBlocksRepository interface {
AddBLock(ctx context.Context, opts *e.Block) (err error)
GetBlock(ctx context.Context, id int64) (block *e.Block, err error)
GetBlockByHash(ctx context.Context, hash string) (block *e.Block, err error)
GetBlockWithTxs(ctx context.Context, id int64) (block *e.BlockWithTransactions, err error)
GetBlockWithTxsByHash(ctx context.Context, hash string) (block *e.BlockWithTransactions, err error)
}
type ITransactionsRepository interface {
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)
GetUserIncomingTransactions(
ctx context.Context, userPubKey string, orderAsc bool, limit int, offset int) ([]*e.Transaction, error)
GetUserOutcomingTransactions(
ctx context.Context, userPubKey string, orderAsc bool, limit int, offset int) ([]*e.Transaction, error)
GetUserTransactions(
ctx context.Context, userPubKey string, orderAsc bool, limit int, offset int) ([]*e.Transaction, error)
GetTransactions(
ctx context.Context, orderAsc bool, limit int, offset int) ([]*e.Transaction, error)
}
type Repository struct {
ITransactionsRepository
IBlocksRepository
}
func NewRepository(db *pgxpool.Pool) *Repository {
return &Repository{
ITransactionsRepository: &TransactionRepository{DB: db},
IBlocksRepository: &BlocksRepository{DB: db},
}
}