more report cards

This commit is contained in:
Yared Yemane 2025-06-08 13:55:10 +03:00
parent 0a668a65f1
commit 6dbce0725d
7 changed files with 44 additions and 31 deletions

View File

@ -121,11 +121,11 @@ func main() {
notificationSvc := notificationservice.New(notificationRepo, logger, cfg) notificationSvc := notificationservice.New(notificationRepo, logger, cfg)
var betStore bet.BetStore // var betStore bet.BetStore
var walletStore wallet.WalletStore // var walletStore wallet.WalletStore
var transactionStore transaction.TransactionStore // var transactionStore transaction.TransactionStore
var branchStore branch.BranchStore // var branchStore branch.BranchStore
var userStore user.UserStore // var userStore user.UserStore
var notificationStore notificationservice.NotificationStore var notificationStore notificationservice.NotificationStore
walletSvc := wallet.NewService( walletSvc := wallet.NewService(
@ -173,14 +173,23 @@ func main() {
) )
reportSvc := report.NewService( reportSvc := report.NewService(
betStore, bet.BetStore(store), // Must implement BetStore
walletStore, wallet.WalletStore(store), // Must implement WalletStore
transactionStore, transaction.TransactionStore(store),
branchStore, branch.BranchStore(store),
userStore, user.UserStore(store),
logger, logger,
) )
// reportSvc := report.NewService(
// betStore,
// walletStore,
// transactionStore,
// branchStore,
// userStore,
// logger,
// )
walletMonitorSvc := monitor.NewService( walletMonitorSvc := monitor.NewService(
*walletSvc, *walletSvc,
*branchSvc, *branchSvc,

View File

@ -138,7 +138,7 @@ CREATE TABLE IF NOT EXISTS transactions (
branch_id BIGINT NOT NULL, branch_id BIGINT NOT NULL,
company_id BIGINT, company_id BIGINT,
cashier_id BIGINT, cashier_id BIGINT,
cashier_name VARCHAR(255)L, cashier_name VARCHAR(255),
bet_id BIGINT, bet_id BIGINT,
number_of_outcomes BIGINT, number_of_outcomes BIGINT,
type BIGINT, type BIGINT,
@ -162,6 +162,7 @@ CREATE TABLE IF NOT EXISTS branches (
id BIGSERIAL PRIMARY KEY, id BIGSERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
location VARCHAR(255) NOT NULL, location VARCHAR(255) NOT NULL,
is_active BOOLEAN NOT NULL DEFAULT false,
wallet_id BIGINT NOT NULL, wallet_id BIGINT NOT NULL,
branch_manager_id BIGINT NOT NULL, branch_manager_id BIGINT NOT NULL,
company_id BIGINT NOT NULL, company_id BIGINT NOT NULL,

View File

@ -44,3 +44,4 @@ CREATE INDEX idx_notifications_recipient_id ON notifications (recipient_id);
CREATE INDEX idx_notifications_timestamp ON notifications (timestamp); CREATE INDEX idx_notifications_timestamp ON notifications (timestamp);
CREATE INDEX idx_notifications_type ON notifications (type); CREATE INDEX idx_notifications_type ON notifications (type);

View File

@ -0,0 +1,12 @@
package domain
type LogEntry struct {
Level string `json:"level" bson:"level"`
Message string `json:"message" bson:"message"`
Timestamp string `json:"timestamp" bson:"timestamp"`
Fields map[string]interface{} `json:"fields" bson:"fields"`
Caller string `json:"caller" bson:"caller"`
Stack string `json:"stacktrace" bson:"stacktrace"`
Service string `json:"service" bson:"service"`
Env string `json:"env" bson:"env"`
}

View File

@ -3,23 +3,13 @@ package mongoLogger
import ( import (
"context" "context"
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/options"
) )
type LogEntry struct {
Level string `json:"level" bson:"level"`
Message string `json:"message" bson:"message"`
Timestamp string `json:"timestamp" bson:"timestamp"`
Fields map[string]interface{} `json:"fields" bson:"fields"`
Caller string `json:"caller" bson:"caller"`
Stack string `json:"stacktrace" bson:"stacktrace"`
Service string `json:"service" bson:"service"`
Env string `json:"env" bson:"env"`
}
func GetLogsHandler(appCtx context.Context) fiber.Handler { func GetLogsHandler(appCtx context.Context) fiber.Handler {
return func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error {
client, err := mongo.Connect(appCtx, options.Client().ApplyURI("mongodb://root:secret@mongo:27017/?authSource=admin")) client, err := mongo.Connect(appCtx, options.Client().ApplyURI("mongodb://root:secret@mongo:27017/?authSource=admin"))
@ -37,7 +27,7 @@ func GetLogsHandler(appCtx context.Context) fiber.Handler {
} }
defer cursor.Close(appCtx) defer cursor.Close(appCtx)
var logs []LogEntry var logs []domain.LogEntry
if err := cursor.All(appCtx, &logs); err != nil { if err := cursor.All(appCtx, &logs); err != nil {
return fiber.NewError(fiber.StatusInternalServerError, "Cursor decoding error: "+err.Error()) return fiber.NewError(fiber.StatusInternalServerError, "Cursor decoding error: "+err.Error())
} }

View File

@ -309,10 +309,10 @@ func (s *Store) GetBetSummary(ctx context.Context, filter domain.ReportFilter) (
) { ) {
query := `SELECT query := `SELECT
COALESCE(SUM(amount), 0) as total_stakes, COALESCE(SUM(amount), 0) as total_stakes,
COUNT(*) as total_bets, COALESCE(COUNT(*), 0) as total_bets,
SUM(CASE WHEN status = 0 THEN 1 ELSE 0 END) as active_bets, COALESCE(SUM(CASE WHEN status = 0 THEN 1 ELSE 0 END), 0) as active_bets,
SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) as total_wins, COALESCE(SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END), 0) as total_wins,
SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END) as total_losses, COALESCE(SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END), 0) as total_losses,
COALESCE(SUM(CASE WHEN status = 1 THEN amount * total_odds ELSE 0 END), 0) as win_balance COALESCE(SUM(CASE WHEN status = 1 THEN amount * total_odds ELSE 0 END), 0) as win_balance
FROM bets` FROM bets`

View File

@ -144,8 +144,8 @@ func (s *Store) UpdateTransactionVerified(ctx context.Context, id int64, verifie
// GetTransactionTotals returns total deposits and withdrawals // GetTransactionTotals returns total deposits and withdrawals
func (s *Store) GetTransactionTotals(ctx context.Context, filter domain.ReportFilter) (deposits, withdrawals domain.Currency, err error) { func (s *Store) GetTransactionTotals(ctx context.Context, filter domain.ReportFilter) (deposits, withdrawals domain.Currency, err error) {
query := `SELECT query := `SELECT
COALESCE(SUM(CASE WHEN type = 'deposit' THEN amount ELSE 0 END), 0) as deposits, COALESCE(SUM(CASE WHEN type = 1 THEN amount ELSE 0 END), 0) as deposits,
COALESCE(SUM(CASE WHEN type = 'withdrawal' THEN amount ELSE 0 END), 0) as withdrawals COALESCE(SUM(CASE WHEN type = 0 THEN amount ELSE 0 END), 0) as withdrawals
FROM transactions` FROM transactions`
args := []interface{}{} args := []interface{}{}
@ -193,8 +193,8 @@ func (s *Store) GetTransactionTotals(ctx context.Context, filter domain.ReportFi
func (s *Store) GetBranchTransactionTotals(ctx context.Context, filter domain.ReportFilter) (map[int64]domain.BranchTransactions, error) { func (s *Store) GetBranchTransactionTotals(ctx context.Context, filter domain.ReportFilter) (map[int64]domain.BranchTransactions, error) {
query := `SELECT query := `SELECT
branch_id, branch_id,
COALESCE(SUM(CASE WHEN type = 'deposit' THEN amount ELSE 0 END), 0) as deposits, COALESCE(SUM(CASE WHEN type = 1 THEN amount ELSE 0 END), 0) as deposits,
COALESCE(SUM(CASE WHEN type = 'withdrawal' THEN amount ELSE 0 END), 0) as withdrawals COALESCE(SUM(CASE WHEN type = 0 THEN amount ELSE 0 END), 0) as withdrawals
FROM transactions` FROM transactions`
args := []interface{}{} args := []interface{}{}