feat: additional api endpoint for hotel data

This commit is contained in:
Björn Fromme
2026-06-27 15:47:42 +02:00
parent 561883f74a
commit 51fa9fac62
2 changed files with 46 additions and 5 deletions
+5
View File
@@ -4,4 +4,9 @@ GET https://ep-reisen.ddev.site/api/product
&hotel=SSTGR &hotel=SSTGR
&key=abcabc123 &key=abcabc123
### GET hotel data for myep
GET https://ep-reisen.ddev.site/api/hotel
?hotel=SSTGR
&key=abcabc123
### ###
@@ -16,29 +16,65 @@ class ProductApiMiddleware implements MiddlewareInterface
{ {
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{ {
if ('/api/product' !== $request->getUri()->getPath()) { $path = $request->getUri()->getPath();
if ('/api/hotel' === $path) {
return $this->handleHotelRequest($request);
}
if ('/api/product' === $path) {
return $this->handleProductRequest($request);
}
return $handler->handle($request); return $handler->handle($request);
} }
private function handleHotelRequest(ServerRequestInterface $request): ResponseInterface
{
// This is currently fake, we only check for existence. Since we are communicating // This is currently fake, we only check for existence. Since we are communicating
// on the backchannel only it's not much of a problem. // on the backchannel only it's not much of a problem.
$apiKey = $request->getQueryParams()['key'] ?? null; $apiKey = $request->getQueryParams()['key'] ?? null;
if (null === $apiKey) { if (null === $apiKey) {
return (new JsonResponse(['message' => 'No api key provided'], 403)); return new JsonResponse(['message' => 'No api key provided'], 403);
}
$hotelCode = $request->getQueryParams()['hotel'] ?? null;
if (null === $hotelCode) {
return new JsonResponse(['message' => 'No hotel code provided'], 400);
}
$data = $this->fetchHotelData($hotelCode);
if ([] === $data) {
return new JsonResponse(['message' => 'Hotel not found'], 404);
}
return new JsonResponse($data);
}
private function handleProductRequest(ServerRequestInterface $request): ResponseInterface
{
// This is currently fake, we only check for existence. Since we are communicating
// on the backchannel only it's not much of a problem.
$apiKey = $request->getQueryParams()['key'] ?? null;
if (null === $apiKey) {
return new JsonResponse(['message' => 'No api key provided'], 403);
} }
$productCode = $request->getQueryParams()['product'] ?? null; $productCode = $request->getQueryParams()['product'] ?? null;
$hotelCode = $request->getQueryParams()['hotel'] ?? null; $hotelCode = $request->getQueryParams()['hotel'] ?? null;
if (null === $productCode) { if (null === $productCode) {
return (new JsonResponse(['message' => 'No product code provided'], 400)); return new JsonResponse(['message' => 'No product code provided'], 400);
} }
$data = $this->fetchProductData($productCode); $data = $this->fetchProductData($productCode);
if (null === $data) { if (null === $data) {
return (new JsonResponse(['message' => 'Product not found'], 404)); return new JsonResponse(['message' => 'Product not found'], 404);
} }
if (null !== $hotelCode) { if (null !== $hotelCode) {