32 lines
1000 B
PHP
32 lines
1000 B
PHP
<?php
|
|
|
|
namespace App\Controller\Api;
|
|
|
|
use App\BusProNet\Model\XmlExportInfo;
|
|
use League\Flysystem\FilesystemOperator;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
|
|
|
#[Route('/api')]
|
|
#[IsGranted('ROLE_OAUTH2_API')]
|
|
class LastUpdateController extends AbstractController
|
|
{
|
|
public function __construct(private readonly FilesystemOperator $xmlExport)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* A missing or unreadable marker answers `{"timestamp": null}`, never a 500: consumers
|
|
* poll this for change detection and treat null as "unknown".
|
|
*/
|
|
#[Route(path: '/last-update', name: 'api_last_update', methods: ['GET'])]
|
|
public function index(): JsonResponse
|
|
{
|
|
$info = XmlExportInfo::fromStorage($this->xmlExport);
|
|
|
|
return $this->json(['timestamp' => $info?->lastTransfer->format('Y-m-d H:i:s')]);
|
|
}
|
|
}
|