update
This commit is contained in:
141
backend/models.go
Normal file
141
backend/models.go
Normal file
@@ -0,0 +1,141 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var scoreStages = []string{"preliminary", "prelim_tiebreak", "final", "final_tiebreak"}
|
||||
|
||||
type App struct {
|
||||
db *sql.DB
|
||||
cfg Config
|
||||
sessions *SessionStore
|
||||
events *EventHub
|
||||
}
|
||||
|
||||
type SessionStore struct {
|
||||
mu sync.RWMutex
|
||||
tokens map[string]time.Time
|
||||
duration time.Duration
|
||||
}
|
||||
|
||||
type EventHub struct {
|
||||
mu sync.RWMutex
|
||||
nextID int
|
||||
subscribers map[int]chan struct{}
|
||||
}
|
||||
|
||||
type CompetitionMeta struct {
|
||||
TitleAr string `json:"titleAr"`
|
||||
TitleEn string `json:"titleEn"`
|
||||
}
|
||||
|
||||
type Player struct {
|
||||
ID int `json:"id"`
|
||||
NameAr string `json:"nameAr"`
|
||||
NameEn string `json:"nameEn"`
|
||||
GroupCode string `json:"groupCode"`
|
||||
ImageData string `json:"imageData"`
|
||||
}
|
||||
|
||||
type RankingRow struct {
|
||||
PlayerID int `json:"playerId"`
|
||||
NameAr string `json:"nameAr"`
|
||||
NameEn string `json:"nameEn"`
|
||||
GroupCode string `json:"groupCode"`
|
||||
ImageData string `json:"imageData"`
|
||||
Score int `json:"score"`
|
||||
TieBreak int `json:"tieBreak"`
|
||||
Rank int `json:"rank"`
|
||||
Seed int `json:"seed"`
|
||||
FinalGroup int `json:"finalGroup"`
|
||||
}
|
||||
|
||||
type TieBreakInfo struct {
|
||||
Required bool `json:"required"`
|
||||
Resolved bool `json:"resolved"`
|
||||
Slots int `json:"slots"`
|
||||
PlayerIDs []int `json:"playerIds"`
|
||||
}
|
||||
|
||||
type DerivedState struct {
|
||||
PreliminaryRanking RankingBundle `json:"preliminaryRanking"`
|
||||
Finalists []RankingRow `json:"finalists"`
|
||||
FinalGroups FinalGroups `json:"finalGroups"`
|
||||
FinalRanking RankingBundle `json:"finalRanking"`
|
||||
Podium []RankingRow `json:"podium"`
|
||||
}
|
||||
|
||||
type RankingBundle struct {
|
||||
Rows []RankingRow `json:"rows"`
|
||||
TieBreak TieBreakInfo `json:"tieBreak"`
|
||||
Unresolved bool `json:"unresolved"`
|
||||
}
|
||||
|
||||
type FinalGroups struct {
|
||||
Group1 []RankingRow `json:"group1"`
|
||||
Group2 []RankingRow `json:"group2"`
|
||||
}
|
||||
|
||||
type StateResponse struct {
|
||||
Competition CompetitionMeta `json:"competition"`
|
||||
Players []Player `json:"players"`
|
||||
Scores map[string]map[string]int `json:"scores"`
|
||||
ScoreProofs map[string]map[string]string `json:"scoreProofs,omitempty"`
|
||||
Settings AppSettings `json:"settings"`
|
||||
Derived DerivedState `json:"derived"`
|
||||
ServerTime string `json:"serverTime"`
|
||||
}
|
||||
|
||||
type AppSettings struct {
|
||||
ViewProofInView bool `json:"viewProofInView"`
|
||||
}
|
||||
|
||||
type AdminLoginRequest struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type PlayerCreateRequest struct {
|
||||
NameAr string `json:"nameAr"`
|
||||
NameEn string `json:"nameEn"`
|
||||
GroupCode string `json:"groupCode"`
|
||||
}
|
||||
|
||||
type PlayerUpdateRequest struct {
|
||||
NameAr *string `json:"nameAr"`
|
||||
NameEn *string `json:"nameEn"`
|
||||
GroupCode *string `json:"groupCode"`
|
||||
ImageData *string `json:"imageData"`
|
||||
ClearImage bool `json:"clearImage"`
|
||||
}
|
||||
|
||||
type ScoreUpdateRequest struct {
|
||||
Score int `json:"score"`
|
||||
}
|
||||
|
||||
type ScoreProofUpdateRequest struct {
|
||||
ImageData string `json:"imageData"`
|
||||
}
|
||||
|
||||
type AdminSettingsUpdateRequest struct {
|
||||
ViewProofInView *bool `json:"viewProofInView"`
|
||||
}
|
||||
|
||||
type ResetStageRequest struct {
|
||||
ResetProofs bool `json:"resetProofs"`
|
||||
}
|
||||
|
||||
type AutoGroupPlayersRequest struct {
|
||||
Groups []string `json:"groups"`
|
||||
}
|
||||
|
||||
type ScoreAdviceResponse struct {
|
||||
Stage string `json:"stage"`
|
||||
PlayerID int `json:"playerId"`
|
||||
AdvisedScore int `json:"advisedScore"`
|
||||
Reason string `json:"reason"`
|
||||
GeneratedAt string `json:"generatedAt"`
|
||||
}
|
||||
Reference in New Issue
Block a user