Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
91.67% |
11 / 12 |
|
83.33% |
5 / 6 |
CRAP | |
0.00% |
0 / 1 |
| GroupOlxConnector | |
91.67% |
11 / 12 |
|
83.33% |
5 / 6 |
8.04 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| slug | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| publishFeed | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
3.03 | |||
| publishListing | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| publicFeedUrl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| regenerateFromPublished | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Publishing\Connectors\GroupOlx\Application\Services; |
| 6 | |
| 7 | use ImovelZapAi\Publishing\Connectors\GroupOlx\Application\Actions\GenerateVrsyncFeedAction; |
| 8 | use ImovelZapAi\Publishing\Connectors\GroupOlx\Application\Data\GroupOlxPublicFeedData; |
| 9 | use ImovelZapAi\Publishing\Connectors\GroupOlx\Application\Ports\GroupOlxConnectorInterface; |
| 10 | use ImovelZapAi\Publishing\Connectors\GroupOlx\Application\Ports\GroupOlxFeedBuilderInterface; |
| 11 | use ImovelZapAi\Publishing\Connectors\GroupOlx\Application\Ports\GroupOlxFeedValidatorInterface; |
| 12 | use ImovelZapAi\Publishing\Connectors\GroupOlx\Application\Ports\GroupOlxPublicFeedInterface; |
| 13 | use ImovelZapAi\Publishing\Connectors\GroupOlx\Domain\Exceptions\GroupOlxConnectorException; |
| 14 | use ImovelZapAi\Publishing\Connectors\GroupOlx\Domain\GroupOlxConnector as GroupOlxConnectorIdentity; |
| 15 | use ImovelZapAi\Publishing\Domain\Canonical\NormalizedListing; |
| 16 | |
| 17 | /** |
| 18 | * Orquestra o conector Grupo OLX a partir de NormalizedListing. |
| 19 | */ |
| 20 | final class GroupOlxConnector implements GroupOlxConnectorInterface |
| 21 | { |
| 22 | public function __construct( |
| 23 | private readonly GroupOlxFeedBuilderInterface $feedBuilder, |
| 24 | private readonly GroupOlxFeedValidatorInterface $validator, |
| 25 | private readonly GroupOlxPublicFeedInterface $publicFeed, |
| 26 | private readonly GenerateVrsyncFeedAction $generateFeed, |
| 27 | ) {} |
| 28 | |
| 29 | public function slug(): string |
| 30 | { |
| 31 | return GroupOlxConnectorIdentity::SLUG; |
| 32 | } |
| 33 | |
| 34 | public function publishFeed(string $tenantId, array $listings): GroupOlxPublicFeedData |
| 35 | { |
| 36 | if ($listings === []) { |
| 37 | throw GroupOlxConnectorException::invalidFeed('Nenhum imóvel para publicar.'); |
| 38 | } |
| 39 | |
| 40 | $build = $this->feedBuilder->build($listings); |
| 41 | $validation = $this->validator->validateBuild($build); |
| 42 | |
| 43 | if (! $validation->isValid()) { |
| 44 | throw GroupOlxConnectorException::invalidFeed($validation->firstError() ?? 'Feed inválido.'); |
| 45 | } |
| 46 | |
| 47 | return $this->publicFeed->publish($tenantId, $build->xml, $build->listingCount()); |
| 48 | } |
| 49 | |
| 50 | public function publishListing(string $tenantId, NormalizedListing $listing): GroupOlxPublicFeedData |
| 51 | { |
| 52 | return $this->publishFeed($tenantId, [$listing]); |
| 53 | } |
| 54 | |
| 55 | public function publicFeedUrl(string $tenantId): string |
| 56 | { |
| 57 | return $this->publicFeed->resolveUrl($tenantId); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Regenera o feed do tenant a partir dos imóveis publicados (uso do worker). |
| 62 | */ |
| 63 | public function regenerateFromPublished(string $tenantId): bool |
| 64 | { |
| 65 | return $this->generateFeed->execute($tenantId); |
| 66 | } |
| 67 | } |