Add leaderboard route with participants, and configure Shell brand colors in Tailwind

This commit is contained in:
ut-masekela
2026-03-25 01:27:18 +02:00
parent a88504357d
commit a63ea60860
10 changed files with 584 additions and 3 deletions

View File

@@ -0,0 +1,57 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Participant extends Model
{
use HasFactory;
protected $fillable = [
'name',
'car_number',
'time_ms',
'status',
];
protected $casts = [
'car_number' => 'integer',
'time_ms' => 'integer',
];
/**
* Format time_ms as mm:ss.ms (e.g., 01:23.456)
*/
public function getFormattedTimeAttribute(): ?string
{
if ($this->time_ms === null) {
return null;
}
$totalMs = $this->time_ms;
$minutes = floor($totalMs / 60000);
$seconds = floor(($totalMs % 60000) / 1000);
$milliseconds = $totalMs % 1000;
return sprintf('%02d:%02d.%03d', $minutes, $seconds, $milliseconds);
}
/**
* Scope to get ranked participants (fastest first, null times last)
*/
public function scopeRanked($query)
{
return $query->orderByRaw('CASE WHEN time_ms IS NULL THEN 1 ELSE 0 END')
->orderBy('time_ms', 'asc');
}
/**
* Scope to get only completed participants
*/
public function scopeCompleted($query)
{
return $query->where('status', 'completed');
}
}