Skip to content

Commit

Permalink
feat(api): added list of active areas
Browse files Browse the repository at this point in the history
  • Loading branch information
blt950 committed Dec 13, 2024
1 parent 05f7013 commit e78902b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions app/Http/Controllers/API/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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 = [];

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e78902b

Please sign in to comment.