initial commit
This commit is contained in:
33
internal/model/game.go
Normal file
33
internal/model/game.go
Normal 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)
|
||||
}
|
||||
}
|
||||
26
internal/model/gameResult.go
Normal file
26
internal/model/gameResult.go
Normal 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
31
internal/model/player.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user