Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| GroupOlxPublicFeed | |
100.00% |
13 / 13 |
|
100.00% |
5 / 5 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| publish | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| resolveUrl | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| isAvailable | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| latestVersion | |
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\Data\FeedStorageVersionData; |
| 8 | use ImovelZapAi\Publishing\Connectors\GroupOlx\Application\Data\GroupOlxPublicFeedData; |
| 9 | use ImovelZapAi\Publishing\Connectors\GroupOlx\Application\Ports\FeedStorageInterface; |
| 10 | use ImovelZapAi\Publishing\Connectors\GroupOlx\Application\Ports\GroupOlxPublicFeedInterface; |
| 11 | use ImovelZapAi\Publishing\Connectors\GroupOlx\Domain\GroupOlxConnector; |
| 12 | use ImovelZapAi\Tenancy\Infrastructure\Persistence\Eloquent\TenantModel; |
| 13 | |
| 14 | /** |
| 15 | * Publica e resolve a URL do feed VRSync pré-gerado (Grupo OLX). |
| 16 | */ |
| 17 | final class GroupOlxPublicFeed implements GroupOlxPublicFeedInterface |
| 18 | { |
| 19 | public function __construct( |
| 20 | private readonly FeedStorageInterface $storage, |
| 21 | ) {} |
| 22 | |
| 23 | public function publish(string $tenantId, string $xml, ?int $listingCount = null): GroupOlxPublicFeedData |
| 24 | { |
| 25 | $version = $this->storage->store($tenantId, $xml); |
| 26 | |
| 27 | return new GroupOlxPublicFeedData( |
| 28 | tenantId: $tenantId, |
| 29 | publicUrl: $this->resolveUrl($tenantId), |
| 30 | format: GroupOlxConnector::FEED_FORMAT, |
| 31 | version: $version->version, |
| 32 | listingCount: $listingCount, |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | public function resolveUrl(string $tenantId): string |
| 37 | { |
| 38 | $tenant = TenantModel::query()->whereKey($tenantId)->firstOrFail(); |
| 39 | |
| 40 | return route('publishing.group_olx.feed.public', $tenant, absolute: true); |
| 41 | } |
| 42 | |
| 43 | public function isAvailable(string $tenantId): bool |
| 44 | { |
| 45 | return $this->storage->exists($tenantId) && $this->storage->get($tenantId) !== null; |
| 46 | } |
| 47 | |
| 48 | public function latestVersion(string $tenantId): ?FeedStorageVersionData |
| 49 | { |
| 50 | return $this->storage->latest($tenantId); |
| 51 | } |
| 52 | } |