ADD: startData and endData params.
This commit is contained in:
parent
0466303277
commit
90fbf343b0
|
|
@ -8,6 +8,7 @@ use App\models\ReportsModel;
|
|||
|
||||
|
||||
use Nyholm\Psr7\Response;
|
||||
use PDOException;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
|
|
@ -20,16 +21,34 @@ class ReportController
|
|||
{
|
||||
$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'], JSON_UNESCAPED_UNICODE));
|
||||
if (!$connection instanceof \PDO) {
|
||||
return new Response(500, ['Content-Type' => 'application/json'], json_encode(['error' => 'Erro interno. Contate a equipe de desenvolvimento.']));
|
||||
}
|
||||
|
||||
if (!isset($queryParams['startData']) && !isset($queryParams['endData'])) {
|
||||
return new Response(403, ['Content-Type' => 'application/json'], json_encode(['error' => 'O parâmetro não foi enviado corretamente, ou não existe. Tente novamente'], JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
try {
|
||||
$sql = 'SELECT * FROM queue_stats_mv WHERE datetime LIKE :receivedDate';
|
||||
if (isset($queryParams['endData'])) {
|
||||
$sql = 'SELECT * FROM queue_stats_mv WHERE datetime BETWEEN :startData AND :endData';
|
||||
|
||||
$startData = $queryParams['startData'];
|
||||
$endData = $queryParams['endData'] . ' 23:59:59';
|
||||
|
||||
$stmt = $connection->prepare($sql);
|
||||
|
||||
$data = $queryParams['data'] . '%';
|
||||
$stmt->bindParam(':receivedDate', $data, \PDO::PARAM_STR);
|
||||
$stmt->bindParam(':startData', $startData, \PDO::PARAM_STR);
|
||||
$stmt->bindParam(':endData', $endData, \PDO::PARAM_STR);
|
||||
} else {
|
||||
$sql = 'SELECT * FROM queue_stats_mv WHERE datetime LIKE :startData';
|
||||
|
||||
$startData = $queryParams['startData'] . '%';
|
||||
|
||||
$stmt = $connection->prepare($sql);
|
||||
|
||||
$stmt->bindParam(':startData', $startData, \PDO::PARAM_STR);
|
||||
}
|
||||
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
|
|
|||
|
|
@ -509,5 +509,5 @@
|
|||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.3.0"
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue