Agentes
This commit is contained in:
@ -55,4 +55,29 @@ class Inmobiliarias
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function agentes(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\Inmobiliaria $inmobiliariaRepository,
|
||||
Repository\Inmobiliaria\SociedadAgente $sociedadAgenteRepository,
|
||||
Repository\Inmobiliaria\TipoAgente $tipoAgenteRepository,
|
||||
int $inmobiliaria_rut): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'sociedad_rut' => $inmobiliaria_rut,
|
||||
'input' => $input,
|
||||
'sociedad' => null,
|
||||
'agentes' => []
|
||||
];
|
||||
try {
|
||||
$inmobiliaria = $inmobiliariaRepository->fetchById($inmobiliaria_rut);
|
||||
$output['sociedad'] = $inmobiliaria;
|
||||
if (isset($input['tipo_agente_id'])) {
|
||||
$tipo = $tipoAgenteRepository->fetchById($input['tipo_agente_id']);
|
||||
$output['agentes'] = $sociedadAgenteRepository->fetchBySociedadAndTipo($inmobiliaria->rut, $tipo->id);
|
||||
} else {
|
||||
$output['agentes'] = $sociedadAgenteRepository->fetchBySociedad($inmobiliaria->rut);
|
||||
}
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
90
app/src/Controller/API/Inmobiliarias/Agentes.php
Normal file
90
app/src/Controller/API/Inmobiliarias/Agentes.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Inmobiliarias;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Agentes
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Repository\Inmobiliaria\Agente $agenteRepository): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'agentes' => []
|
||||
];
|
||||
try {
|
||||
$output['agentes'] = $agenteRepository->fetchAll('abreviacion');
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response, Repository\Inmobiliaria\Agente $agenteRepository): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'agente' => null
|
||||
];
|
||||
try {
|
||||
$agente = $agenteRepository->create($input);
|
||||
$output['agente'] = $agenteRepository->save($agente);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\Inmobiliaria\Agente $agenteRepository, int $agente_id): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'agente_id' => $agente_id,
|
||||
'input' => $input,
|
||||
'agente' => null
|
||||
];
|
||||
try {
|
||||
$agente = $agenteRepository->fetchById($agente_id);
|
||||
$output['agente'] = $agenteRepository->edit($agente, $input);
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function register(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Repository\Inmobiliaria $inmobiliariaRepository,
|
||||
Repository\Inmobiliaria\Agente $agenteRepository,
|
||||
Repository\Inmobiliaria\TipoAgente $tipoAgenteRepository,
|
||||
Repository\Inmobiliaria\AgenteTipo $agenteTipoRepository,
|
||||
Repository\Inmobiliaria\SociedadAgente $sociedadAgenteRepository): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'sociedad' => null,
|
||||
'agente' => null,
|
||||
'tipo_agente' => null,
|
||||
'sociedad_agente' => null
|
||||
];
|
||||
try {
|
||||
$sociedad = $inmobiliariaRepository->fetchById($input['sociedad_rut']);
|
||||
$output['sociedad'] = $sociedad;
|
||||
$agente = $agenteRepository->fetchById($input['agente_id']);
|
||||
$output['agente'] = $agente;
|
||||
$tipo = $tipoAgenteRepository->fetchById($input['tipo_agente_id']);
|
||||
$output['tipo_agente'] = $tipo;
|
||||
$agenteTipo = $agenteTipoRepository->fetchByAgenteAndTipo($agente->id, $tipo->id);
|
||||
try {
|
||||
$output['sociedad_agente'] = $sociedadAgenteRepository->fetchBySociedadAndAgenteAndTipo($sociedad->rut, $agente->id, $tipo->id);
|
||||
} catch (EmptyResult) {
|
||||
$data = [
|
||||
'sociedad_rut' => $sociedad->rut,
|
||||
'agente_tipo_id' => $agenteTipo->id
|
||||
];
|
||||
$sociedadAgente = $sociedadAgenteRepository->create($data);
|
||||
$output['sociedad_agente'] = $sociedadAgenteRepository->save($sociedadAgente);
|
||||
}
|
||||
} catch (EmptyResult) {
|
||||
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user