Add leaderboard for all tracks and track calendar

This commit is contained in:
2026-07-15 11:53:35 +04:00
parent 4a894a4399
commit a56841237d
20 changed files with 1394 additions and 25 deletions
+34 -3
View File
@@ -8,15 +8,18 @@ import (
// memoryStore is an in-process implementation of Store for tests and
// for early PoC runs without a database. It is goroutine-safe.
type memoryStore struct {
mu sync.Mutex
tracks map[TrackID]TrackMeta
cars map[CarID]CarMeta
mu sync.Mutex
tracks map[TrackID]TrackMeta
cars map[CarID]CarMeta
calendar []TrackCalendarEntry
nextID int
}
func newMemoryStore() *memoryStore {
return &memoryStore{
tracks: make(map[TrackID]TrackMeta),
cars: make(map[CarID]CarMeta),
nextID: 1,
}
}
@@ -72,4 +75,32 @@ func (m *memoryStore) UpdateCarStats(_ context.Context, id string, fn func(*CarM
fn(&c)
m.cars[id] = c
return nil
}
func (m *memoryStore) GetTrackCalendar(_ context.Context) ([]TrackCalendarEntry, error) {
m.mu.Lock()
defer m.mu.Unlock()
out := append([]TrackCalendarEntry(nil), m.calendar...)
return out, nil
}
func (m *memoryStore) CreateTrackCalendar(_ context.Context, entry TrackCalendarEntry) (TrackCalendarEntry, error) {
m.mu.Lock()
defer m.mu.Unlock()
entry.ID = m.nextID
m.nextID++
m.calendar = append(m.calendar, entry)
return entry, nil
}
func (m *memoryStore) DeleteTrackCalendar(_ context.Context, id int) error {
m.mu.Lock()
defer m.mu.Unlock()
for i, entry := range m.calendar {
if entry.ID == id {
m.calendar = append(m.calendar[:i], m.calendar[i+1:]...)
return nil
}
}
return ErrNotFound
}