105 lines
3.2 KiB
Go
105 lines
3.2 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db"
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
func convertShopDeposit(deposit dbgen.ShopDeposit) domain.ShopDeposit {
|
|
return domain.ShopDeposit{
|
|
ID: deposit.ID,
|
|
ShopTransactionID: deposit.ShopTransactionID,
|
|
CustomerID: deposit.CustomerID,
|
|
WalletTransferID: deposit.WalletTransferID,
|
|
}
|
|
}
|
|
|
|
func convertShopDepositDetail(deposit dbgen.ShopDepositDetail) domain.ShopDepositDetail {
|
|
return domain.ShopDepositDetail{
|
|
ID: deposit.ID,
|
|
ShopTransactionID: deposit.ShopTransactionID,
|
|
CustomerID: deposit.CustomerID,
|
|
WalletTransferID: deposit.WalletTransferID,
|
|
FullName: deposit.FullName,
|
|
PhoneNumber: deposit.PhoneNumber,
|
|
Amount: domain.Currency(deposit.Amount),
|
|
BranchID: deposit.BranchID,
|
|
CompanyID: deposit.CompanyID,
|
|
TransactionVerified: deposit.TransactionVerified,
|
|
UpdatedAt: deposit.UpdatedAt.Time,
|
|
CreatedAt: deposit.CreatedAt.Time,
|
|
}
|
|
}
|
|
func convertCreateShopDeposit(deposit domain.CreateShopDeposit) dbgen.CreateShopDepositParams {
|
|
return dbgen.CreateShopDepositParams{
|
|
ShopTransactionID: deposit.ShopTransactionID,
|
|
CustomerID: deposit.CustomerID,
|
|
WalletTransferID: deposit.WalletTransferID,
|
|
}
|
|
}
|
|
|
|
func (s *Store) CreateShopDeposit(ctx context.Context, deposit domain.CreateShopDeposit) (domain.ShopDeposit, error) {
|
|
newShopDeposit, err := s.queries.CreateShopDeposit(ctx, convertCreateShopDeposit(deposit))
|
|
|
|
if err != nil {
|
|
return domain.ShopDeposit{}, err
|
|
}
|
|
return convertShopDeposit(newShopDeposit), nil
|
|
}
|
|
|
|
func (s *Store) GetAllShopDeposit(ctx context.Context, filter domain.ShopDepositFilter) ([]domain.ShopDepositDetail, error) {
|
|
deposits, err := s.queries.GetAllShopDeposit(ctx, dbgen.GetAllShopDepositParams{
|
|
BranchID: pgtype.Int8{
|
|
Int64: filter.BranchID.Value,
|
|
Valid: filter.BranchID.Valid,
|
|
},
|
|
CompanyID: pgtype.Int8{
|
|
Int64: filter.CompanyID.Value,
|
|
Valid: filter.CompanyID.Valid,
|
|
},
|
|
Query: pgtype.Text{
|
|
String: filter.Query.Value,
|
|
Valid: filter.Query.Valid,
|
|
},
|
|
CreatedBefore: pgtype.Timestamp{
|
|
Time: filter.CreatedBefore.Value,
|
|
Valid: filter.CreatedBefore.Valid,
|
|
},
|
|
CreatedAfter: pgtype.Timestamp{
|
|
Time: filter.CreatedAfter.Value,
|
|
Valid: filter.CreatedAfter.Valid,
|
|
},
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var result []domain.ShopDepositDetail = make([]domain.ShopDepositDetail, 0, len(deposits))
|
|
|
|
for _, deposit := range deposits {
|
|
result = append(result, convertShopDepositDetail(deposit))
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (s *Store) GetShopDepositByID(ctx context.Context, id int64) (domain.ShopDepositDetail, error) {
|
|
deposit, err := s.queries.GetShopDepositByID(ctx, id)
|
|
if err != nil {
|
|
return domain.ShopDepositDetail{}, err
|
|
}
|
|
|
|
return convertShopDepositDetail(deposit), err
|
|
}
|
|
|
|
func (s *Store) GetShopDepositByShopTransactionID(ctx context.Context, shopTransactionID int64) (domain.ShopDepositDetail, error) {
|
|
deposit, err := s.queries.GetShopDepositByShopTransactionID(ctx, shopTransactionID)
|
|
if err != nil {
|
|
return domain.ShopDepositDetail{}, err
|
|
}
|
|
|
|
return convertShopDepositDetail(deposit), err
|
|
}
|