- Introduced BetStatStore, BranchStatStore, and WalletStatStore interfaces for handling statistics. - Implemented repository methods for fetching and updating bet, branch, and wallet statistics. - Created reporting services for generating interval reports for bets, branches, companies, and wallets. - Enhanced CSV writing functionality to support dynamic struct to CSV conversion. - Added cron jobs for periodic updates of branch and wallet statistics. - Updated wallet handler to include transaction statistics in the response.
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db"
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/ports"
|
|
)
|
|
|
|
// Interface for creating new wallet stats store
|
|
func NewWalletStatStore(s *Store) ports.WalletStatStore { return s }
|
|
|
|
func (s *Store) UpdateWalletStats(ctx context.Context) error {
|
|
return s.queries.UpdateWalletStats(ctx)
|
|
}
|
|
|
|
func (s *Store) GetWalletStatByID(ctx context.Context, walletID int64) ([]domain.WalletStat, error) {
|
|
stats, err := s.queries.GetWalletStatsByID(ctx, walletID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return domain.ConvertDBWalletStatsList(stats), nil
|
|
}
|
|
|
|
func (s *Store) GetWalletStatsByInterval(ctx context.Context, filter domain.WalletStatFilter) ([]domain.WalletStat, error) {
|
|
stats, err := s.queries.GetWalletStats(ctx, dbgen.GetWalletStatsParams{
|
|
Interval: filter.Interval.ToPG(),
|
|
UserID: filter.UserID.ToPG(),
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return domain.ConvertDBWalletStatsByIntervalList(stats), nil
|
|
}
|