feat(api): add tag filtering on the applications list endpoint (#7360)
This commit is contained in:
parent
2f5e879b73
commit
31ba241d97
3 changed files with 43 additions and 7 deletions
|
|
@ -64,6 +64,17 @@ private function removeSensitiveData($application)
|
||||||
['bearerAuth' => []],
|
['bearerAuth' => []],
|
||||||
],
|
],
|
||||||
tags: ['Applications'],
|
tags: ['Applications'],
|
||||||
|
parameters: [
|
||||||
|
new OA\Parameter(
|
||||||
|
name: 'tag',
|
||||||
|
in: 'query',
|
||||||
|
description: 'Filter applications by tag name.',
|
||||||
|
required: false,
|
||||||
|
schema: new OA\Schema(
|
||||||
|
type: 'string',
|
||||||
|
)
|
||||||
|
),
|
||||||
|
],
|
||||||
responses: [
|
responses: [
|
||||||
new OA\Response(
|
new OA\Response(
|
||||||
response: 200,
|
response: 200,
|
||||||
|
|
@ -94,13 +105,19 @@ public function applications(Request $request)
|
||||||
if (is_null($teamId)) {
|
if (is_null($teamId)) {
|
||||||
return invalidTokenResponse();
|
return invalidTokenResponse();
|
||||||
}
|
}
|
||||||
$projects = Project::where('team_id', $teamId)->get();
|
|
||||||
$applications = collect();
|
$tagName = $request->query('tag');
|
||||||
$applications->push($projects->pluck('applications')->flatten());
|
|
||||||
$applications = $applications->flatten();
|
$applications = Application::ownedByCurrentTeamAPI($teamId)
|
||||||
$applications = $applications->map(function ($application) {
|
->when($tagName, function ($query, $tagName) {
|
||||||
return $this->removeSensitiveData($application);
|
$query->whereHas('tags', function ($query) use ($tagName) {
|
||||||
});
|
$query->where('name', $tagName);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
->get()
|
||||||
|
->map(function ($application) {
|
||||||
|
return $this->removeSensitiveData($application);
|
||||||
|
});
|
||||||
|
|
||||||
return response()->json($applications);
|
return response()->json($applications);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
openapi.json
11
openapi.json
|
|
@ -19,6 +19,17 @@
|
||||||
"summary": "List",
|
"summary": "List",
|
||||||
"description": "List all applications.",
|
"description": "List all applications.",
|
||||||
"operationId": "list-applications",
|
"operationId": "list-applications",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "tag",
|
||||||
|
"in": "query",
|
||||||
|
"description": "Filter applications by tag name.",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "Get all applications.",
|
"description": "Get all applications.",
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,14 @@ paths:
|
||||||
summary: List
|
summary: List
|
||||||
description: 'List all applications.'
|
description: 'List all applications.'
|
||||||
operationId: list-applications
|
operationId: list-applications
|
||||||
|
parameters:
|
||||||
|
-
|
||||||
|
name: tag
|
||||||
|
in: query
|
||||||
|
description: 'Filter applications by tag name.'
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: 'Get all applications.'
|
description: 'Get all applications.'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue