diff --git a/backend-laravel/app/Http/Controllers/VilleController.php b/backend-laravel/app/Http/Controllers/VilleController.php new file mode 100644 index 0000000..f89f47c --- /dev/null +++ b/backend-laravel/app/Http/Controllers/VilleController.php @@ -0,0 +1,15 @@ + $count )); } + + public static function getCurrentVille() + { + // Get cycle + $cycles = self::get(); + + // If no cycle, generate one + $cycle = $cycles->isEmpty() ? self::generateCycle() : $cycles->first(); + + // Decode shuffledList + $villes_ids = explode(self::$delimiter, $cycle->shuffledList); + + // Get the ville id according to the index of the cycle + $current_ville_id = $villes_ids[$cycle->index]; + + // Get the ville + $ville = Ville::where('id', $current_ville_id)->firstOrFail(); + + // Return it + return $ville; + + } } diff --git a/backend-laravel/routes/api.php b/backend-laravel/routes/api.php index 889937e..47a0fae 100644 --- a/backend-laravel/routes/api.php +++ b/backend-laravel/routes/api.php @@ -3,6 +3,8 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; +use App\Http\Controllers\VilleController; + /* |-------------------------------------------------------------------------- | API Routes @@ -17,3 +19,5 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) { return $request->user(); }); + +Route::get('/ville/today', [VilleController::class, 'today']);