Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat(api): add tag filtering on the applications list endpoint (#7360)

Yassine Benh31ba241d973e
diff --git a/app/Http/Controllers/Api/ApplicationsController.php b/app/Http/Controllers/Api/ApplicationsController.php
index b7e9ac6ff3..0ec63562e9 100644
--- a/app/Http/Controllers/Api/ApplicationsController.php
+++ b/app/Http/Controllers/Api/ApplicationsController.php
@@ -64,6 +64,17 @@ class ApplicationsController extends Controller
['bearerAuth' => []],
],
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: [
new OA\Response(
response: 200,
@@ -94,13 +105,19 @@ class ApplicationsController extends Controller
if (is_null($teamId)) {
return invalidTokenResponse();
}
- $projects = Project::where('team_id', $teamId)->get();
- $applications = collect();
- $applications->push($projects->pluck('applications')->flatten());
- $applications = $applications->flatten();
- $applications = $applications->map(function ($application) {
- return $this->removeSensitiveData($application);
- });
+
+ $tagName = $request->query('tag');
+
+ $applications = Application::ownedByCurrentTeamAPI($teamId)
+ ->when($tagName, function ($query, $tagName) {
+ $query->whereHas('tags', function ($query) use ($tagName) {
+ $query->where('name', $tagName);
+ });
+ })
+ ->get()
+ ->map(function ($application) {
+ return $this->removeSensitiveData($application);
+ });
return response()->json($applications);
}
diff --git a/openapi.json b/openapi.json
index 9bbae8154c..5a2465a104 100644
--- a/openapi.json
+++ b/openapi.json
@@ -19,6 +19,17 @@
"summary": "List",
"description": "List all applications.",
"operationId": "list-applications",
+ "parameters": [
+ {
+ "name": "tag",
+ "in": "query",
+ "description": "Filter applications by tag name.",
+ "required": false,
+ "schema": {
+ "type": "string"
+ }
+ }
+ ],
"responses": {
"200": {
"description": "Get all applications.",
diff --git a/openapi.yaml b/openapi.yaml
index 4a68857fbc..28aba508fa 100644
--- a/openapi.yaml
+++ b/openapi.yaml
@@ -14,6 +14,14 @@ paths:
summary: List
description: 'List all applications.'
operationId: list-applications
+ parameters:
+ -
+ name: tag
+ in: query
+ description: 'Filter applications by tag name.'
+ required: false
+ schema:
+ type: string
responses:
'200':
description: 'Get all applications.'