From 8fe357cc95b1d5e77aa13201fcaddcfdbb95373d Mon Sep 17 00:00:00 2001 From: Aldarien Date: Thu, 25 Mar 2021 23:33:37 -0300 Subject: [PATCH] Slim API --- app/Controller/API/Unidades.php | 13 ++--- app/Controller/Cierres.php | 2 +- composer.json | 17 ++++-- incoviba/modelos/src/old/Venta/Unidad.php | 14 ++--- public/api/index.php | 41 +++------------ resources/routes/api.php | 8 +++ resources/routes/api/unidades.php | 6 +++ .../views/ventas/cierres/evaluar.blade.php | 10 ++-- setup/api/config.php | 11 ++++ setup/api/setups.php | 15 ++++++ setup/app.php | 52 +++++++++++++++++++ setup/common/config.php | 40 ++++++++++++++ setup/composer.php | 6 +++ setup/database.php | 29 +++++++++++ setup/env/config.php | 5 ++ setup/router.php | 5 ++ 16 files changed, 216 insertions(+), 58 deletions(-) create mode 100644 resources/routes/api.php create mode 100644 resources/routes/api/unidades.php create mode 100644 setup/api/config.php create mode 100644 setup/api/setups.php create mode 100644 setup/app.php create mode 100644 setup/common/config.php create mode 100644 setup/composer.php create mode 100644 setup/database.php create mode 100644 setup/env/config.php create mode 100644 setup/router.php diff --git a/app/Controller/API/Unidades.php b/app/Controller/API/Unidades.php index d136445..b50d515 100644 --- a/app/Controller/API/Unidades.php +++ b/app/Controller/API/Unidades.php @@ -1,16 +1,12 @@ findOne($id_proyecto); if (!$proyecto) { throw new \InvalidArgumentException('Proyecto identificado por ' . $id_proyecto . ' no existe.'); @@ -39,6 +35,7 @@ class Unidades { ); }); $output = array_values($unidades); - return json_encode($output); + $response->getBody()->write(\json_encode($output)); + return $response->withHeader('Content-Type', 'application/json'); } } diff --git a/app/Controller/Cierres.php b/app/Controller/Cierres.php index 077a5ce..46a76b9 100644 --- a/app/Controller/Cierres.php +++ b/app/Controller/Cierres.php @@ -250,7 +250,7 @@ class Cierres public static function evalue() { $proyectos = \model(Proyecto::class)->orderByAsc('descripcion')->findMany(); - return view('ventas.cierres.evaluar', compact('proyectos')); + return view('ventas.cierres.evaluar', ['proyectos' => $proyectos, 'locations' => config('locations')]); } public static function evaluar() { diff --git a/composer.json b/composer.json index 29d3da5..62af58a 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,12 @@ "phpoffice/phpword": "^0.14.0", "slam/php-excel": "^4.4", "fabpot/goutte": "^3.2", - "incoviba/modelos": "dev-master" + "incoviba/modelos": "dev-master", + "slim/slim": "4.x-dev", + "php-di/slim-bridge": "dev-master", + "rubellum/slim-blade-view": "dev-master", + "nyholm/psr7": "1.4.x-dev", + "nyholm/psr7-server": "dev-master" }, "require-dev" : { "phpunit/phpunit" : "^6.3", @@ -44,11 +49,17 @@ "repositories": [ { "type": "path", - "url": "aldarien/**" + "url": "./aldarien/**", + "options": { + "symlink": false + } }, { "type": "path", - "url": "incoviba/modelos" + "url": "./incoviba/modelos", + "options": { + "symlink": false + } } ] } diff --git a/incoviba/modelos/src/old/Venta/Unidad.php b/incoviba/modelos/src/old/Venta/Unidad.php index 9fbf4db..bfed43b 100644 --- a/incoviba/modelos/src/old/Venta/Unidad.php +++ b/incoviba/modelos/src/old/Venta/Unidad.php @@ -181,13 +181,15 @@ class Unidad extends Model public function isVendida() { if ($this->is_vendidad == null) { $this->is_vendida = false; - $p = $this->propiedad(); - if ($p) { - $v = $p->venta(); - if ($v) { - $this->is_vendida = true; + try { + $p = $this->propiedad(); + if ($p) { + $v = $p->venta(); + if ($v) { + $this->is_vendida = true; + } } - } + } catch(\Exception $e) {} } return $this->is_vendida; } diff --git a/public/api/index.php b/public/api/index.php index bb5e4d0..223ef89 100644 --- a/public/api/index.php +++ b/public/api/index.php @@ -1,35 +1,8 @@ run(); diff --git a/resources/routes/api.php b/resources/routes/api.php new file mode 100644 index 0000000..91f436f --- /dev/null +++ b/resources/routes/api.php @@ -0,0 +1,8 @@ +isDir()) { + continue; + } + include_once $file->getRealPath(); +} diff --git a/resources/routes/api/unidades.php b/resources/routes/api/unidades.php new file mode 100644 index 0000000..9341283 --- /dev/null +++ b/resources/routes/api/unidades.php @@ -0,0 +1,6 @@ +group('/unidades', function($app) { + $app->get('/no_reservadas/{id_proyecto}/{id_tipo}', [Unidades::class, 'no_reservadas']); +}); diff --git a/resources/views/ventas/cierres/evaluar.blade.php b/resources/views/ventas/cierres/evaluar.blade.php index d7e88bc..34050af 100644 --- a/resources/views/ventas/cierres/evaluar.blade.php +++ b/resources/views/ventas/cierres/evaluar.blade.php @@ -69,8 +69,7 @@ @push('scripts')