Files
acc-server-manager/local/service/leaderboard.go
Fran Jurmanović cf7473b373
Some checks failed
Release and Deploy / build (push) Failing after 6m58s
Release and Deploy / deploy (push) Has been skipped
update models to use uuid referencing
2026-03-01 16:46:06 +01:00

38 lines
969 B
Go

package service
import (
"acc-server-manager/local/model"
"acc-server-manager/local/repository"
"context"
"fmt"
"github.com/google/uuid"
)
type LeaderboardService struct {
repo *repository.LeaderboardRepository
}
func NewLeaderboardService(repo *repository.LeaderboardRepository) *LeaderboardService {
return &LeaderboardService{repo: repo}
}
// Get returns the leaderboard for a server.
func (s *LeaderboardService) Get(ctx context.Context, serverID uuid.UUID) (*model.Leaderboard, error) {
return s.repo.GetOrCreateByServerID(ctx, serverID)
}
// Update replaces the leaderboard for a server.
func (s *LeaderboardService) Update(ctx context.Context, serverID uuid.UUID, lb *model.Leaderboard) (*model.Leaderboard, error) {
if lb == nil {
return nil, fmt.Errorf("input is required")
}
for i := range lb.Drivers {
lb.Drivers[i].Position = i
}
for i := range lb.Races {
lb.Races[i].Position = i
}
return s.repo.FullReplace(ctx, serverID, lb)
}