feat: API endpoint for last update of XML data
This commit is contained in:
@@ -13,6 +13,11 @@ GET {{base_url}}/api/crm-attributes
|
|||||||
Accept: application/json
|
Accept: application/json
|
||||||
Authorization: Bearer {{$auth.token("oauth2_profile")}}
|
Authorization: Bearer {{$auth.token("oauth2_profile")}}
|
||||||
|
|
||||||
|
### API last update at
|
||||||
|
GET {{base_url}}/api/last-update
|
||||||
|
Accept: application/json
|
||||||
|
Authorization: Bearer {{$auth.token("oauth2_api")}}
|
||||||
|
|
||||||
### API countries
|
### API countries
|
||||||
GET {{base_url}}/api/countries
|
GET {{base_url}}/api/countries
|
||||||
Accept: application/json
|
Accept: application/json
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\Api;
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route(path: '/last-update', name: 'api_last_update', methods: ['GET'])]
|
||||||
|
public function index(): JsonResponse
|
||||||
|
{
|
||||||
|
if (false === $this->xmlExport->has('uebertragung.info')) {
|
||||||
|
$lastUploadAt = null;
|
||||||
|
} else {
|
||||||
|
$file = $this->xmlExport->read('uebertragung.info');
|
||||||
|
$lines = explode("\n", $file);
|
||||||
|
$line = trim($lines[0]);
|
||||||
|
|
||||||
|
if (true === empty($line)) {
|
||||||
|
$lastUploadAt = null;
|
||||||
|
} else {
|
||||||
|
$lastUploadAt = \DateTime::createFromFormat('d.m.Y H:i:s', $line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->json(['timestamp' => $lastUploadAt->format('Y-m-d H:i:s')]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user