Feat: Streamline and extend logging

This commit is contained in:
Björn Fromme
2023-10-21 10:01:25 +02:00
parent 124307616c
commit 5ac8ea7491
52 changed files with 261 additions and 74 deletions
@@ -3,7 +3,9 @@
namespace App\Controller\Teamer\Disposition;
use App\Entity\Disposition;
use App\Entity\User;
use App\Service\Common\IcsGenerator;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Component\HttpFoundation\Response;
@@ -12,13 +14,21 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
class IcsController extends AbstractController
{
public function __construct(private readonly LoggerInterface $logger)
{}
#[Route('/teamer/disposition/ics/{uuid}', name: 'app_teamer_disposition_ics')]
#[IsGranted('ROLE_TEAMER')]
#[IsGranted('VIEW', subject: 'disposition')]
public function index(Disposition $disposition): Response
{
/** @var User $user */
$user = $this->getUser();
$teamer = $user->getTeamer();
$assignment = $disposition->getAssignment();
$destination = $assignment->getDestination();
$jobProfile = $assignment->getJobProfile();
$ics = (new IcsGenerator($disposition))->generate();
$filename = sprintf(
'Einteilung_%s_%s-%s.ics',
@@ -26,12 +36,19 @@ class IcsController extends AbstractController
$assignment->getEffectivePeriod()->start->format('d.m.Y'),
$assignment->getEffectivePeriod()->end->format('d.m.Y')
);
$disposition = HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_INLINE, $filename, md5($filename));
$contentDisposition = HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_INLINE, $filename, md5($filename));
$response = new Response($ics);
$response->setPrivate();
$response->headers->set('Content-type', 'text/calendar');
$response->headers->set('Content-Disposition', $disposition);
$response->headers->set('Content-Disposition', $contentDisposition);
$this->logger->info('Create ICS file', [
'assignment_id' => $assignment->getId(),
'destination' => (string) $destination,
'teamer_id' => $teamer->getId(),
'teamer_name' => (string) $teamer,
]);
return $response;
}