68 lines
2.1 KiB
PHP
68 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);
|
|
|
|
return TicketLinkResource::make($ticketLink->load(['sourceTicket', 'targetTicket', 'ticketLinkType']))
|
|
->additional([
|
|
'meta' => [
|
|
'message' => "{$ticketLink->ticketLinkType->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);
|
|
}
|
|
}
|