|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Frosh\Tools\Controller; |
| 4 | + |
| 5 | +use Frosh\Tools\Components\Elasticsearch\ElasticsearchManager; |
| 6 | +use Shopware\Core\Framework\Routing\Annotation\RouteScope; |
| 7 | +use Symfony\Component\HttpFoundation\JsonResponse; |
| 8 | +use Symfony\Component\HttpFoundation\Response; |
| 9 | +use Symfony\Component\Routing\Annotation\Route; |
| 10 | + |
| 11 | +/** |
| 12 | + * @RouteScope(scopes={"api"}) |
| 13 | + * @Route(path="/api/_action/frosh-tools/elasticsearch") |
| 14 | + */ |
| 15 | +class ElasticsearchController |
| 16 | +{ |
| 17 | + private ElasticsearchManager $manager; |
| 18 | + |
| 19 | + public function __construct(ElasticsearchManager $manager) |
| 20 | + { |
| 21 | + $this->manager = $manager; |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * @Route(path="/status", methods={"GET"}, name="api.frosh.tools.elasticsearch.status") |
| 26 | + */ |
| 27 | + public function status(): Response |
| 28 | + { |
| 29 | + if (!$this->manager->isEnabled()) { |
| 30 | + return new Response('', Response::HTTP_PRECONDITION_FAILED); |
| 31 | + } |
| 32 | + |
| 33 | + return new JsonResponse($this->manager->info()); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @Route(path="/indices", methods={"GET"}, name="api.frosh.tools.elasticsearch.indices") |
| 38 | + */ |
| 39 | + public function indices(): Response |
| 40 | + { |
| 41 | + if (!$this->manager->isEnabled()) { |
| 42 | + return new Response('', Response::HTTP_PRECONDITION_FAILED); |
| 43 | + } |
| 44 | + |
| 45 | + return new JsonResponse($this->manager->indices()); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @Route(path="/index/{indexName}", methods={"DELETE"}, name="api.frosh.tools.elasticsearch.delete_index") |
| 50 | + */ |
| 51 | + public function deleteIndex(string $indexName): Response |
| 52 | + { |
| 53 | + if (!$this->manager->isEnabled()) { |
| 54 | + return new Response('', Response::HTTP_PRECONDITION_FAILED); |
| 55 | + } |
| 56 | + |
| 57 | + return new JsonResponse($this->manager->deleteIndex($indexName)); |
| 58 | + } |
| 59 | +} |
0 commit comments