Files
KanbanGit/app/Http/Controllers/Api/ProjectTicketLinkController.php
T
Twyco 3ec59ef367
CI/CD / preconditions (pull_request) Successful in 1s
CI/CD / test_and_check_app (pull_request) Failing after 59s
CI/CD / Publish immutable image (pull_request) Skipped
feat: support both ticket link directions (KAN-12)
2026-10-01 08:13:54 +02:00

69 lines
2.1 KiB
PHP

<?php
namespace App\Http\Controllers\Api;
use App\Actions\Permissions\PermissionService;
use App\Actions\Tickets\DeleteProjectTicketLink;
use App\Actions\Tickets\StoreProjectTicketLink;
use App\Enums\Permission;
use App\Http\Requests\StoreTicketLinkRequest;
use App\Http\Resources\TicketLinkResource;
use App\Models\Project;
use App\Models\Ticket;
use App\Models\TicketLink;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ProjectTicketLinkController extends ApiController
{
public function __construct(
private readonly DeleteProjectTicketLink $deleteProjectTicketLink,
private readonly PermissionService $permissionService,
private readonly StoreProjectTicketLink $storeProjectTicketLink,
) {}
public function store(
StoreTicketLinkRequest $request,
Project $project,
Ticket $ticket,
): JsonResponse {
$user = $this->authenticatedUser($request);
abort_unless(
$this->permissionService->allows($user, Permission::ProjectWrite, $project),
403,
);
$ticketLink = $this->storeProjectTicketLink->handle($project, $ticket, $user, $request->validated());
$ticketLink->setAttribute('current_ticket_id', $ticket->id);
$label = $ticketLink->ticketLinkType->labelForSource($ticketLink->source_ticket_id === $ticket->id);
return TicketLinkResource::make($ticketLink->load(['sourceTicket', 'targetTicket', 'ticketLinkType']))
->additional([
'meta' => [
'message' => "{$label} link was saved.",
],
])
->response()
->setStatusCode(201);
}
public function destroy(
Request $request,
Project $project,
Ticket $ticket,
TicketLink $ticketLink,
): JsonResponse {
$user = $this->authenticatedUser($request);
abort_unless(
$this->permissionService->allows($user, Permission::ProjectWrite, $project),
403,
);
$this->deleteProjectTicketLink->handle($ticket, $ticketLink, $user);
return response()->json(null, 204);
}
}