Editar cuota

This commit is contained in:
Juan Pablo Vial
2024-10-23 08:39:11 -03:00
parent fe6a01b2fb
commit 389e60980e
5 changed files with 233 additions and 4 deletions

View File

@ -0,0 +1,59 @@
<?php
namespace Incoviba\Service\Contabilidad;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Controller\withRedis;
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Service\Redis;
class Banco extends Ideal\Service
{
use withRedis;
public function __construct(LoggerInterface $logger, protected Repository\Contabilidad\Banco $bancoRepository,
protected Redis $redisService)
{
parent::__construct($logger);
}
protected string $redisKey = 'bancos';
public function getAll(null|string|array $ordering = null): array
{
try {
return $this->fetchRedis($this->redisService, $this->redisKey);
} catch (Implement\Exception\EmptyRedis) {
try {
$bancos = array_map([$this, 'process'], $this->bancoRepository->fetchAll($ordering));
$this->saveRedis($this->redisService, $this->redisKey, $bancos);
return $bancos;
} catch (Implement\Exception\EmptyResult) {
return [];
}
}
}
public function getById(int $banco_id): ?Model\Contabilidad\Banco
{
try {
$bancos = $this->getAll();
$bancos = array_filter($bancos, fn($banco) => $banco->getId() === $banco_id);
return array_shift($bancos);
} catch (Implement\Exception\EmptyRedis) {
try {
$banco = $this->process($this->bancoRepository->fetchById($banco_id));
$this->saveRedis($this->redisService, $this->redisKey, [$banco]);
return $banco;
} catch (Implement\Exception\EmptyResult) {
return null;
}
}
}
protected function process(Model\Contabilidad\Banco $banco): Model\Contabilidad\Banco
{
return $banco;
}
}