wip: initial commit
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\DataLoader\PickupDataLoader;
|
||||
use App\BusProNet\DataLoader\TravelDataLoader;
|
||||
use App\BusProNet\Model\File;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\Form\BookingType;
|
||||
use App\Form\Model\BookingData;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
use function Symfony\Component\String\u;
|
||||
|
||||
class BookingController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly TravelDataLoader $travelDataLoader,
|
||||
private readonly PickupDataLoader $pickupDataLoader,
|
||||
private readonly Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/bookings', name: 'app_bookings')]
|
||||
#[IsGranted("ROLE_USER")]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$bpnUser = $request->getSession()->get('bpn_user');
|
||||
|
||||
if (null === $bpnUser) {
|
||||
return $this->security->logout();
|
||||
}
|
||||
|
||||
$bookings = $this->apiClient->getBookings($bpnUser->getEmail(), $bpnUser->getPassword());
|
||||
|
||||
return $this->render('booking/index.html.twig', [
|
||||
'bookings' => $bookings->getItems(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/bookings/{id}/edit', name: 'app_booking_edit', requirements: ['id' => '\d+'])]
|
||||
#[IsGranted("ROLE_USER")]
|
||||
public function edit(int $id, Request $request): Response
|
||||
{
|
||||
$bpnUser = $request->getSession()->get('bpn_user');
|
||||
|
||||
if (null === $bpnUser) {
|
||||
return $this->security->logout();
|
||||
}
|
||||
|
||||
$booking = $this->apiClient->getBooking($bpnUser->getEmail(), $bpnUser->getPassword(), $id);
|
||||
|
||||
//$this->denyAccessUnlessGranted('VIEW', $booking);
|
||||
|
||||
$travelData = $this->travelDataLoader->loadById($booking->travelId);
|
||||
|
||||
if (null === $travelData) {
|
||||
$this->addFlash('error', 'Reisedaten nicht (mehr) verfügbar');
|
||||
|
||||
return $this->redirectToRoute('app_bookings');
|
||||
}
|
||||
|
||||
$mutableFields = $this->apiClient->getMutableFields($booking->travelId);
|
||||
$availabilities = $this->apiClient->getAvailabilities($booking->travelId);
|
||||
|
||||
$this->travelDataLoader->enrichServicesData($travelData, $availabilities);
|
||||
$this->pickupDataLoader->enrichPickupsData($travelData);
|
||||
|
||||
$formData = BookingData::fromBooking($booking);
|
||||
|
||||
$form = $this->createForm(BookingType::class, $formData, [
|
||||
'hx_post' => $this->generateUrl('app_booking_edit', ['id' => $id]),
|
||||
'hx_target' => '#app',
|
||||
'hx_swap' => 'innerHTML show:top',
|
||||
'attr' => ['novalidate' => 'novalidate'],
|
||||
'travel' => $travelData,
|
||||
'mutable_fields' => $mutableFields,
|
||||
]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->apiClient->updateBooking($bpnUser->getEmail(), $bpnUser->getPassword(), $formData);
|
||||
}
|
||||
|
||||
return $this->render('booking/edit.html.twig', [
|
||||
'booking' => $booking,
|
||||
'travelData' => $travelData,
|
||||
'mutableFields' => $mutableFields,
|
||||
'availabilities' => $availabilities,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/bookings/{id}/documents', name: 'app_booking_documents', requirements: ['id' => '\d+'])]
|
||||
#[IsGranted("ROLE_USER")]
|
||||
public function documents(int $id, Request $request): Response
|
||||
{
|
||||
$bpnUser = $request->getSession()->get('bpn_user');
|
||||
|
||||
if (null === $bpnUser) {
|
||||
return $this->security->logout();
|
||||
}
|
||||
|
||||
$file = $this
|
||||
->apiClient
|
||||
->getDocuments($bpnUser->getEmail(), $bpnUser->getPassword(), $id, 'Dokumentdruck')
|
||||
;
|
||||
|
||||
if (null === $file || $file instanceof Notification) {
|
||||
$this->addFlash('error', 'Keine Dokumente vorhanden');
|
||||
|
||||
return $this->redirectToRoute('app_bookings');
|
||||
}
|
||||
|
||||
return $this->createDownloadResponse($file);
|
||||
}
|
||||
|
||||
#[Route('/bookings/{id}/confirmation', name: 'app_booking_confirmation', requirements: ['id' => '\d+'])]
|
||||
#[IsGranted("ROLE_USER")]
|
||||
public function confirmation(int $id, Request $request): Response
|
||||
{
|
||||
$bpnUser = $request->getSession()->get('bpn_user');
|
||||
|
||||
if (null === $bpnUser) {
|
||||
return $this->security->logout();
|
||||
}
|
||||
|
||||
$file = $this
|
||||
->apiClient
|
||||
->getDocuments($bpnUser->getEmail(), $bpnUser->getPassword(), $id, 'Vorgangdruck')
|
||||
;
|
||||
|
||||
return $this->createDownloadResponse($file);
|
||||
}
|
||||
|
||||
private function createDownloadResponse(File $file): Response
|
||||
{
|
||||
$filename = u($file->filename)->ascii();
|
||||
|
||||
$response = new Response($file->content);
|
||||
|
||||
$disposition = $response->headers->makeDisposition(
|
||||
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
|
||||
$filename,
|
||||
md5($filename)
|
||||
);
|
||||
|
||||
$response->headers->set('Content-Disposition', $disposition);
|
||||
$response->headers->set('Content-Type', $file->mimeType);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\Form\PersonalDataType;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class PersonalDataController extends AbstractController
|
||||
{
|
||||
public function __construct(private readonly ApiClient $apiClient, private readonly Security $security)
|
||||
{}
|
||||
|
||||
#[Route('/personal-data', name: 'app_personal_data')]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$bpnUser = $request->getSession()->get('bpn_user');
|
||||
|
||||
if (null === $bpnUser) {
|
||||
return $this->security->logout();
|
||||
}
|
||||
|
||||
$personalData = $this
|
||||
->apiClient
|
||||
->getPersonalData($bpnUser->getEmail(), $bpnUser->getPassword())
|
||||
;
|
||||
|
||||
$form = $this->createForm(PersonalDataType::class, $personalData, [
|
||||
'attr' => ['novalidate' => 'novalidate'],
|
||||
'hx_post' => $this->generateUrl('app_personal_data'),
|
||||
'hx_target' => '#app',
|
||||
]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
try {
|
||||
$this->apiClient->updatePersonalData($bpnUser->getEmail(), $bpnUser->getPassword(), $personalData);
|
||||
$this->addFlash('success', 'Personal data updated.');
|
||||
} catch (ApiClientException $e) {
|
||||
$this->addFlash('error', $e->getMessage());
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('app_personal_data');
|
||||
}
|
||||
|
||||
return $this->render('personal_data/index.html.twig', [
|
||||
'personalData' => $personalData,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
|
||||
class SecurityController extends AbstractController
|
||||
{
|
||||
#[Route('/', name: 'app_login')]
|
||||
#[IsGranted('PUBLIC_ACCESS')]
|
||||
public function login(AuthenticationUtils $authenticationUtils): Response
|
||||
{
|
||||
if (null !== $this->getUser()) {
|
||||
return $this->redirectToRoute('app_personal_data');
|
||||
}
|
||||
|
||||
$error = $authenticationUtils->getLastAuthenticationError();
|
||||
$lastUsername = $authenticationUtils->getLastUsername();
|
||||
|
||||
return $this->render('security/login.html.twig', [
|
||||
'last_username' => $lastUsername,
|
||||
'error' => $error,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/logout', name: 'app_logout')]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function logout(): void
|
||||
{}
|
||||
}
|
||||
Reference in New Issue
Block a user