Agregar Proveedor
This commit is contained in:
79
app/src/Controller/API/Inmobiliarias/Proveedores.php
Normal file
79
app/src/Controller/API/Inmobiliarias/Proveedores.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Inmobiliarias;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Proveedores extends Ideal\Controller
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Inmobiliaria\Proveedor $proveedorService): ResponseInterface
|
||||
{
|
||||
$output = ['proveedores' => []];
|
||||
try {
|
||||
$output['proveedores'] = $proveedorService->getAll('nombre');
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Inmobiliaria\Proveedor $proveedorService): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'proveedores' => [],
|
||||
'success' => [],
|
||||
];
|
||||
foreach ($input['proveedores'] as $json) {
|
||||
$data = json_decode($json, true);
|
||||
try {
|
||||
$output['proveedores'] []= $proveedorService->add($data);
|
||||
$output['success'] []= true;
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
$output['success'] []= false;
|
||||
}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Inmobiliaria\Proveedor $proveedorService): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'proveedores' => [],
|
||||
'success' => [],
|
||||
];
|
||||
foreach ($input['proveedores'] as $json) {
|
||||
$data = json_decode($json, true);
|
||||
try {
|
||||
$output['proveedores'] []= $proveedorService->edit($data);
|
||||
$output['success'] []= true;
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
$output['success'] []= false;
|
||||
}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Inmobiliaria\Proveedor $proveedorService, int $proveedor_rut): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'proveedor_rut' => $proveedor_rut,
|
||||
'proveedor' => null,
|
||||
'success' => false
|
||||
];
|
||||
try {
|
||||
$output['proveedor'] = $proveedorService->getById($proveedor_rut);
|
||||
$output['success'] = $proveedorService->delete($output['proveedor']);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
@ -11,8 +11,7 @@ use Incoviba\Service;
|
||||
class Proveedores
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||
Service\Inmobiliaria\Proveedor $proveedorService,
|
||||
Repository\Inmobiliaria\TipoSociedad $tipoSociedad): ResponseInterface
|
||||
Service\Inmobiliaria\Proveedor $proveedorService): ResponseInterface
|
||||
{
|
||||
$proveedores = [];
|
||||
try {
|
||||
|
Reference in New Issue
Block a user