feat: resources api endpoint
This commit is contained in:
parent
5e2afd4b4d
commit
c7693d0ec3
30
app/Http/Controllers/Api/Resources.php
Normal file
30
app/Http/Controllers/Api/Resources.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Project;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Resources extends Controller
|
||||
{
|
||||
public function resources(Request $request)
|
||||
{
|
||||
$teamId = get_team_id_from_token();
|
||||
if (is_null($teamId)) {
|
||||
return response()->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);
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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 () {
|
||||
|
Loading…
Reference in New Issue
Block a user