Extract searchEvents() to EventIndexService, reduce duplication across controllers
- Add searchEvents() method: Meilisearch search with DB fallback - Use in HomeController, AdminController, AccountController (removes ~45 duplicated lines) - Add assets/vendor/ to ESLint ignores - Update EventIndexServiceTest for new constructor Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,6 @@ use App\Entity\Payout;
|
||||
use App\Entity\User;
|
||||
use App\Service\EventIndexService;
|
||||
use App\Service\MailerService;
|
||||
use App\Service\MeilisearchService;
|
||||
use App\Service\PayoutPdfService;
|
||||
use App\Service\StripeService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
@@ -26,7 +25,7 @@ class AccountController extends AbstractController
|
||||
private const BREADCRUMB_ACCOUNT = ['name' => 'Mon compte', 'url' => '/mon-compte'];
|
||||
|
||||
#[Route('/mon-compte', name: 'app_account')]
|
||||
public function index(Request $request, StripeService $stripeService, EntityManagerInterface $em, PaginatorInterface $paginator, MeilisearchService $meilisearch): Response
|
||||
public function index(Request $request, StripeService $stripeService, EntityManagerInterface $em, PaginatorInterface $paginator, EventIndexService $eventIndex): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
@@ -58,25 +57,7 @@ class AccountController extends AbstractController
|
||||
['createdAt' => 'DESC'],
|
||||
);
|
||||
$searchQuery = $request->query->getString('q', '');
|
||||
if ('' !== $searchQuery) {
|
||||
try {
|
||||
$searchResults = $meilisearch->search('event_'.$user->getId(), $searchQuery);
|
||||
$eventIds = array_map(fn (array $hit) => $hit['id'], $searchResults['hits'] ?? []);
|
||||
$eventsQuery = $eventIds
|
||||
? $em->getRepository(Event::class)->findBy(['id' => $eventIds])
|
||||
: [];
|
||||
} catch (\Throwable) {
|
||||
$eventsQuery = $em->getRepository(Event::class)->findBy(
|
||||
['account' => $user],
|
||||
['startAt' => 'ASC'],
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$eventsQuery = $em->getRepository(Event::class)->findBy(
|
||||
['account' => $user],
|
||||
['startAt' => 'ASC'],
|
||||
);
|
||||
}
|
||||
$eventsQuery = $eventIndex->searchEvents('event_'.$user->getId(), $searchQuery, ['account' => $user]);
|
||||
$events = $paginator->paginate($eventsQuery, $request->query->getInt('page', 1), 10);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user