mapado route -> 'mapado-api'

This commit is contained in:
isUnknown 2024-07-29 08:57:35 +02:00
parent 37a84058d1
commit dde1813f78
12 changed files with 127 additions and 42 deletions

View file

@ -3,6 +3,7 @@
return [
'debug' => true,
'routes' => [
require_once(__DIR__ . '/routes/mapado.php')
require_once(__DIR__ . '/routes/mapado-api.php'),
require_once(__DIR__ . '/routes/month-dates.php')
]
];

View file

@ -1,6 +1,6 @@
<?php
return [
'pattern' => '/mapado.json',
'pattern' => '/mapado-api.json',
'method' => 'POST',
'action' => function () {
$jsonRequest = file_get_contents("php://input");

View file

@ -0,0 +1,25 @@
<?php
return [
'pattern' => '/month-dates.json',
'method' => 'POST',
'action' => function () {
$jsonRequest = file_get_contents("php://input");
$request = json_decode($jsonRequest, true);
$dates = $request['dates'];
$year = explode('-', $request['month'])[0];
$correspondingSeasons = page('programme')->children()->filter(
fn ($season) => str_contains($season->title()->value(), $year)
);
$eventsFromSameMonth = $correspondingSeasons->children()->filter(
fn ($event) => $event->isNotEmpty() && $event->startDate()->toDate('Y-m') == $request['month']
);
foreach ($eventsFromSameMonth as $event) {
$day = $event->startDate()->toDate('d');
}
return json_encode($eventsFromSameMonth);
}
];