mirror of
https://github.com/IS1DI/x0gp.git
synced 2026-07-16 20:47:55 +00:00
Add leaderboard for all tracks and track calendar
This commit is contained in:
@@ -606,4 +606,45 @@ func (s *Service) ListCarsByOwner(ownerID string) []CarMeta {
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// GetTrackCalendar returns all track calendar entries from the store.
|
||||
func (s *Service) GetTrackCalendar(ctx context.Context) ([]TrackCalendarEntry, error) {
|
||||
if s.store == nil {
|
||||
return nil, ErrStoreMissing
|
||||
}
|
||||
return s.store.GetTrackCalendar(ctx)
|
||||
}
|
||||
|
||||
// CreateTrackCalendar creates a new calendar entry.
|
||||
func (s *Service) CreateTrackCalendar(ctx context.Context, trackID string, startAt, endAt time.Time) (TrackCalendarEntry, error) {
|
||||
if s.store == nil {
|
||||
return TrackCalendarEntry{}, ErrStoreMissing
|
||||
}
|
||||
|
||||
s.mu.RLock()
|
||||
_, trackExists := s.tracks[TrackID(trackID)]
|
||||
s.mu.RUnlock()
|
||||
if !trackExists {
|
||||
return TrackCalendarEntry{}, fmt.Errorf("%w: track %s does not exist", ErrNotFound, trackID)
|
||||
}
|
||||
|
||||
if startAt.After(endAt) || startAt.Equal(endAt) {
|
||||
return TrackCalendarEntry{}, fmt.Errorf("%w: start time must be before end time", ErrInvalidInput)
|
||||
}
|
||||
|
||||
entry := TrackCalendarEntry{
|
||||
TrackID: trackID,
|
||||
StartAt: startAt,
|
||||
EndAt: endAt,
|
||||
}
|
||||
return s.store.CreateTrackCalendar(ctx, entry)
|
||||
}
|
||||
|
||||
// DeleteTrackCalendar deletes a calendar entry.
|
||||
func (s *Service) DeleteTrackCalendar(ctx context.Context, id int) error {
|
||||
if s.store == nil {
|
||||
return ErrStoreMissing
|
||||
}
|
||||
return s.store.DeleteTrackCalendar(ctx, id)
|
||||
}
|
||||
Reference in New Issue
Block a user