- Introduced EventWithSettings and EventWithSettingsRes structs for enhanced event data handling. - Implemented conversion functions for creating and updating event settings. - Added support for fetching events with settings from the database. - Created new report data structures for comprehensive reporting capabilities. - Implemented event statistics retrieval and filtering by league and sport. - Added handlers for event statistics endpoints in the web server. - Introduced DateInterval type for managing time intervals in reports.
253 lines
9.5 KiB
Go
253 lines
9.5 KiB
Go
package domain
|
|
|
|
import (
|
|
"time"
|
|
|
|
dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db"
|
|
)
|
|
|
|
type EventWithSettings struct {
|
|
ID int64
|
|
SourceEventID string
|
|
SportID int32
|
|
MatchName string
|
|
HomeTeam string
|
|
AwayTeam string
|
|
HomeTeamID int64
|
|
AwayTeamID int64
|
|
HomeTeamImage string
|
|
AwayTeamImage string
|
|
LeagueID int64
|
|
LeagueName string
|
|
LeagueCC ValidString
|
|
StartTime time.Time
|
|
Source EventSource
|
|
Status EventStatus
|
|
IsMonitored bool
|
|
IsFeatured bool
|
|
IsActive bool
|
|
WinningUpperLimit int64
|
|
DefaultIsFeatured bool
|
|
DefaultIsActive bool
|
|
DefaultWinningUpperLimit int64
|
|
Score ValidString
|
|
MatchMinute ValidInt
|
|
TimerStatus ValidString
|
|
AddedTime ValidInt
|
|
MatchPeriod ValidInt
|
|
IsLive bool
|
|
UpdatedAt time.Time
|
|
FetchedAt time.Time
|
|
TotalOddOutcomes int64
|
|
NumberOfBets int64
|
|
TotalAmount Currency
|
|
AvgBetAmount Currency
|
|
TotalPotentialWinnings Currency
|
|
}
|
|
|
|
type EventWithSettingsRes struct {
|
|
ID int64 `json:"id"`
|
|
SourceEventID string `json:"source_event_id"`
|
|
SportID int32 `json:"sport_id"`
|
|
MatchName string `json:"match_name"`
|
|
HomeTeam string `json:"home_team"`
|
|
AwayTeam string `json:"away_team"`
|
|
HomeTeamID int64 `json:"home_team_id"`
|
|
AwayTeamID int64 `json:"away_team_id"`
|
|
HomeTeamImage string `json:"home_team_image"`
|
|
AwayTeamImage string `json:"away_team_image"`
|
|
LeagueID int64 `json:"league_id"`
|
|
LeagueName string `json:"league_name"`
|
|
LeagueCC string `json:"league_cc"`
|
|
StartTime time.Time `json:"start_time"`
|
|
Source EventSource `json:"source"`
|
|
Status EventStatus `json:"status"`
|
|
IsMonitored bool `json:"is_monitored"`
|
|
IsFeatured bool `json:"is_featured"`
|
|
IsActive bool `json:"is_active"`
|
|
WinningUpperLimit int64 `json:"winning_upper_limit"`
|
|
DefaultIsFeatured bool `json:"default_is_featured"`
|
|
DefaultIsActive bool `json:"default_is_active"`
|
|
DefaultWinningUpperLimit int64 `json:"default_winning_upper_limit"`
|
|
Score string `json:"score,omitempty"`
|
|
MatchMinute int `json:"match_minute,omitempty"`
|
|
TimerStatus string `json:"timer_status,omitempty"`
|
|
AddedTime int `json:"added_time,omitempty"`
|
|
MatchPeriod int `json:"match_period,omitempty"`
|
|
IsLive bool `json:"is_live"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
FetchedAt time.Time `json:"fetched_at"`
|
|
TotalOddOutcomes int64 `json:"total_odd_outcomes"`
|
|
NumberOfBets int64 `json:"number_of_bets"`
|
|
TotalAmount float32 `json:"total_amount"`
|
|
AvgBetAmount float32 `json:"average_bet_amount"`
|
|
TotalPotentialWinnings float32 `json:"total_potential_winnings"`
|
|
}
|
|
|
|
type EventSettings struct {
|
|
CompanyID int64
|
|
EventID int64
|
|
IsActive ValidBool
|
|
IsFeatured ValidBool
|
|
WinningUpperLimit ValidInt
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
type UpdateTenantEventSettings struct {
|
|
CompanyID int64
|
|
EventID int64
|
|
IsActive ValidBool
|
|
IsFeatured ValidBool
|
|
WinningUpperLimit ValidInt64
|
|
}
|
|
type UpdateGlobalEventSettings struct {
|
|
EventID int64
|
|
IsActive ValidBool
|
|
IsFeatured ValidBool
|
|
WinningUpperLimit ValidInt64
|
|
}
|
|
|
|
func ConvertCreateEventSettings(eventSettings UpdateTenantEventSettings) dbgen.SaveTenantEventSettingsParams {
|
|
return dbgen.SaveTenantEventSettingsParams{
|
|
CompanyID: eventSettings.CompanyID,
|
|
EventID: eventSettings.EventID,
|
|
IsActive: eventSettings.IsActive.ToPG(),
|
|
IsFeatured: eventSettings.IsFeatured.ToPG(),
|
|
WinningUpperLimit: eventSettings.WinningUpperLimit.ToPG(),
|
|
}
|
|
}
|
|
|
|
func ConvertDBEventWithSetting(event dbgen.EventWithSetting) EventWithSettings {
|
|
return EventWithSettings{
|
|
ID: event.ID,
|
|
SourceEventID: event.SourceEventID,
|
|
WinningUpperLimit: event.WinningUpperLimit,
|
|
SportID: event.SportID,
|
|
MatchName: event.MatchName,
|
|
HomeTeam: event.HomeTeam,
|
|
AwayTeam: event.AwayTeam,
|
|
HomeTeamID: event.HomeTeamID,
|
|
AwayTeamID: event.AwayTeamID,
|
|
HomeTeamImage: event.HomeKitImage,
|
|
AwayTeamImage: event.AwayKitImage,
|
|
LeagueID: event.LeagueID,
|
|
LeagueName: event.LeagueName,
|
|
LeagueCC: ValidString{
|
|
Value: event.LeagueCc.String,
|
|
Valid: event.LeagueCc.Valid,
|
|
},
|
|
StartTime: event.StartTime.Time.UTC(),
|
|
Source: EventSource(event.Source),
|
|
Status: EventStatus(event.Status),
|
|
IsFeatured: event.IsFeatured,
|
|
IsMonitored: event.IsMonitored,
|
|
IsActive: event.IsActive,
|
|
DefaultIsFeatured: event.DefaultIsFeatured,
|
|
DefaultIsActive: event.DefaultIsActive,
|
|
DefaultWinningUpperLimit: event.DefaultWinningUpperLimit,
|
|
Score: ValidString{
|
|
Value: event.Score.String,
|
|
Valid: event.Score.Valid,
|
|
},
|
|
MatchMinute: ValidInt{
|
|
Value: int(event.MatchMinute.Int32),
|
|
Valid: event.MatchMinute.Valid,
|
|
},
|
|
TimerStatus: ValidString{
|
|
Value: event.TimerStatus.String,
|
|
Valid: event.TimerStatus.Valid,
|
|
},
|
|
AddedTime: ValidInt{
|
|
Value: int(event.AddedTime.Int32),
|
|
Valid: event.AddedTime.Valid,
|
|
},
|
|
MatchPeriod: ValidInt{
|
|
Value: int(event.MatchPeriod.Int32),
|
|
Valid: event.MatchPeriod.Valid,
|
|
},
|
|
IsLive: event.IsLive,
|
|
UpdatedAt: event.UpdatedAt.Time,
|
|
FetchedAt: event.FetchedAt.Time,
|
|
TotalOddOutcomes: event.TotalOutcomes,
|
|
NumberOfBets: event.NumberOfBets,
|
|
TotalAmount: Currency(event.TotalAmount),
|
|
AvgBetAmount: Currency(event.AvgBetAmount),
|
|
TotalPotentialWinnings: Currency(event.TotalPotentialWinnings),
|
|
}
|
|
}
|
|
|
|
func ConvertDBEventWithSettings(events []dbgen.EventWithSetting) []EventWithSettings {
|
|
result := make([]EventWithSettings, len(events))
|
|
for i, e := range events {
|
|
result[i] = ConvertDBEventWithSetting(e)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func ConvertUpdateTenantEventSettings(event UpdateTenantEventSettings) dbgen.SaveTenantEventSettingsParams {
|
|
return dbgen.SaveTenantEventSettingsParams{
|
|
EventID: event.EventID,
|
|
CompanyID: event.CompanyID,
|
|
IsActive: event.IsActive.ToPG(),
|
|
IsFeatured: event.IsFeatured.ToPG(),
|
|
WinningUpperLimit: event.WinningUpperLimit.ToPG(),
|
|
}
|
|
}
|
|
func ConvertUpdateGlobalEventSettings(event UpdateGlobalEventSettings) dbgen.UpdateGlobalEventSettingsParams {
|
|
return dbgen.UpdateGlobalEventSettingsParams{
|
|
ID: event.EventID,
|
|
DefaultIsActive: event.IsActive.ToPG(),
|
|
DefaultIsFeatured: event.IsFeatured.ToPG(),
|
|
DefaultWinningUpperLimit: event.WinningUpperLimit.ToPG(),
|
|
}
|
|
}
|
|
|
|
func ConvertEventWitSettingRes(event EventWithSettings) EventWithSettingsRes {
|
|
return EventWithSettingsRes{
|
|
ID: event.ID,
|
|
SourceEventID: event.SourceEventID,
|
|
SportID: event.SportID,
|
|
MatchName: event.MatchName,
|
|
HomeTeam: event.HomeTeam,
|
|
AwayTeam: event.AwayTeam,
|
|
HomeTeamID: event.HomeTeamID,
|
|
AwayTeamID: event.AwayTeamID,
|
|
HomeTeamImage: event.HomeTeamImage,
|
|
AwayTeamImage: event.AwayTeamImage,
|
|
LeagueID: event.LeagueID,
|
|
LeagueName: event.LeagueName,
|
|
LeagueCC: event.LeagueCC.Value,
|
|
StartTime: event.StartTime.UTC(),
|
|
Source: EventSource(event.Source),
|
|
Status: EventStatus(event.Status),
|
|
IsFeatured: event.IsFeatured,
|
|
IsMonitored: event.IsMonitored,
|
|
IsActive: event.IsActive,
|
|
DefaultIsFeatured: event.DefaultIsFeatured,
|
|
DefaultIsActive: event.DefaultIsActive,
|
|
DefaultWinningUpperLimit: event.DefaultWinningUpperLimit,
|
|
WinningUpperLimit: event.WinningUpperLimit,
|
|
Score: event.Score.Value,
|
|
MatchMinute: event.MatchMinute.Value,
|
|
TimerStatus: event.TimerStatus.Value,
|
|
AddedTime: event.AddedTime.Value,
|
|
MatchPeriod: event.MatchPeriod.Value,
|
|
IsLive: event.IsLive,
|
|
FetchedAt: event.FetchedAt.UTC(),
|
|
UpdatedAt: event.UpdatedAt,
|
|
TotalOddOutcomes: event.TotalOddOutcomes,
|
|
NumberOfBets: event.NumberOfBets,
|
|
TotalAmount: event.TotalAmount.Float32(),
|
|
AvgBetAmount: event.AvgBetAmount.Float32(),
|
|
TotalPotentialWinnings: event.TotalPotentialWinnings.Float32(),
|
|
}
|
|
}
|
|
|
|
func ConvertEventWithSettingResList(events []EventWithSettings) []EventWithSettingsRes {
|
|
result := make([]EventWithSettingsRes, 0, len(events))
|
|
for _, event := range events {
|
|
result = append(result, ConvertEventWitSettingRes(event))
|
|
}
|
|
return result
|
|
}
|