51 lines
1.5 KiB
PHP
51 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\api;
|
|
|
|
require_once '../app/models/ReportsModel.php';
|
|
|
|
use App\models\ReportsModel;
|
|
|
|
|
|
use Nyholm\Psr7\Response;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
|
|
class ReportController
|
|
{
|
|
|
|
public function __construct(public ReportsModel $reportsModel) {}
|
|
public function show(ServerRequestInterface $request, $queryParams)
|
|
{
|
|
$connection = $this->reportsModel->dbConnect();
|
|
|
|
if (!isset($queryParams['data'])) {
|
|
return new Response(403, ['Content-Type' => 'application/json'], json_encode(['error' => 'O parâmetro "data" não foi enviado corretamente, ou não existe. Tente novamente']));
|
|
}
|
|
|
|
try {
|
|
$sql = 'SELECT * FROM queue_stats_mv WHERE datetime LIKE :receivedDate';
|
|
$stmt = $connection->prepare($sql);
|
|
|
|
$data = $queryParams['data'] . '%';
|
|
$stmt->bindParam(':receivedDate', $data, \PDO::PARAM_STR);
|
|
|
|
$stmt->execute();
|
|
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
|
|
return new Response(
|
|
200,
|
|
['Content-Type' => 'application/json'],
|
|
json_encode(['success' => true, 'data' => $result], JSON_UNESCAPED_UNICODE)
|
|
);
|
|
} catch (\PDOException $e) {
|
|
return new Response(
|
|
500,
|
|
['Content-Type' => 'application/json'],
|
|
json_encode(['error' => 'Erro ao executar a consulta: ' . $e->getMessage()])
|
|
);
|
|
}
|
|
}
|
|
}
|