Skip to content

Commit

Permalink
Merge pull request #10829 from snipe/features/add_statuslabel_filter_…
Browse files Browse the repository at this point in the history
…by_type_in_api

Added filter by status_type in StatusLabels API index endpoint
  • Loading branch information
snipe authored Mar 16, 2022
2 parents 40a9470 + 89ddbdd commit 93ff952
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/Http/Controllers/Api/StatuslabelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ public function index(Request $request)
$statuslabels = $statuslabels->TextSearch($request->input('search'));
}


// if a status_type is passed, filter by that
if ($request->filled('status_type')) {
if (strtolower($request->input('status_type'))== 'pending') {
$statuslabels = $statuslabels->Pending();
} elseif (strtolower($request->input('status_type'))== 'archived') {
$statuslabels = $statuslabels->Archived();
} elseif (strtolower($request->input('status_type'))== 'deployable') {
$statuslabels = $statuslabels->Deployable();
} elseif (strtolower($request->input('status_type'))== 'undeployable') {
$statuslabels = $statuslabels->Undeployable();
}
}

// Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which
// case we override with the actual count, so we should return 0 items.
$offset = (($statuslabels) && ($request->get('offset') > $statuslabels->count())) ? $statuslabels->count() : $request->get('offset', 0);
Expand Down
12 changes: 12 additions & 0 deletions app/Models/Statuslabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ public function scopeDeployable()
->where('deployable', '=', 1);
}

/**
* Query builder scope for undeployable status types
*
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeUndeployable()
{
return $this->where('pending', '=', 0)
->where('archived', '=', 0)
->where('deployable', '=', 0);
}

/**
* Helper function to determine type attributes
*
Expand Down

0 comments on commit 93ff952

Please sign in to comment.