- 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.
70 lines
1.4 KiB
Go
70 lines
1.4 KiB
Go
package domain
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
type EventStatus string
|
|
|
|
const (
|
|
STATUS_PENDING EventStatus = "upcoming"
|
|
STATUS_IN_PLAY EventStatus = "in_play"
|
|
STATUS_TO_BE_FIXED EventStatus = "to_be_fixed"
|
|
STATUS_ENDED EventStatus = "ended"
|
|
STATUS_POSTPONED EventStatus = "postponed"
|
|
STATUS_CANCELLED EventStatus = "cancelled"
|
|
STATUS_WALKOVER EventStatus = "walkover"
|
|
STATUS_INTERRUPTED EventStatus = "interrupted"
|
|
STATUS_ABANDONED EventStatus = "abandoned"
|
|
STATUS_RETIRED EventStatus = "retired"
|
|
STATUS_SUSPENDED EventStatus = "suspended"
|
|
STATUS_DECIDED_BY_FA EventStatus = "decided_by_fa"
|
|
STATUS_REMOVED EventStatus = "removed"
|
|
)
|
|
|
|
func (s EventStatus) IsValid() bool {
|
|
switch s {
|
|
case STATUS_PENDING,
|
|
STATUS_IN_PLAY,
|
|
STATUS_TO_BE_FIXED,
|
|
STATUS_ENDED,
|
|
STATUS_POSTPONED,
|
|
STATUS_CANCELLED,
|
|
STATUS_WALKOVER,
|
|
STATUS_INTERRUPTED,
|
|
STATUS_ABANDONED,
|
|
STATUS_RETIRED,
|
|
STATUS_SUSPENDED,
|
|
STATUS_DECIDED_BY_FA,
|
|
STATUS_REMOVED:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func ParseEventStatus(val string) (EventStatus, error) {
|
|
s := EventStatus(val)
|
|
if !s.IsValid() {
|
|
return "", fmt.Errorf("invalid EventStatus: %q", val)
|
|
}
|
|
return s, nil
|
|
}
|
|
|
|
|
|
|
|
type ValidEventStatus struct {
|
|
Value EventStatus
|
|
Valid bool
|
|
}
|
|
|
|
func (v ValidEventStatus) ToPG() pgtype.Text {
|
|
return pgtype.Text{
|
|
String: string(v.Value),
|
|
Valid: v.Valid,
|
|
}
|
|
}
|
|
|