Add application API and OpenAPI docs
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Actions\Permissions\PermissionService;
|
||||
use App\Actions\Repositories\BuildProjectRepositorySettingsPayload;
|
||||
use App\Actions\Repositories\DeleteProjectRepositoryConnection;
|
||||
use App\Actions\Repositories\StoreProjectRepositoryConnection;
|
||||
use App\Actions\Repositories\UpdateProjectRepositoryConnection;
|
||||
use App\Enums\Permission;
|
||||
use App\Http\Requests\StoreRepositoryConnectionRequest;
|
||||
use App\Http\Requests\UpdateRepositoryConnectionRequest;
|
||||
use App\Http\Resources\RepositoryConnectionResource;
|
||||
use App\Models\Project;
|
||||
use App\Models\RepositoryConnection;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProjectRepositorySettingsController extends ApiController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly BuildProjectRepositorySettingsPayload $buildProjectRepositorySettingsPayload,
|
||||
private readonly DeleteProjectRepositoryConnection $deleteProjectRepositoryConnection,
|
||||
private readonly PermissionService $permissionService,
|
||||
private readonly StoreProjectRepositoryConnection $storeProjectRepositoryConnection,
|
||||
private readonly UpdateProjectRepositoryConnection $updateProjectRepositoryConnection,
|
||||
) {}
|
||||
|
||||
public function show(Request $request, Project $project): JsonResponse
|
||||
{
|
||||
$user = $this->authenticatedUser($request);
|
||||
|
||||
abort_unless(
|
||||
$this->permissionService->allows($user, Permission::ProjectAdmin, $project),
|
||||
403,
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'data' => $this->buildProjectRepositorySettingsPayload->handle($project, $user),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreRepositoryConnectionRequest $request, Project $project): JsonResponse
|
||||
{
|
||||
$user = $this->authenticatedUser($request);
|
||||
|
||||
abort_unless(
|
||||
$this->permissionService->allows($user, Permission::ProjectAdmin, $project),
|
||||
403,
|
||||
);
|
||||
|
||||
$repositoryConnection = $this->storeProjectRepositoryConnection->handle($project, $user, $request->validated());
|
||||
|
||||
return RepositoryConnectionResource::make($repositoryConnection)
|
||||
->additional([
|
||||
'meta' => [
|
||||
'message' => "{$repositoryConnection->repository_full_name} was linked to {$project->name}.",
|
||||
],
|
||||
])
|
||||
->response()
|
||||
->setStatusCode(201);
|
||||
}
|
||||
|
||||
public function update(
|
||||
UpdateRepositoryConnectionRequest $request,
|
||||
Project $project,
|
||||
RepositoryConnection $repositoryConnection,
|
||||
): JsonResponse {
|
||||
$user = $this->authenticatedUser($request);
|
||||
|
||||
abort_unless(
|
||||
$this->permissionService->allows($user, Permission::ProjectAdmin, $project),
|
||||
403,
|
||||
);
|
||||
|
||||
$repositoryConnection = $this->updateProjectRepositoryConnection->handle(
|
||||
$project,
|
||||
$repositoryConnection,
|
||||
$user,
|
||||
$request->validated(),
|
||||
);
|
||||
|
||||
return RepositoryConnectionResource::make($repositoryConnection)
|
||||
->additional([
|
||||
'meta' => [
|
||||
'message' => "{$repositoryConnection->repository_full_name} connection was updated.",
|
||||
],
|
||||
])
|
||||
->response();
|
||||
}
|
||||
|
||||
public function destroy(Request $request, Project $project, RepositoryConnection $repositoryConnection): JsonResponse
|
||||
{
|
||||
$user = $this->authenticatedUser($request);
|
||||
|
||||
abort_unless(
|
||||
$this->permissionService->allows($user, Permission::ProjectAdmin, $project),
|
||||
403,
|
||||
);
|
||||
|
||||
$this->deleteProjectRepositoryConnection->handle($repositoryConnection);
|
||||
|
||||
return response()->json(null, 204);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user