-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathUiFeedExportController.php
More file actions
87 lines (76 loc) · 3.01 KB
/
Copy pathUiFeedExportController.php
File metadata and controls
87 lines (76 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
declare(strict_types=1);
namespace Omikron\FactFinder\Shopware6\Api;
use Omikron\FactFinder\Shopware6\Command\DataExportCommand;
use Omikron\FactFinder\Shopware6\Message\FeedExport;
use Omikron\FactFinder\Shopware6\Message\RefreshExportCache;
use Omikron\FactFinder\Shopware6\MessageQueue\FeedExportHandler;
use Omikron\FactFinder\Shopware6\MessageQueue\RefreshExportCacheHandler;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route(defaults={"_routeScope"={"api"}})
*/
class UiFeedExportController extends AbstractController
{
public function __construct(
private FeedExportHandler $feedExportHandler,
private DataExportCommand $dataExportCommand,
private RefreshExportCacheHandler $refreshCacheHandler,
private LoggerInterface $factfinderLogger,
) {
}
/**
* @Route("/api/_action/fact-finder/generate-feed", name="api.action.fact_finder.export_feed", methods={"GET"}, defaults={"XmlHttpRequest"=true})
*
* @param Request $request
*
* @return JsonResponse
*/
public function generateExportFeedAction(Request $request): JsonResponse
{
try {
$this->feedExportHandler->__invoke(new FeedExport(
$request->query->get('salesChannelValue'),
$request->query->get('salesChannelLanguageValue'),
$request->query->get('exportTypeValue')
));
return new JsonResponse();
} catch (\Exception $e) {
$this->factfinderLogger->error($e->getMessage());
return new JsonResponse(['message' => 'Problem with export. Check logs for more informations'], 400);
}
}
/**
* @Route("/api/_action/fact-finder/get-export-type-options", name="api.action.fact_finder.get_export_type_options", methods={"GET"}, defaults={"XmlHttpRequest"=true})
*
* @return JsonResponse
*/
public function getTypeEntityMap(): JsonResponse
{
return new JsonResponse($this->dataExportCommand->getTypeEntityMap());
}
/**
* @Route("/api/_action/fact-finder/refresh-export-cache", name="api.action.fact_finder.refresh-export-cache", methods={"GET"}, defaults={"XmlHttpRequest"=true})
*
* @param Request $request
*
* @return JsonResponse
*/
public function refreshExportCacheAction(Request $request): JsonResponse
{
try {
$this->refreshCacheHandler->__invoke(new RefreshExportCache(
$request->query->get('salesChannelValue'),
$request->query->get('salesChannelLanguageValue')
));
return new JsonResponse();
} catch (\Exception $e) {
$this->factfinderLogger->error($e->getMessage());
return new JsonResponse(['message' => 'Problem with cache export. Check logs for more informations'], 400);
}
}
}