Reduce AccountController to 20 methods, remove unused AdminOrdersController constant
- Move export, exportPdf, payoutPdf from AccountController to AccountEventOperationsController (9 -> 12 methods) - Remove getAllowedBilletTypes delegate from AccountController - Update tests to reference AccountEventCatalogController for that method - Remove unused DQL_EXCLUDE_INVITATIONS from AdminOrdersController Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,10 +13,8 @@ use App\Entity\Payout;
|
||||
use App\Entity\User;
|
||||
use App\Service\AuditService;
|
||||
use App\Service\EventIndexService;
|
||||
use App\Service\ExportService;
|
||||
use App\Service\MailerService;
|
||||
use App\Service\OrderIndexService;
|
||||
use App\Service\PayoutPdfService;
|
||||
use App\Service\StripeService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Knp\Component\Pager\PaginatorInterface;
|
||||
@@ -595,73 +593,6 @@ class AccountController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
/** @codeCoverageIgnore Generates PDF with dompdf */
|
||||
#[Route('/mon-compte/payout/{id}/attestation', name: 'app_account_payout_pdf')]
|
||||
public function payoutPdf(Payout $payout, PayoutPdfService $pdfService): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
if ($payout->getOrganizer()->getId() !== $user->getId()) {
|
||||
throw $this->createAccessDeniedException();
|
||||
}
|
||||
|
||||
return new Response($pdfService->generate($payout), 200, [
|
||||
'Content-Type' => self::CONTENT_TYPE_PDF,
|
||||
'Content-Disposition' => 'inline; filename="attestation_'.$payout->getStripePayoutId().self::PDF_SUFFIX,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/mon-compte/export/{year}/{month}', name: 'app_account_export', requirements: ['year' => '\d{4}', 'month' => '\d{1,2}'], methods: ['GET'])]
|
||||
public function export(int $year, int $month, ExportService $exportService): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('ROLE_ORGANIZER');
|
||||
if ($redirect = $this->requireStripeReady()) { // @codeCoverageIgnoreStart
|
||||
return $redirect;
|
||||
} // @codeCoverageIgnoreEnd
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$stats = $exportService->getMonthlyStats($year, $month, $user);
|
||||
$csv = $exportService->generateCsv($stats['orders']);
|
||||
|
||||
$filename = sprintf('export_%04d_%02d.csv', $year, $month);
|
||||
|
||||
return new Response($csv, 200, [
|
||||
'Content-Type' => 'text/csv; charset=utf-8',
|
||||
'Content-Disposition' => 'attachment; filename="'.$filename.'"',
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/mon-compte/export/{year}/{month}/pdf', name: 'app_account_export_pdf', requirements: ['year' => '\d{4}', 'month' => '\d{1,2}'], methods: ['GET'])]
|
||||
public function exportPdf(int $year, int $month, ExportService $exportService): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('ROLE_ORGANIZER');
|
||||
if ($redirect = $this->requireStripeReady()) { // @codeCoverageIgnoreStart
|
||||
return $redirect;
|
||||
} // @codeCoverageIgnoreEnd
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$stats = $exportService->getMonthlyStats($year, $month, $user);
|
||||
$pdf = $exportService->generatePdf($stats, $year, $month, $user);
|
||||
|
||||
$filename = sprintf('recap_%04d_%02d.pdf', $year, $month);
|
||||
|
||||
return new Response($pdf, 200, [
|
||||
'Content-Type' => self::CONTENT_TYPE_PDF,
|
||||
'Content-Disposition' => 'inline; filename="'.$filename.'"',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getAllowedBilletTypes(?string $offer): array
|
||||
{
|
||||
return AccountEventCatalogController::getAllowedBilletTypes($offer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<BilletBuyer> $paidOrders
|
||||
*
|
||||
|
||||
@@ -10,8 +10,12 @@ use App\Entity\BilletBuyerItem;
|
||||
use App\Entity\BilletOrder;
|
||||
use App\Entity\Category;
|
||||
use App\Entity\Event;
|
||||
use App\Entity\Payout;
|
||||
use App\Entity\User;
|
||||
use App\Service\AuditService;
|
||||
use App\Service\BilletOrderService;
|
||||
use App\Service\ExportService;
|
||||
use App\Service\PayoutPdfService;
|
||||
use App\Service\StripeService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@@ -549,4 +553,63 @@ class AccountEventOperationsController extends AbstractController
|
||||
|
||||
return $details;
|
||||
}
|
||||
|
||||
/** @codeCoverageIgnore Generates PDF with dompdf */
|
||||
#[Route('/mon-compte/payout/{id}/attestation', name: 'app_account_payout_pdf')]
|
||||
public function payoutPdf(Payout $payout, PayoutPdfService $pdfService): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
if ($payout->getOrganizer()->getId() !== $user->getId()) {
|
||||
throw $this->createAccessDeniedException();
|
||||
}
|
||||
|
||||
return new Response($pdfService->generate($payout), 200, [
|
||||
'Content-Type' => self::CONTENT_TYPE_PDF,
|
||||
'Content-Disposition' => 'inline; filename="attestation_'.$payout->getStripePayoutId().self::PDF_SUFFIX,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/mon-compte/export/{year}/{month}', name: 'app_account_export', requirements: ['year' => '\d{4}', 'month' => '\d{1,2}'], methods: ['GET'])]
|
||||
public function export(int $year, int $month, ExportService $exportService): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('ROLE_ORGANIZER');
|
||||
if ($redirect = $this->requireStripeReady()) { // @codeCoverageIgnoreStart
|
||||
return $redirect;
|
||||
} // @codeCoverageIgnoreEnd
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$stats = $exportService->getMonthlyStats($year, $month, $user);
|
||||
$csv = $exportService->generateCsv($stats['orders']);
|
||||
|
||||
$filename = sprintf('export_%04d_%02d.csv', $year, $month);
|
||||
|
||||
return new Response($csv, 200, [
|
||||
'Content-Type' => 'text/csv; charset=utf-8',
|
||||
'Content-Disposition' => 'attachment; filename="'.$filename.'"',
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/mon-compte/export/{year}/{month}/pdf', name: 'app_account_export_pdf', requirements: ['year' => '\d{4}', 'month' => '\d{1,2}'], methods: ['GET'])]
|
||||
public function exportPdf(int $year, int $month, ExportService $exportService): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('ROLE_ORGANIZER');
|
||||
if ($redirect = $this->requireStripeReady()) { // @codeCoverageIgnoreStart
|
||||
return $redirect;
|
||||
} // @codeCoverageIgnoreEnd
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$stats = $exportService->getMonthlyStats($year, $month, $user);
|
||||
$pdf = $exportService->generatePdf($stats, $year, $month, $user);
|
||||
|
||||
$filename = sprintf('recap_%04d_%02d.pdf', $year, $month);
|
||||
|
||||
return new Response($pdf, 200, [
|
||||
'Content-Type' => self::CONTENT_TYPE_PDF,
|
||||
'Content-Disposition' => 'inline; filename="'.$filename.'"',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
class AdminOrdersController extends AbstractController
|
||||
{
|
||||
private const DQL_STATUS_PAID = 'o.status = :paid';
|
||||
private const DQL_EXCLUDE_INVITATIONS = 'o.isInvitation = false OR o.isInvitation IS NULL';
|
||||
|
||||
#[Route('/commandes', name: 'app_admin_orders', methods: ['GET'])]
|
||||
public function orders(Request $request, EntityManagerInterface $em, PaginatorInterface $paginator): Response
|
||||
|
||||
@@ -2049,25 +2049,25 @@ class AccountControllerTest extends WebTestCase
|
||||
|
||||
public function testGetAllowedBilletTypesBasic(): void
|
||||
{
|
||||
$types = \App\Controller\AccountController::getAllowedBilletTypes('basic');
|
||||
$types = \App\Controller\AccountEventCatalogController::getAllowedBilletTypes('basic');
|
||||
self::assertSame(['billet', 'reservation_brocante', 'vote'], $types);
|
||||
}
|
||||
|
||||
public function testGetAllowedBilletTypesSurMesure(): void
|
||||
{
|
||||
$types = \App\Controller\AccountController::getAllowedBilletTypes('sur-mesure');
|
||||
$types = \App\Controller\AccountEventCatalogController::getAllowedBilletTypes('sur-mesure');
|
||||
self::assertSame(['billet', 'reservation_brocante', 'vote'], $types);
|
||||
}
|
||||
|
||||
public function testGetAllowedBilletTypesFree(): void
|
||||
{
|
||||
$types = \App\Controller\AccountController::getAllowedBilletTypes('free');
|
||||
$types = \App\Controller\AccountEventCatalogController::getAllowedBilletTypes('free');
|
||||
self::assertSame(['billet'], $types);
|
||||
}
|
||||
|
||||
public function testGetAllowedBilletTypesNull(): void
|
||||
{
|
||||
$types = \App\Controller\AccountController::getAllowedBilletTypes(null);
|
||||
$types = \App\Controller\AccountEventCatalogController::getAllowedBilletTypes(null);
|
||||
self::assertSame(['billet'], $types);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user