Fix: Add dedicated process for withdrawal of applications by teamer

This commit is contained in:
Björn Fromme
2023-10-21 10:20:24 +02:00
parent e3dc2b22fd
commit 0fce77fbb7
3 changed files with 22 additions and 15 deletions
@@ -0,0 +1,50 @@
<?php
namespace App\Controller\Teamer\Application;
use App\Controller\Traits\ReturnUrlTrait;
use App\Entity\Application;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class WithdrawController extends AbstractController
{
use ReturnUrlTrait;
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly LoggerInterface $logger
) {
}
#[Route('/teamer/application/withdraw/{uuid}', name: 'app_teamer_application_withdraw')]
#[IsGranted('WITHDRAW', subject: 'application')]
public function index(Application $application, Request $request): Response
{
/** @var User $user */
$user = $this->getUser();
$teamer = $user->getTeamer();
$assignment = $application->getAssignment();
$this->entityManager->remove($application);
$this->entityManager->flush();
$this->logger->info('Withdraw application', [
'teamer_id' => $teamer->getId(),
'teamer_name' => (string) $teamer,
'application_id' => $application->getId(),
'assignment_id' => $assignment->getId(),
'destination' => (string) $assignment->getDestination(),
]);
$returnUrl = $this->getReturnUrl($request, 'app_teamer_index');
return $this->redirect($returnUrl);
}
}