more report cards
This commit is contained in:
parent
0a668a65f1
commit
6dbce0725d
29
cmd/main.go
29
cmd/main.go
|
|
@ -121,11 +121,11 @@ func main() {
|
|||
|
||||
notificationSvc := notificationservice.New(notificationRepo, logger, cfg)
|
||||
|
||||
var betStore bet.BetStore
|
||||
var walletStore wallet.WalletStore
|
||||
var transactionStore transaction.TransactionStore
|
||||
var branchStore branch.BranchStore
|
||||
var userStore user.UserStore
|
||||
// var betStore bet.BetStore
|
||||
// var walletStore wallet.WalletStore
|
||||
// var transactionStore transaction.TransactionStore
|
||||
// var branchStore branch.BranchStore
|
||||
// var userStore user.UserStore
|
||||
var notificationStore notificationservice.NotificationStore
|
||||
|
||||
walletSvc := wallet.NewService(
|
||||
|
|
@ -173,14 +173,23 @@ func main() {
|
|||
)
|
||||
|
||||
reportSvc := report.NewService(
|
||||
betStore,
|
||||
walletStore,
|
||||
transactionStore,
|
||||
branchStore,
|
||||
userStore,
|
||||
bet.BetStore(store), // Must implement BetStore
|
||||
wallet.WalletStore(store), // Must implement WalletStore
|
||||
transaction.TransactionStore(store),
|
||||
branch.BranchStore(store),
|
||||
user.UserStore(store),
|
||||
logger,
|
||||
)
|
||||
|
||||
// reportSvc := report.NewService(
|
||||
// betStore,
|
||||
// walletStore,
|
||||
// transactionStore,
|
||||
// branchStore,
|
||||
// userStore,
|
||||
// logger,
|
||||
// )
|
||||
|
||||
walletMonitorSvc := monitor.NewService(
|
||||
*walletSvc,
|
||||
*branchSvc,
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ CREATE TABLE IF NOT EXISTS transactions (
|
|||
branch_id BIGINT NOT NULL,
|
||||
company_id BIGINT,
|
||||
cashier_id BIGINT,
|
||||
cashier_name VARCHAR(255)L,
|
||||
cashier_name VARCHAR(255),
|
||||
bet_id BIGINT,
|
||||
number_of_outcomes BIGINT,
|
||||
type BIGINT,
|
||||
|
|
@ -162,6 +162,7 @@ CREATE TABLE IF NOT EXISTS branches (
|
|||
id BIGSERIAL PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
location VARCHAR(255) NOT NULL,
|
||||
is_active BOOLEAN NOT NULL DEFAULT false,
|
||||
wallet_id BIGINT NOT NULL,
|
||||
branch_manager_id BIGINT NOT NULL,
|
||||
company_id BIGINT NOT NULL,
|
||||
|
|
|
|||
|
|
@ -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_type ON notifications (type);
|
||||
|
||||
|
|
|
|||
12
internal/domain/mongoLogs.go
Normal file
12
internal/domain/mongoLogs.go
Normal 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"`
|
||||
}
|
||||
|
|
@ -3,23 +3,13 @@ package mongoLogger
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"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 {
|
||||
return func(c *fiber.Ctx) error {
|
||||
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)
|
||||
|
||||
var logs []LogEntry
|
||||
var logs []domain.LogEntry
|
||||
if err := cursor.All(appCtx, &logs); err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, "Cursor decoding error: "+err.Error())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -309,10 +309,10 @@ func (s *Store) GetBetSummary(ctx context.Context, filter domain.ReportFilter) (
|
|||
) {
|
||||
query := `SELECT
|
||||
COALESCE(SUM(amount), 0) as total_stakes,
|
||||
COUNT(*) as total_bets,
|
||||
SUM(CASE WHEN status = 0 THEN 1 ELSE 0 END) as active_bets,
|
||||
SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) as total_wins,
|
||||
SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END) as total_losses,
|
||||
COALESCE(COUNT(*), 0) as total_bets,
|
||||
COALESCE(SUM(CASE WHEN status = 0 THEN 1 ELSE 0 END), 0) as active_bets,
|
||||
COALESCE(SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END), 0) as total_wins,
|
||||
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
|
||||
FROM bets`
|
||||
|
||||
|
|
|
|||
|
|
@ -144,8 +144,8 @@ func (s *Store) UpdateTransactionVerified(ctx context.Context, id int64, verifie
|
|||
// GetTransactionTotals returns total deposits and withdrawals
|
||||
func (s *Store) GetTransactionTotals(ctx context.Context, filter domain.ReportFilter) (deposits, withdrawals domain.Currency, err error) {
|
||||
query := `SELECT
|
||||
COALESCE(SUM(CASE WHEN type = 'deposit' 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 = 1 THEN amount ELSE 0 END), 0) as deposits,
|
||||
COALESCE(SUM(CASE WHEN type = 0 THEN amount ELSE 0 END), 0) as withdrawals
|
||||
FROM transactions`
|
||||
|
||||
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) {
|
||||
query := `SELECT
|
||||
branch_id,
|
||||
COALESCE(SUM(CASE WHEN type = 'deposit' 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 = 1 THEN amount ELSE 0 END), 0) as deposits,
|
||||
COALESCE(SUM(CASE WHEN type = 0 THEN amount ELSE 0 END), 0) as withdrawals
|
||||
FROM transactions`
|
||||
|
||||
args := []interface{}{}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user