Contratos desde proyectos

This commit is contained in:
Juan Pablo Vial
2025-03-03 21:46:53 -03:00
parent aeeca65d94
commit 8ea4995f6b
3 changed files with 38 additions and 0 deletions

View File

@ -27,4 +27,5 @@ $app->group('/proyecto/{proyecto_id}', function($app) {
$app->group('/terreno', function($app) { $app->group('/terreno', function($app) {
$app->post('/edit[/]', [Proyectos::class, 'terreno']); $app->post('/edit[/]', [Proyectos::class, 'terreno']);
}); });
$app->get('/brokers', [Proyectos::class, 'brokers']);
}); });

View File

@ -4,6 +4,7 @@ namespace Incoviba\Controller\API;
use Incoviba\Common\Implement\Exception\EmptyRedis; use Incoviba\Common\Implement\Exception\EmptyRedis;
use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Controller\withRedis; use Incoviba\Controller\withRedis;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Model; use Incoviba\Model;
use Incoviba\Repository; use Incoviba\Repository;
use Incoviba\Service; use Incoviba\Service;
@ -170,4 +171,20 @@ class Proyectos
} catch (EmptyResult) {} } catch (EmptyResult) {}
return $this->withJson($response, $output); return $this->withJson($response, $output);
} }
public function brokers(ServerRequestInterface $request, ResponseInterface $response,
Repository\Proyecto $proyectoRepository, Service\Proyecto\Broker\Contract $contractService,
int $proyecto_id): ResponseInterface
{
$output = [
'proyecto_id' => $proyecto_id,
'contracts' => []
];
try {
$proyecto = $proyectoRepository->fetchById($proyecto_id);
$output['contracts'] = $contractService->getByProject($proyecto->id);
} catch (EmptyResult | Read $exception) {
return $this->withError($response, $exception);
}
return $this->withJson($response, $output);
}
} }

View File

@ -29,6 +29,26 @@ class Contract extends Ideal\Service
return []; return [];
} }
} }
/**
* @param int $project_id
* @return array
* @throws ServiceAction\Read
*/
public function getByProject(int $project_id): array
{
try {
return array_map([$this, 'process'], $this->contractRepository->fetchByProject($project_id));
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception);
}
}
/**
* @param int $broker_rut
* @return array
* @throws ServiceAction\Read
*/
public function getByBroker(int $broker_rut): array public function getByBroker(int $broker_rut): array
{ {
try { try {