initial commit

This commit is contained in:
2025-02-02 15:11:35 +01:00
commit 3640116dd5
39 changed files with 10298 additions and 0 deletions

33
internal/model/game.go Normal file
View File

@@ -0,0 +1,33 @@
package model
import (
"fmt"
"time"
)
type GameID string
type Game struct {
ID GameID `json:"id"`
Added time.Time `json:"added"`
Author PlayerID `json:"author"`
Team0Player0 PlayerID `json:"t0p0"`
Team0Player1 PlayerID `json:"t0p1"`
Team1Player0 PlayerID `json:"t1p0"`
Team1Player1 PlayerID `json:"t1p1"`
Score int `json:"score"`
Overtime bool `jsone:"ot"`
}
func (id *GameID) Scan(src any) error {
switch v := src.(type) {
case int64:
*id = GameID(fmt.Sprintf("%d", v))
return nil
case string:
*id = GameID(v)
return nil
default:
return fmt.Errorf("unsupported type %T for GameID", src)
}
}

View File

@@ -0,0 +1,26 @@
package model
import "fmt"
type GameResultID string
type GameResult struct {
ID GameResultID
Game GameID
Player PlayerID
StartElo int
EndElo int
}
func (id *GameResultID) Scan(src any) error {
switch v := src.(type) {
case int64:
*id = GameResultID(fmt.Sprintf("%d", v)) // Convert int64 to string and assign it
return nil
case string:
*id = GameResultID(v)
return nil
default:
return fmt.Errorf("unsupported type %T for GameResultID", src)
}
}

31
internal/model/player.go Normal file
View File

@@ -0,0 +1,31 @@
package model
import "fmt"
type PlayerID string
type Player struct {
ID PlayerID
Name string
Elo int
}
func NewPlayer(name string) Player {
return Player{
Name: name,
Elo: 1000,
}
}
func (id *PlayerID) Scan(src any) error {
switch v := src.(type) {
case int64:
*id = PlayerID(fmt.Sprintf("%d", v)) // Convert int64 to string and assign it
return nil
case string:
*id = PlayerID(v)
return nil
default:
return fmt.Errorf("unsupported type %T for PlayerID", src)
}
}