collection-crud/src/Controller/PreviouslyOwnedGpuControlle...

88 lines
2.6 KiB
PHP

<?php declare(strict_types=1);
namespace App\Controller;
use App\Entity\PreviouslyOwnedGpu;
use App\Form\PreviouslyOwnedGpuType;
use Doctrine\ORM\{EntityManagerInterface, ORMInvalidArgumentException};
use LogicException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response};
use Symfony\Component\Routing\Annotation\Route;
use UnexpectedValueException;
/**
* PreviouslyownedGpu controller.
*/
#[Route(path: 'previously-owned-gpu')]
class PreviouslyOwnedGpuController extends AbstractController {
use FormControllerBase;
protected const ENTITY = PreviouslyOwnedGpu::class;
protected const TEMPLATE_PATH = 'previouslyownedgpu/';
protected const ROUTE_PREFIX = 'previously-owned-gpu_';
protected const FORM = PreviouslyOwnedGpuType::class;
public function __construct(private readonly EntityManagerInterface $entityManager)
{
}
/**
* Lists all previouslyOwnedGpu entities.
*
* @throws UnexpectedValueException
*/
#[Route(path: '/', name: 'previously-owned-gpu_index', methods: ['GET'])]
public function indexAction(): Response
{
$items = $this->entityManager->getRepository(self::ENTITY)->findAll();
return $this->render('previouslyownedgpu/index.html.twig', [
'gpus' => $items,
]);
}
/**
* Finds and displays a previouslyOwnedGpu entity.
*/
#[Route(path: '/{id}', name: 'previously-owned-gpu_show', methods: ['GET'])]
public function showAction(PreviouslyOwnedGpu $previouslyOwnedGpu): Response
{
return $this->itemView($previouslyOwnedGpu, 'previouslyOwnedGpu');
}
/**
* Displays a form to edit an existing previouslyOwnedGpu entity.
*
* @throws LogicException
*/
#[Route(path: '/{id}/edit', name: 'previously-owned-gpu_edit', methods: ['GET', 'POST'])]
public function editAction(Request $request, PreviouslyOwnedGpu $previouslyOwnedGpu): RedirectResponse|Response
{
return $this->itemUpdate($request, $previouslyOwnedGpu, 'previouslyOwnedGpu');
}
/**
* Moves a Gpu to the previouslyOwned table
*
* @throws LogicException
* @throws ORMInvalidArgumentException
*/
#[Route(path: '/{id}/reacquire', name: 'previously-owned-gpu_reacquire', methods: ['POST'])]
public function reacquireAction(Request $request, PreviouslyOwnedGpu $Gpu): RedirectResponse
{
return $this->itemReacquire($request, $Gpu, 'gpu_index');
}
/**
* Creates a form to move
*
* @param PreviouslyOwnedGpu $Gpu The Gpu entity
*/
private function createReacquireForm(PreviouslyOwnedGpu $Gpu): FormInterface
{
return $this->buildForm($Gpu, 'previously-owned-gpu_reacquire', 'POST');
}
}