Add more gitignore
This commit is contained in:
@ -11,27 +11,26 @@ import (
|
||||
type MapScoreList []MapScore
|
||||
|
||||
type Capture struct {
|
||||
ID int64 `bun:",pk,autoincrement"`
|
||||
Host string
|
||||
Port string
|
||||
Name string
|
||||
Active bool
|
||||
Start time.Time
|
||||
ID int64 `bun:",pk,autoincrement"`
|
||||
Host string `bun:",notnull"`
|
||||
Port string `bun:",notnull"`
|
||||
Name string `bun:",unique,notnull"`
|
||||
Active bool `bun:",notnull"`
|
||||
Start time.Time `bun:",notnull,default:current_timestamp"`
|
||||
MapScores MapScoreList `bun:"rel:has-many,join:id=capture_id"`
|
||||
}
|
||||
|
||||
type MapScore struct {
|
||||
ID int64 `bun:",pk,autoincrement"`
|
||||
CaptureID int64 `bun:"capture_id"`
|
||||
StartTime time.Time
|
||||
Map string
|
||||
ScoreList []Score `bun:"rel:has-many,join:id=mapscore_id"`
|
||||
ID int64 `bun:",pk,autoincrement"`
|
||||
CaptureID int64 `bun:"capture_id"`
|
||||
StartTime time.Time `bun:",notnull"`
|
||||
Map string `bun:",notnull"`
|
||||
ScoreList []Score `bun:"rel:has-many,join:id=mapscore_id"`
|
||||
}
|
||||
|
||||
type Score struct {
|
||||
ID int64 `bun:",pk,autoincrement"`
|
||||
MapScoreID int64 `bun:"mapscore_id"`
|
||||
Name string
|
||||
Name string `bun:",pk,notnull"`
|
||||
MapScoreID int64 `bun:"mapscore_id,pk,notnull"`
|
||||
Score int
|
||||
Ping int
|
||||
}
|
||||
@ -57,7 +56,7 @@ func (msl MapScoreList) BuildTable() *ResultTable {
|
||||
Header: []ResultTableHeader{{Title: "Name"}, {Title: "Total"}},
|
||||
}
|
||||
|
||||
userMapRows := make(map[string]*ResultTableRow)
|
||||
userMapRows := make(map[string]int)
|
||||
|
||||
for mapIndex, mapScore := range msl {
|
||||
rt.Header = append(rt.Header, ResultTableHeader{
|
||||
@ -73,12 +72,12 @@ func (msl MapScoreList) BuildTable() *ResultTable {
|
||||
Individual: make([]int, len(msl)),
|
||||
})
|
||||
|
||||
userMapRows[score.Name] = &rt.Rows[len(rt.Rows)-1]
|
||||
userMapRows[score.Name] = len(rt.Rows) - 1
|
||||
}
|
||||
|
||||
row := userMapRows[score.Name]
|
||||
row.Total = row.Total + score.Score
|
||||
row.Individual[mapIndex] = score.Score
|
||||
rt.Rows[row].Total = rt.Rows[row].Total + score.Score
|
||||
rt.Rows[row].Individual[mapIndex] = score.Score
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,6 +13,13 @@ import (
|
||||
type Persistence interface {
|
||||
CreateCapture(context.Context, *Capture) error
|
||||
GetCaptures(context.Context) ([]Capture, error)
|
||||
GetCapturesByID(context.Context, int64) (*Capture, error)
|
||||
DeleteCapture(context.Context, int64) error
|
||||
|
||||
GetRecentMapScore(context.Context, int64) (*MapScore, error)
|
||||
CreateMapScore(context.Context, *MapScore) error
|
||||
|
||||
CreateOrUpdateScores(context.Context, []Score) error
|
||||
}
|
||||
|
||||
type SQLitePersistence struct {
|
||||
@ -51,8 +58,53 @@ func (s *SQLitePersistence) GetCaptures(ctx context.Context) ([]Capture, error)
|
||||
return captures, nil
|
||||
}
|
||||
|
||||
func (s *SQLitePersistence) GetCapturesByID(ctx context.Context, id int64) (*Capture, error) {
|
||||
capture := Capture{
|
||||
ID: id,
|
||||
}
|
||||
|
||||
err := s.db.NewSelect().Model(&capture).WherePK().Relation("MapScores").Relation("MapScores.ScoreList").Scan(ctx)
|
||||
|
||||
return &capture, err
|
||||
}
|
||||
|
||||
func (s *SQLitePersistence) DeleteCapture(ctx context.Context, id int64) error {
|
||||
capture := Capture{
|
||||
ID: id,
|
||||
}
|
||||
|
||||
_, err := s.db.NewDelete().Model(&capture).WherePK().Exec(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SQLitePersistence) CreateCapture(ctx context.Context, capture *Capture) error {
|
||||
_, err := s.db.NewInsert().Model(capture).Exec(ctx)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SQLitePersistence) GetRecentMapScore(ctx context.Context, captureid int64) (*MapScore, error) {
|
||||
var scores []MapScore
|
||||
|
||||
err := s.db.NewSelect().Model(&scores).Where("capture_id = ?", captureid).Limit(1).Order("start_time DESC").Scan(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(scores) <= 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return &scores[0], nil
|
||||
}
|
||||
|
||||
func (s *SQLitePersistence) CreateMapScore(ctx context.Context, mapscore *MapScore) error {
|
||||
_, err := s.db.NewInsert().Model(mapscore).Exec(ctx)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SQLitePersistence) CreateOrUpdateScores(ctx context.Context, scores []Score) error {
|
||||
_, err := s.db.NewInsert().Model(&scores).On("CONFLICT (name, mapscore_id) DO UPDATE").Exec(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user