feature/cierres #25

Open
aldarien wants to merge 446 commits from feature/cierres into develop
451 changed files with 1240 additions and 19750 deletions
Showing only changes of commit 12e3d7ed3b - Show all commits

View File

@ -0,0 +1,85 @@
<?php
namespace Incoviba\Service\Proyecto\Broker;
use Incoviba\Exception\ServiceAction\Update;
use PDOException;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Exception\ServiceAction;
use Incoviba\Model;
use Incoviba\Repository;
class Contract extends Ideal\Service
{
public function __construct(LoggerInterface $logger,
protected Repository\Proyecto\Broker\Contract $contractRepository)
{
parent::__construct($logger);
}
public function getAll(): array
{
try {
return $this->contractRepository->fetchAll();
} catch (Implement\Exception\EmptyResult) {
return [];
}
}
/**
* @throws ServiceAction\Read
*/
public function getById(int $id): Model\Proyecto\Broker\Contract
{
try {
return $this->contractRepository->fetchById($id);
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception);
}
}
/**
* @throws ServiceAction\Create
*/
public function add(array $data): Model\Proyecto\Broker\Contract
{
try {
return $this->contractRepository->fetchActiveByProjectAndBroker($data['proyecto_id'], $data['broker_rut']);
} catch (Implement\Exception\EmptyResult) {}
try {
$filteredData = $this->contractRepository->filterData($data);
$contract = $this->contractRepository->create($filteredData);
return $this->contractRepository->save($contract);
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Create(__CLASS__, $exception);
}
}
/**
* @throws Update
*/
public function edit(Model\Proyecto\Broker\Contract $contract, array $data): Model\Proyecto\Broker\Contract
{
try {
$filteredData = $this->contractRepository->filterData($data);
return $this->contractRepository->edit($contract, $filteredData);
} catch (PDOException | Implement\Exception\EmptyResult) {
throw new ServiceAction\Update(__CLASS__);
}
}
/**
* @throws ServiceAction\Delete
*/
public function delete(int $id): Model\Proyecto\Broker\Contract
{
try {
$contract = $this->contractRepository->fetchById($id);
$this->contractRepository->remove($contract->id);
return $contract;
} catch (PDOException | Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Delete(__CLASS__, $exception);
}
}
}