Compare commits
6 Commits
b526f8700a
...
a8a0b4b6bf
| Author | SHA1 | Date |
|---|---|---|
|
|
a8a0b4b6bf | |
|
|
19a07aa427 | |
|
|
ddf90ffeff | |
|
|
b3b6c27dfe | |
|
|
d7133daa31 | |
|
|
53ca033085 |
|
|
@ -2,7 +2,11 @@
|
||||||
|
|
||||||
namespace App\api;
|
namespace App\api;
|
||||||
|
|
||||||
use Models\ReportsModel;
|
require_once '../app/models/ReportsModel.php';
|
||||||
|
|
||||||
|
use App\Models\ReportsModel;
|
||||||
|
|
||||||
|
|
||||||
use Nyholm\Psr7\Response;
|
use Nyholm\Psr7\Response;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
@ -10,8 +14,33 @@ use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
class ReportController
|
class ReportController
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public function __construct(public ReportsModel $reportsModel) {}
|
||||||
public function show(ServerRequestInterface $request, $queryParams)
|
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()])
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1,28 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
class ReportsModel
|
||||||
|
{
|
||||||
|
private $hostname = 'produs.linepbx.com.br';
|
||||||
|
private $username = 'produs-api';
|
||||||
|
private $password = '*Ingline.Sys#9420%SECURITY#';
|
||||||
|
private $database = 'qstats';
|
||||||
|
private static $connection = null;
|
||||||
|
|
||||||
|
public function __construct() {}
|
||||||
|
|
||||||
|
public function dbConnect()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (self::$connection === null) {
|
||||||
|
try {
|
||||||
|
self::$connection = new \PDO('mysql:host=produs.linepbx.com.br;dbname=qstats;charset=utf8mb4', $this->username, $this->password);
|
||||||
|
self::$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||||
|
} catch (\PDOException $e) {
|
||||||
|
return json_encode(['error' => 'Erro na conexão com o banco ' . $e->getMessage()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return self::$connection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
"name": "administrador/linepbx-api",
|
"name": "administrador/linepbx-api",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"app\\": "app/"
|
"app\\": "app/",
|
||||||
|
"core\\": "core/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"authors": [
|
"authors": [
|
||||||
|
|
@ -14,6 +15,7 @@
|
||||||
"require": {
|
"require": {
|
||||||
"psr/http-message": "^2.0",
|
"psr/http-message": "^2.0",
|
||||||
"nyholm/psr7": "^1.8",
|
"nyholm/psr7": "^1.8",
|
||||||
"nyholm/psr7-server": "^1.1"
|
"nyholm/psr7-server": "^1.1",
|
||||||
|
"php-di/php-di": "^7.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,69 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "9c15ad4fc717c578191a8cd9b9095bd0",
|
"content-hash": "2bab835ea30f0b34fd12f9cb0086d45b",
|
||||||
"packages": [
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "laravel/serializable-closure",
|
||||||
|
"version": "v2.0.6",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/laravel/serializable-closure.git",
|
||||||
|
"reference": "038ce42edee619599a1debb7e81d7b3759492819"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/laravel/serializable-closure/zipball/038ce42edee619599a1debb7e81d7b3759492819",
|
||||||
|
"reference": "038ce42edee619599a1debb7e81d7b3759492819",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^8.1"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"illuminate/support": "^10.0|^11.0|^12.0",
|
||||||
|
"nesbot/carbon": "^2.67|^3.0",
|
||||||
|
"pestphp/pest": "^2.36|^3.0",
|
||||||
|
"phpstan/phpstan": "^2.0",
|
||||||
|
"symfony/var-dumper": "^6.2.0|^7.0.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "2.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Laravel\\SerializableClosure\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Taylor Otwell",
|
||||||
|
"email": "taylor@laravel.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Nuno Maduro",
|
||||||
|
"email": "nuno@laravel.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP.",
|
||||||
|
"keywords": [
|
||||||
|
"closure",
|
||||||
|
"laravel",
|
||||||
|
"serializable"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/laravel/serializable-closure/issues",
|
||||||
|
"source": "https://github.com/laravel/serializable-closure"
|
||||||
|
},
|
||||||
|
"time": "2025-10-09T13:42:30+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "nyholm/psr7",
|
"name": "nyholm/psr7",
|
||||||
"version": "1.8.2",
|
"version": "1.8.2",
|
||||||
|
|
@ -150,6 +211,187 @@
|
||||||
],
|
],
|
||||||
"time": "2023-11-08T09:30:43+00:00"
|
"time": "2023-11-08T09:30:43+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "php-di/invoker",
|
||||||
|
"version": "2.3.7",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/PHP-DI/Invoker.git",
|
||||||
|
"reference": "3c1ddfdef181431fbc4be83378f6d036d59e81e1"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/PHP-DI/Invoker/zipball/3c1ddfdef181431fbc4be83378f6d036d59e81e1",
|
||||||
|
"reference": "3c1ddfdef181431fbc4be83378f6d036d59e81e1",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=7.3",
|
||||||
|
"psr/container": "^1.0|^2.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"athletic/athletic": "~0.1.8",
|
||||||
|
"mnapoli/hard-mode": "~0.3.0",
|
||||||
|
"phpunit/phpunit": "^9.0 || ^10 || ^11 || ^12"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Invoker\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"description": "Generic and extensible callable invoker",
|
||||||
|
"homepage": "https://github.com/PHP-DI/Invoker",
|
||||||
|
"keywords": [
|
||||||
|
"callable",
|
||||||
|
"dependency",
|
||||||
|
"dependency-injection",
|
||||||
|
"injection",
|
||||||
|
"invoke",
|
||||||
|
"invoker"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/PHP-DI/Invoker/issues",
|
||||||
|
"source": "https://github.com/PHP-DI/Invoker/tree/2.3.7"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/mnapoli",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2025-08-30T10:22:22+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "php-di/php-di",
|
||||||
|
"version": "7.1.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/PHP-DI/PHP-DI.git",
|
||||||
|
"reference": "f88054cc052e40dbe7b383c8817c19442d480352"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/PHP-DI/PHP-DI/zipball/f88054cc052e40dbe7b383c8817c19442d480352",
|
||||||
|
"reference": "f88054cc052e40dbe7b383c8817c19442d480352",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"laravel/serializable-closure": "^1.0 || ^2.0",
|
||||||
|
"php": ">=8.0",
|
||||||
|
"php-di/invoker": "^2.0",
|
||||||
|
"psr/container": "^1.1 || ^2.0"
|
||||||
|
},
|
||||||
|
"provide": {
|
||||||
|
"psr/container-implementation": "^1.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"friendsofphp/php-cs-fixer": "^3",
|
||||||
|
"friendsofphp/proxy-manager-lts": "^1",
|
||||||
|
"mnapoli/phpunit-easymock": "^1.3",
|
||||||
|
"phpunit/phpunit": "^9.6 || ^10 || ^11",
|
||||||
|
"vimeo/psalm": "^5|^6"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"friendsofphp/proxy-manager-lts": "Install it if you want to use lazy injection (version ^1)"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"src/functions.php"
|
||||||
|
],
|
||||||
|
"psr-4": {
|
||||||
|
"DI\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"description": "The dependency injection container for humans",
|
||||||
|
"homepage": "https://php-di.org/",
|
||||||
|
"keywords": [
|
||||||
|
"PSR-11",
|
||||||
|
"container",
|
||||||
|
"container-interop",
|
||||||
|
"dependency injection",
|
||||||
|
"di",
|
||||||
|
"ioc",
|
||||||
|
"psr11"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/PHP-DI/PHP-DI/issues",
|
||||||
|
"source": "https://github.com/PHP-DI/PHP-DI/tree/7.1.1"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/mnapoli",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://tidelift.com/funding/github/packagist/php-di/php-di",
|
||||||
|
"type": "tidelift"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2025-08-16T11:10:48+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "psr/container",
|
||||||
|
"version": "2.0.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/php-fig/container.git",
|
||||||
|
"reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963",
|
||||||
|
"reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=7.4.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "2.0.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Psr\\Container\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "PHP-FIG",
|
||||||
|
"homepage": "https://www.php-fig.org/"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Common Container Interface (PHP FIG PSR-11)",
|
||||||
|
"homepage": "https://github.com/php-fig/container",
|
||||||
|
"keywords": [
|
||||||
|
"PSR-11",
|
||||||
|
"container",
|
||||||
|
"container-interface",
|
||||||
|
"container-interop",
|
||||||
|
"psr"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/php-fig/container/issues",
|
||||||
|
"source": "https://github.com/php-fig/container/tree/2.0.2"
|
||||||
|
},
|
||||||
|
"time": "2021-11-05T16:47:00+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "psr/http-factory",
|
"name": "psr/http-factory",
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
use Core\Router;
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
|
return [
|
||||||
|
Router::class => function (ContainerInterface $container) {
|
||||||
|
return new Router($container); // ou passe dependências se houver
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
@ -4,6 +4,8 @@ namespace Core;
|
||||||
|
|
||||||
require_once '../app/api/ReportController.php';
|
require_once '../app/api/ReportController.php';
|
||||||
|
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
use DI\Container;
|
||||||
use Nyholm\Psr7\Response;
|
use Nyholm\Psr7\Response;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
@ -12,8 +14,10 @@ use Nyholm\Psr7Server\ServerRequestCreatorInterface;
|
||||||
|
|
||||||
class Router
|
class Router
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
protected $routes = [];
|
protected $routes = [];
|
||||||
public function __construct() {}
|
public function __construct(protected ContainerInterface $container ) {}
|
||||||
|
|
||||||
public function setRoute($method, $uri, $action)
|
public function setRoute($method, $uri, $action)
|
||||||
{
|
{
|
||||||
|
|
@ -71,7 +75,7 @@ class Router
|
||||||
return new Response(500, ['Content-Type' => 'application/json', 'Accept' => 'application/json'], json_encode(['error' => 'Recurso não foi encontrado']));
|
return new Response(500, ['Content-Type' => 'application/json', 'Accept' => 'application/json'], json_encode(['error' => 'Recurso não foi encontrado']));
|
||||||
}
|
}
|
||||||
|
|
||||||
$controllerInstance = new $controllerClass();
|
$controllerInstance = $this->container->get($controllerClass);
|
||||||
|
|
||||||
if (empty($queryParams)) {
|
if (empty($queryParams)) {
|
||||||
return new Response(403, ['Content-Type' => 'application/json', 'Accept' => 'application/json'], json_encode(['error' => 'O parâmetro de data não foi enviado.']));
|
return new Response(403, ['Content-Type' => 'application/json', 'Accept' => 'application/json'], json_encode(['error' => 'O parâmetro de data não foi enviado.']));
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,13 @@ use App\Controllers\ReportController;
|
||||||
|
|
||||||
use Core\Router;
|
use Core\Router;
|
||||||
|
|
||||||
$router = new Router();
|
use DI\ContainerBuilder;
|
||||||
|
|
||||||
|
$containerBuilder = new ContainerBuilder();
|
||||||
|
$containerBuilder->addDefinitions('../config/config.php');
|
||||||
|
$container = $containerBuilder->build();
|
||||||
|
|
||||||
|
$router = $container->get(Router::class);
|
||||||
|
|
||||||
require_once '../routes/api.php';
|
require_once '../routes/api.php';
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue