Skip to content

Commit 93ff952

Browse files
authored
Merge pull request #10829 from snipe/features/add_statuslabel_filter_by_type_in_api
Added filter by status_type in StatusLabels API index endpoint
2 parents 40a9470 + 89ddbdd commit 93ff952

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

app/Http/Controllers/Api/StatuslabelsController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ public function index(Request $request)
3030
$statuslabels = $statuslabels->TextSearch($request->input('search'));
3131
}
3232

33+
34+
// if a status_type is passed, filter by that
35+
if ($request->filled('status_type')) {
36+
if (strtolower($request->input('status_type'))== 'pending') {
37+
$statuslabels = $statuslabels->Pending();
38+
} elseif (strtolower($request->input('status_type'))== 'archived') {
39+
$statuslabels = $statuslabels->Archived();
40+
} elseif (strtolower($request->input('status_type'))== 'deployable') {
41+
$statuslabels = $statuslabels->Deployable();
42+
} elseif (strtolower($request->input('status_type'))== 'undeployable') {
43+
$statuslabels = $statuslabels->Undeployable();
44+
}
45+
}
46+
3347
// Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which
3448
// case we override with the actual count, so we should return 0 items.
3549
$offset = (($statuslabels) && ($request->get('offset') > $statuslabels->count())) ? $statuslabels->count() : $request->get('offset', 0);

app/Models/Statuslabel.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ public function scopeDeployable()
120120
->where('deployable', '=', 1);
121121
}
122122

123+
/**
124+
* Query builder scope for undeployable status types
125+
*
126+
* @return \Illuminate\Database\Query\Builder Modified query builder
127+
*/
128+
public function scopeUndeployable()
129+
{
130+
return $this->where('pending', '=', 0)
131+
->where('archived', '=', 0)
132+
->where('deployable', '=', 0);
133+
}
134+
123135
/**
124136
* Helper function to determine type attributes
125137
*

0 commit comments

Comments
 (0)