Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
21 / 21 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| PublishedGroupOlxPropertiesQuery | |
100.00% |
21 / 21 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| execute | |
100.00% |
21 / 21 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Publishing\Connectors\GroupOlx\Application\Queries; |
| 6 | |
| 7 | use ImovelZapAi\Properties\Infrastructure\Persistence\Eloquent\PropertyModel; |
| 8 | use ImovelZapAi\Publishing\Connectors\GroupOlx\Domain\GroupOlxConnector; |
| 9 | use ImovelZapAi\Publishing\Domain\Enums\PublicationTargetStatus; |
| 10 | use ImovelZapAi\Publishing\Infrastructure\Persistence\Eloquent\PublicationModel; |
| 11 | |
| 12 | /** |
| 13 | * Imóveis publicados no canal Grupo OLX (ou xml_export enquanto o canal não é provisionado). |
| 14 | */ |
| 15 | final class PublishedGroupOlxPropertiesQuery |
| 16 | { |
| 17 | /** @var list<string> */ |
| 18 | private const PUBLISHER_SLUGS = [ |
| 19 | GroupOlxConnector::SLUG, |
| 20 | 'xml_export', |
| 21 | ]; |
| 22 | |
| 23 | /** |
| 24 | * @return list<PropertyModel> |
| 25 | */ |
| 26 | public function execute(string $tenantId): array |
| 27 | { |
| 28 | return PublicationModel::query() |
| 29 | ->where('tenant_id', $tenantId) |
| 30 | ->whereHas('targets', function ($query): void { |
| 31 | $query |
| 32 | ->where('status', PublicationTargetStatus::Published) |
| 33 | ->whereHas('publisher', fn ($publisher) => $publisher->whereIn('slug', self::PUBLISHER_SLUGS)); |
| 34 | }) |
| 35 | ->with([ |
| 36 | 'property.state', |
| 37 | 'property.city', |
| 38 | 'property.neighborhood', |
| 39 | 'property.images', |
| 40 | 'property.creator', |
| 41 | 'property.tenant', |
| 42 | ]) |
| 43 | ->get() |
| 44 | ->map(fn (PublicationModel $publication): ?PropertyModel => $publication->property) |
| 45 | ->filter() |
| 46 | ->unique(fn (PropertyModel $property): string => (string) $property->id) |
| 47 | ->values() |
| 48 | ->all(); |
| 49 | } |
| 50 | } |