UPDATE: Update show method with new logic.
This commit is contained in:
parent
b3b6c27dfe
commit
ddf90ffeff
|
|
@ -2,7 +2,11 @@
|
|||
|
||||
namespace App\api;
|
||||
|
||||
use Models\ReportsModel;
|
||||
require_once '../app/models/ReportsModel.php';
|
||||
|
||||
use App\Models\ReportsModel;
|
||||
|
||||
|
||||
use Nyholm\Psr7\Response;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
|
@ -10,8 +14,33 @@ use Psr\Http\Message\ResponseInterface;
|
|||
|
||||
class ReportController
|
||||
{
|
||||
|
||||
public function __construct(public ReportsModel $reportsModel) {}
|
||||
public function show(ServerRequestInterface $request, $queryParams)
|
||||
{
|
||||
return new Response(200, ['Content-Type' => 'application/json'], json_encode(['success' => 'data']));
|
||||
$connection = $this->reportsModel->dbConnect();
|
||||
|
||||
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()])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue