feat: additional api endpoint for hotel data
This commit is contained in:
@@ -4,4 +4,9 @@ GET https://ep-reisen.ddev.site/api/product
|
||||
&hotel=SSTGR
|
||||
&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
|
||||
{
|
||||
if ('/api/product' !== $request->getUri()->getPath()) {
|
||||
return $handler->handle($request);
|
||||
$path = $request->getUri()->getPath();
|
||||
|
||||
if ('/api/hotel' === $path) {
|
||||
return $this->handleHotelRequest($request);
|
||||
}
|
||||
|
||||
if ('/api/product' === $path) {
|
||||
return $this->handleProductRequest($request);
|
||||
}
|
||||
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
private function handleHotelRequest(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));
|
||||
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;
|
||||
$hotelCode = $request->getQueryParams()['hotel'] ?? null;
|
||||
|
||||
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);
|
||||
|
||||
if (null === $data) {
|
||||
return (new JsonResponse(['message' => 'Product not found'], 404));
|
||||
return new JsonResponse(['message' => 'Product not found'], 404);
|
||||
}
|
||||
|
||||
if (null !== $hotelCode) {
|
||||
|
||||
Reference in New Issue
Block a user