94 lines
2.5 KiB
PHP
94 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Contracts\Repositories\EmployeeRepository;
|
|
use App\Models\Employee;
|
|
use Domain\Models\ValueObjects\Code;
|
|
use Domain\Models\ValueObjects\Matricule;
|
|
use Illuminate\Support\Collection;
|
|
use Ramsey\Uuid\UuidInterface;
|
|
|
|
class EloquentEmployeeRepository implements EmployeeRepository
|
|
{
|
|
/** @return array<int, Employee> */
|
|
public function getAll(): array
|
|
{
|
|
return Employee::query()
|
|
->get()
|
|
->all();
|
|
}
|
|
|
|
public function find(UuidInterface $id): ?Employee
|
|
{
|
|
return Employee::query()
|
|
->where('id', $id->toString())
|
|
->first();
|
|
}
|
|
|
|
public function persist(Employee $employee): void
|
|
{
|
|
$employee->save();
|
|
}
|
|
|
|
public function delete(Employee $employee): void
|
|
{
|
|
$employee->delete();
|
|
}
|
|
|
|
public function findByMatriculeAndCode(Matricule $matricule, Code $code): ?Employee
|
|
{
|
|
return Employee::query()
|
|
->where('matricule', $matricule->value)
|
|
->where('code', $code->value)
|
|
->first();
|
|
}
|
|
|
|
public function findByMatricule(Matricule $matricule): ?Employee
|
|
{
|
|
return Employee::query()
|
|
->where('matricule', $matricule->value)
|
|
->first();
|
|
}
|
|
|
|
/**
|
|
* @param array<array-key, Matricule>|Collection<array-key, Matricule> $matricules
|
|
* @return array<int, Employee>
|
|
*/
|
|
public function getWhereMatriculeIn(array | Collection $matricules): array
|
|
{
|
|
return Employee::query()
|
|
->whereIn('matricule', $matricules)
|
|
->get()
|
|
->all();
|
|
}
|
|
|
|
/**
|
|
* @param array<array-key, Matricule>|Collection<array-key, Matricule> $matricules
|
|
* @return array<string, Employee>
|
|
*/
|
|
public function getWithCustomerWhereMatriculeIn(array | Collection $matricules): array
|
|
{
|
|
return Employee::query()
|
|
->with('customer')
|
|
->whereIn('matricule', $matricules)
|
|
->get()
|
|
->keyBy('matricule')
|
|
->all();
|
|
}
|
|
|
|
/**
|
|
* @param array<array-key, Matricule>|Collection<array-key, Matricule> $excludedMatricules
|
|
* @return array<int, Employee>
|
|
*/
|
|
public function getWithCustomerWhereMatriculeNotIn(array | Collection $excludedMatricules): array
|
|
{
|
|
return Employee::query()
|
|
->with('customer')
|
|
->whereNotIn('matricule', $excludedMatricules)
|
|
->get()
|
|
->all();
|
|
}
|
|
}
|