|
|
|
|
@ -5,35 +5,9 @@ namespace App\Http\Controllers\Api;
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Models\Competition;
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
|
|
|
|
|
|
class PublicCompetitionController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function active(): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
$query = Competition::query();
|
|
|
|
|
if (Schema::hasColumn('competitions', 'published')) {
|
|
|
|
|
$query->where('published', true);
|
|
|
|
|
}
|
|
|
|
|
if (Schema::hasColumn('competitions', 'status')) {
|
|
|
|
|
$query->whereIn('status', ['published', 'signup_open']);
|
|
|
|
|
}
|
|
|
|
|
if (Schema::hasColumn('competitions', 'signup_open_at')) {
|
|
|
|
|
$query->orderByDesc('signup_open_at');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$competition = $query->orderByDesc('id')->firstOrFail();
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'id' => $competition->id,
|
|
|
|
|
'slug' => $competition->slug,
|
|
|
|
|
'name' => $competition->name,
|
|
|
|
|
'status' => $competition->status,
|
|
|
|
|
'signup_open_at' => $competition->signup_open_at?->toIso8601String(),
|
|
|
|
|
'signup_close_at' => $competition->signup_close_at?->toIso8601String(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function showBySlug(string $slug): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
$competition = Competition::query()
|
|
|
|
|
|