lasthourcloud/app/Http/Controllers/Api/ProjectController.php

55 lines
1.7 KiB
PHP
Raw Normal View History

2024-07-01 14:26:50 +00:00
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Project;
use Illuminate\Http\Request;
class ProjectController extends Controller
{
public function projects(Request $request)
{
$teamId = getTeamIdFromToken();
if (is_null($teamId)) {
return invalidTokenResponse();
}
$projects = Project::whereTeamId($teamId)->select('id', 'name', 'uuid')->get();
2024-07-03 11:13:38 +00:00
return response()->json(serializeApiResponse($projects),
);
2024-07-01 14:26:50 +00:00
}
public function project_by_uuid(Request $request)
{
$teamId = getTeamIdFromToken();
if (is_null($teamId)) {
return invalidTokenResponse();
}
$project = Project::whereTeamId($teamId)->whereUuid(request()->uuid)->first()->load(['environments']);
if (! $project) {
2024-07-03 11:13:38 +00:00
return response()->json(['message' => 'Project not found.'], 404);
2024-07-01 14:26:50 +00:00
}
2024-07-03 11:13:38 +00:00
return response()->json(
serializeApiResponse($project),
);
2024-07-01 14:26:50 +00:00
}
public function environment_details(Request $request)
{
$teamId = getTeamIdFromToken();
if (is_null($teamId)) {
return invalidTokenResponse();
}
$project = Project::whereTeamId($teamId)->whereUuid(request()->uuid)->first();
$environment = $project->environments()->whereName(request()->environment_name)->first();
if (! $environment) {
2024-07-03 11:13:38 +00:00
return response()->json(['message' => 'Environment not found.'], 404);
2024-07-01 14:26:50 +00:00
}
$environment = $environment->load(['applications', 'postgresqls', 'redis', 'mongodbs', 'mysqls', 'mariadbs', 'services']);
2024-07-03 11:13:38 +00:00
return response()->json(serializeApiResponse($environment));
2024-07-01 14:26:50 +00:00
}
}