From e78902b7ab0d5cf28810c6c79d32f9e48d7e1643 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 13 Dec 2024 16:39:30 +0100 Subject: [PATCH] feat(api): added list of active areas --- app/Http/Controllers/API/UserController.php | 13 ++++++++++--- docs/api.md | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/API/UserController.php b/app/Http/Controllers/API/UserController.php index e42247e6..77820312 100644 --- a/app/Http/Controllers/API/UserController.php +++ b/app/Http/Controllers/API/UserController.php @@ -33,6 +33,7 @@ public function index(Request $request) $paramIncludeName = (isset($parameters['include']) && in_array('name', $parameters['include'])) ?? false; $paramIncludeEmail = (isset($parameters['include']) && in_array('email', $parameters['include'])) ?? false; $paramIncludeDivisions = (isset($parameters['include']) && in_array('divisions', $parameters['include'])) ?? false; + $paramIncludeActiveAreas = (isset($parameters['include']) && in_array('activeAreas', $parameters['include'])) ?? false; $paramIncludeEndorsements = (isset($parameters['include']) && in_array('endorsements', $parameters['include'])) ?? false; $paramIncludeRoles = (isset($parameters['include']) && in_array('roles', $parameters['include'])) ?? false; $paramIncludeTraining = (isset($parameters['include']) && in_array('training', $parameters['include'])) ?? false; @@ -136,7 +137,7 @@ public function index(Request $request) // // Return the final result // - $returnUsers = $this->mapUsers($returnUsers, $paramIncludeName, $paramIncludeEmail, $paramIncludeDivisions, $paramIncludeEndorsements, $paramIncludeRoles, $paramIncludeTraining); + $returnUsers = $this->mapUsers($returnUsers, $paramIncludeName, $paramIncludeEmail, $paramIncludeDivisions, $paramIncludeActiveAreas, $paramIncludeEndorsements, $paramIncludeRoles, $paramIncludeTraining); $returnUsers = $returnUsers->sortBy('id')->values(); return response()->json(['data' => $returnUsers], 200); @@ -147,9 +148,9 @@ public function index(Request $request) * * @return Collection */ - private function mapUsers(Collection $users, bool $includeName, bool $includeEmail, bool $includeDivisions, bool $includeEndorsements, bool $includeRoles, bool $includeTraining) + private function mapUsers(Collection $users, bool $includeName, bool $includeEmail, bool $includeDivisions, bool $includeActiveAreas, bool $includeEndorsements, bool $includeRoles, bool $includeTraining) { - return $users->map(function ($user) use ($includeName, $includeEmail, $includeDivisions, $includeEndorsements, $includeRoles, $includeTraining) { + return $users->map(function ($user) use ($includeName, $includeEmail, $includeDivisions, $includeActiveAreas, $includeEndorsements, $includeRoles, $includeTraining) { $returnData = []; @@ -162,6 +163,12 @@ private function mapUsers(Collection $users, bool $includeName, bool $includeEma ($includeDivisions) ? $returnData['division'] = $user->division : null; ($includeDivisions) ? $returnData['subdivision'] = $user->subdivision : null; $returnData['atc_active'] = $user->isAtcActive(); + ($includeActiveAreas) ? $returnData['atc_active_areas'] = + $user->atc_active_areas = Area::all()->mapWithKeys(function ($area) use ($user) { + $activity = $user->atcActivity->firstWhere('area_id', $area->id); + + return [strtolower($area->name) => $activity ? $activity->atc_active : false]; + }) : null; ($includeEndorsements) ? $returnData['endorsements'] = $user->endorsements : null; ($includeRoles) ? $returnData['roles'] = $user->roles : null; ($includeTraining) ? $returnData['training'] = $user->training : null; diff --git a/docs/api.md b/docs/api.md index f3fd21a8..7e6f06d5 100644 --- a/docs/api.md +++ b/docs/api.md @@ -29,7 +29,7 @@ Parameters to add additional fields to the result | name | Include user's full name | | email | Include user's email | | divisions | Include user's region, division and subdivision | - +| activeAreas | Include user's ATC active status per area | #### Example return with all parameters