Add more gitignore

This commit is contained in:
Henri Burau
2024-06-04 14:27:09 +02:00
parent a793da1307
commit e2b9b8f176
28 changed files with 316 additions and 3176 deletions

View File

@ -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
}