Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
54.55% |
6 / 11 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ListDocumentTemplatesQuery | |
54.55% |
6 / 11 |
|
0.00% |
0 / 1 |
3.85 | |
0.00% |
0 / 1 |
| execute | |
54.55% |
6 / 11 |
|
0.00% |
0 / 1 |
3.85 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Documents\Application\Queries; |
| 6 | |
| 7 | use Illuminate\Contracts\Pagination\LengthAwarePaginator; |
| 8 | use ImovelZapAi\Documents\Infrastructure\Persistence\Eloquent\DocumentTemplateModel; |
| 9 | |
| 10 | final class ListDocumentTemplatesQuery |
| 11 | { |
| 12 | /** @param array{document_type?: string|null, search?: string|null, per_page?: int} $filters */ |
| 13 | public function execute(string $tenantId, array $filters = []): LengthAwarePaginator |
| 14 | { |
| 15 | $query = DocumentTemplateModel::query() |
| 16 | ->where('tenant_id', $tenantId) |
| 17 | ->latest(); |
| 18 | |
| 19 | if (! empty($filters['document_type'])) { |
| 20 | $query->where('document_type', $filters['document_type']); |
| 21 | } |
| 22 | if (! empty($filters['search'])) { |
| 23 | $search = '%'.$filters['search'].'%'; |
| 24 | $query->where(function ($q) use ($search): void { |
| 25 | $q->where('name', 'ilike', $search); |
| 26 | }); |
| 27 | } |
| 28 | |
| 29 | return $query->paginate((int) ($filters['per_page'] ?? 20)); |
| 30 | } |
| 31 | } |