From 2a03b452d3d0fc90f5708470ff1548dc92928e02 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 7 Mar 2024 12:01:21 +0100 Subject: [PATCH] feat: team api endpoint --- app/Http/Controllers/Api/Team.php | 64 +++++++++++++++++++++++++++++++ routes/api.php | 8 ++++ 2 files changed, 72 insertions(+) create mode 100644 app/Http/Controllers/Api/Team.php diff --git a/app/Http/Controllers/Api/Team.php b/app/Http/Controllers/Api/Team.php new file mode 100644 index 000000000..d99ea8ea7 --- /dev/null +++ b/app/Http/Controllers/Api/Team.php @@ -0,0 +1,64 @@ +json(['error' => 'Invalid token.', 'docs' => 'https://coolify.io/docs/api/authentication'], 400); + } + $teams = auth()->user()->teams; + return response()->json($teams); + } + public function team_by_id(Request $request) + { + $id = $request->id; + $teamId = get_team_id_from_token(); + if (is_null($teamId)) { + return response()->json(['error' => 'Invalid token.', 'docs' => 'https://coolify.io/docs/api/authentication'], 400); + } + $teams = auth()->user()->teams; + $team = $teams->where('id', $id)->first(); + if (is_null($team)) { + return response()->json(['error' => 'Team not found.'], 404); + } + return response()->json($team); + } + public function members_by_id(Request $request) + { + $id = $request->id; + $teamId = get_team_id_from_token(); + if (is_null($teamId)) { + return response()->json(['error' => 'Invalid token.', 'docs' => 'https://coolify.io/docs/api/authentication'], 400); + } + $teams = auth()->user()->teams; + $team = $teams->where('id', $id)->first(); + if (is_null($team)) { + return response()->json(['error' => 'Team not found.'], 404); + } + return response()->json($team->members); + } + public function current_team(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); + } + $team = auth()->user()->currentTeam(); + return response()->json($team); + } + public function current_team_members(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); + } + $team = auth()->user()->currentTeam(); + return response()->json($team->members); + } +} diff --git a/routes/api.php b/routes/api.php index ae60e5b7b..b27d1fb28 100644 --- a/routes/api.php +++ b/routes/api.php @@ -5,6 +5,7 @@ use App\Http\Controllers\Api\Project; use App\Http\Controllers\Api\Resources; use App\Http\Controllers\Api\Server; +use App\Http\Controllers\Api\Team; use Illuminate\Http\Request; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Route; @@ -35,6 +36,13 @@ Route::get('/server/{uuid}', [Server::class, 'server_by_uuid']); Route::get('/resources', [Resources::class, 'resources']); Route::get('/domains', [Domains::class, 'domains']); + Route::get('/teams', [Team::class, 'teams']); + Route::get('/team/current', [Team::class, 'current_team']); + Route::get('/team/current/members', [Team::class, 'current_team_members']); + Route::get('/team/{id}', [Team::class, 'team_by_id']); + Route::get('/team/{id}/members', [Team::class, 'members_by_id']); + + //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']);