117 lines
3.2 KiB
PHP
117 lines
3.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Uwil\ArcadiaGenesisPhpClient\Service;
|
||
|
|
|
||
|
|
use Uwil\ArcadiaGenesisPhpClient\Lib\ApiDto\Dto\Employee;
|
||
|
|
use Uwil\ArcadiaGenesisPhpClient\Lib\ApiDto\Dto\PageOf;
|
||
|
|
use Uwil\ArcadiaGenesisPhpClient\Lib\ApiQueryBuilder\Direction;
|
||
|
|
use Uwil\ArcadiaGenesisPhpClient\Lib\ApiValueObject\ArcadiaEmployeeId;
|
||
|
|
use Uwil\ArcadiaGenesisPhpClient\Lib\ApiValueObject\EmployeeSorter;
|
||
|
|
use Uwil\ArcadiaGenesisPhpClient\Lib\ApiValueObject\SiteId;
|
||
|
|
use Uwil\ArcadiaGenesisPhpClient\Lib\Pagination;
|
||
|
|
use Uwil\ArcadiaGenesisPhpClient\Repository\EmployeeRepository;
|
||
|
|
|
||
|
|
final class EmployeeService
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
private readonly EmployeeRepository $employeeRepository
|
||
|
|
) {
|
||
|
|
}
|
||
|
|
|
||
|
|
/** @return PageOf<Employee> */
|
||
|
|
public function getAllSince(
|
||
|
|
Pagination $pagination,
|
||
|
|
\DateTimeInterface $since,
|
||
|
|
Direction $sortDirection = Direction::DESC,
|
||
|
|
): PageOf {
|
||
|
|
return $this->employeeRepository->selectAllSince(
|
||
|
|
$pagination,
|
||
|
|
$since,
|
||
|
|
$sortDirection
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** @return PageOf<Employee> */
|
||
|
|
public function getAll(
|
||
|
|
Pagination $pagination,
|
||
|
|
?EmployeeSorter $sorter = null,
|
||
|
|
): PageOf {
|
||
|
|
return $this->employeeRepository->selectAll(
|
||
|
|
$pagination,
|
||
|
|
$sorter,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param SiteId[]|SiteId $sites
|
||
|
|
* @return PageOf<Employee>
|
||
|
|
*/
|
||
|
|
public function getAllOfSitesSince(
|
||
|
|
Pagination $pagination,
|
||
|
|
array | SiteId $sites,
|
||
|
|
\DateTimeInterface $since,
|
||
|
|
Direction $sortDirection = Direction::DESC,
|
||
|
|
): PageOf {
|
||
|
|
$sites = is_array($sites) ? $sites : [$sites];
|
||
|
|
|
||
|
|
if (count($sites) < 1) {
|
||
|
|
throw new \InvalidArgumentException('At least 1 site is required');
|
||
|
|
}
|
||
|
|
|
||
|
|
foreach ($sites as $site) {
|
||
|
|
if (! ($site instanceof SiteId)) {
|
||
|
|
throw new \InvalidArgumentException('Expected instance of ' . SiteId::class);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return $this->employeeRepository->selectAllHavingSitesSince(
|
||
|
|
$pagination,
|
||
|
|
$since,
|
||
|
|
$sites,
|
||
|
|
$sortDirection,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param SiteId[]|SiteId $sites
|
||
|
|
* @return PageOf<Employee>
|
||
|
|
*/
|
||
|
|
public function getAllOfSites(
|
||
|
|
Pagination $pagination,
|
||
|
|
array | SiteId $sites,
|
||
|
|
?EmployeeSorter $sorter = null,
|
||
|
|
): PageOf {
|
||
|
|
$sites = is_array($sites) ? $sites : [$sites];
|
||
|
|
|
||
|
|
if (count($sites) < 1) {
|
||
|
|
throw new \InvalidArgumentException('At least 1 site is required');
|
||
|
|
}
|
||
|
|
|
||
|
|
foreach ($sites as $site) {
|
||
|
|
if (! ($site instanceof SiteId)) {
|
||
|
|
throw new \InvalidArgumentException('Expected instance of ' . SiteId::class);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($sorter !== null) {
|
||
|
|
return $this->employeeRepository->selectAllHavingSites(
|
||
|
|
$pagination,
|
||
|
|
$sites,
|
||
|
|
$sorter
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
return $this->employeeRepository->selectAllHavingSites(
|
||
|
|
$pagination,
|
||
|
|
$sites,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function findBy(ArcadiaEmployeeId $id): ?Employee
|
||
|
|
{
|
||
|
|
return $this->employeeRepository->find($id);
|
||
|
|
}
|
||
|
|
}
|