diff --git a/app/Http/Controllers/Api/StatsController.php b/app/Http/Controllers/Api/StatsController.php new file mode 100644 index 000000000..db14d0466 --- /dev/null +++ b/app/Http/Controllers/Api/StatsController.php @@ -0,0 +1,32 @@ +count(); + $response['flight_time'] = Pirep::where($where)->count(); + + foreach ($avgStats as $static) { + $response['average_'.$static] = Pirep::where($where)->avg($static); + } + + $response['balance'] = Auth::user()->journal->balance->getValue() ?? 0; + return new Stats((object) $response); + } +} diff --git a/app/Http/Resources/Stats.php b/app/Http/Resources/Stats.php new file mode 100644 index 000000000..4671f821b --- /dev/null +++ b/app/Http/Resources/Stats.php @@ -0,0 +1,24 @@ + $this->flights, + 'total_time' => $this->flight_time, + 'average_time' => $this->average_flight_time, + 'average_score' => number_format($this->average_score), + 'balance' => $this->balance, + 'average_fuel' => number_format($this->average_fuel_used / 2.20462262185).' Kg', + 'average_landing' => number_format($this->average_landing_rate), + ]; + } +} diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index fe214cc6f..3a79d73aa 100755 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -660,6 +660,7 @@ private function mapApiRoutes() // This is the info of the user whose token is in use Route::get('user', 'UserController@index'); + Route::get('user/stats', 'StatsController@index'); Route::get('user/fleet', 'UserController@fleet'); Route::get('user/pireps', 'UserController@pireps');