WIP: Implement application process

This commit is contained in:
Björn Fromme
2023-10-09 16:59:35 +02:00
parent abced8c924
commit 3a458df94f
17 changed files with 441 additions and 219 deletions
@@ -0,0 +1,57 @@
<?php
namespace App\Controller\Teamer\Application;
use App\Entity\Application;
use App\Entity\Assignment;
use App\Entity\User;
use App\Form\TeamerApplicationType;
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 CreateController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly LoggerInterface $logger
) {
}
#[Route('/teamer/apply/{uuid}', name: 'app_teamer_application_create')]
#[IsGranted('ROLE_TEAMER')]
#[IsGranted('APPLY', subject: 'assignment')]
public function index(Assignment $assignment, Request $request): Response
{
/** @var User $user */
$user = $this->getUser();
$teamer = $user->getTeamer();
$application = new Application($assignment, $teamer);
$form = $this->createForm(TeamerApplicationType::class, $application);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->entityManager->persist($application);
$this->entityManager->flush();
$this->addFlash('success', 'Deine Bewerbung wurde entgegengenommen');
$this->logger->info('Create application', [
'teamer' => $teamer->getUuid(),
'application' => $application->getUuid(),
]);
return $this->redirectToRoute('app_teamer_index');
}
return $this->render('teamer/application/create.html.twig', [
'assignment' => $assignment,
'teamer' => $teamer,
'form' => $form,
]);
}
}