diff --git a/app/Http/Controllers/Api/Resources.php b/app/Http/Controllers/Api/Resources.php new file mode 100644 index 000000000..a6e25758c --- /dev/null +++ b/app/Http/Controllers/Api/Resources.php @@ -0,0 +1,30 @@ +json(['error' => 'Invalid token.', 'docs' => 'https://coolify.io/docs/api/authentication'], 400); + } + $projects = Project::where('team_id', $teamId)->get(); + $resources = collect(); + $resources->push($projects->pluck('applications')->flatten()); + $resources->push($projects->pluck('services')->flatten()); + $resources->push($projects->pluck('postgresqls')->flatten()); + $resources->push($projects->pluck('redis')->flatten()); + $resources->push($projects->pluck('mongodbs')->flatten()); + $resources->push($projects->pluck('mysqls')->flatten()); + $resources->push($projects->pluck('mariadbs')->flatten()); + $resources = $resources->flatten(); + return response()->json($resources); + } + +} diff --git a/app/Models/Project.php b/app/Models/Project.php index 6416971f6..27ae10778 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -27,7 +27,8 @@ protected static function booted() $project->settings()->delete(); }); } - public function environment_variables() { + public function environment_variables() + { return $this->hasMany(SharedEnvironmentVariable::class); } public function environments() @@ -74,7 +75,8 @@ public function mariadbs() { return $this->hasManyThrough(StandaloneMariadb::class, Environment::class); } - public function resource_count() { + public function resource_count() + { return $this->applications()->count() + $this->postgresqls()->count() + $this->redis()->count() + $this->mongodbs()->count() + $this->mysqls()->count() + $this->mariadbs()->count(); } } diff --git a/routes/api.php b/routes/api.php index a1ddd666e..ae60e5b7b 100644 --- a/routes/api.php +++ b/routes/api.php @@ -3,6 +3,7 @@ use App\Http\Controllers\Api\Deploy; use App\Http\Controllers\Api\Domains; use App\Http\Controllers\Api\Project; +use App\Http\Controllers\Api\Resources; use App\Http\Controllers\Api\Server; use Illuminate\Http\Request; use Illuminate\Support\Facades\Http; @@ -32,10 +33,11 @@ Route::get('/deploy', [Deploy::class, 'deploy']); Route::get('/servers', [Server::class, 'servers']); Route::get('/server/{uuid}', [Server::class, 'server_by_uuid']); - Route::get('/projects', [Project::class, 'projects']); - Route::get('/project/{uuid}', [Project::class, 'project_by_uuid']); - Route::get('/project/{uuid}/{environment_name}', [Project::class, 'environment_details']); + Route::get('/resources', [Resources::class, 'resources']); Route::get('/domains', [Domains::class, 'domains']); + //Route::get('/projects', [Project::class, 'projects']); + //Route::get('/project/{uuid}', [Project::class, 'project_by_uuid']); + //Route::get('/project/{uuid}/{environment_name}', [Project::class, 'environment_details']); }); Route::get('/{any}', function () {