Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
21 / 21 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| GetGroupOlxPublicationLogsQuery | |
100.00% |
21 / 21 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| execute | |
100.00% |
21 / 21 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Publishing\Connectors\GroupOlx\Application\Queries; |
| 6 | |
| 7 | use ImovelZapAi\Publishing\Connectors\GroupOlx\Application\Data\GroupOlxPublicationLogData; |
| 8 | use ImovelZapAi\Publishing\Connectors\GroupOlx\Infrastructure\Persistence\Eloquent\GroupOlxPublicationLogModel; |
| 9 | |
| 10 | /** |
| 11 | * Lista PublicationLogs do Grupo OLX (mais recentes primeiro). |
| 12 | */ |
| 13 | final class GetGroupOlxPublicationLogsQuery |
| 14 | { |
| 15 | /** |
| 16 | * @return list<GroupOlxPublicationLogData> |
| 17 | */ |
| 18 | public function execute(string $tenantId, int $limit = 50): array |
| 19 | { |
| 20 | return GroupOlxPublicationLogModel::query() |
| 21 | ->with('triggeredBy:id,name') |
| 22 | ->where('tenant_id', $tenantId) |
| 23 | ->orderByDesc('generated_at') |
| 24 | ->limit(max(1, $limit)) |
| 25 | ->get() |
| 26 | ->map(fn (GroupOlxPublicationLogModel $log): GroupOlxPublicationLogData => new GroupOlxPublicationLogData( |
| 27 | id: (string) $log->id, |
| 28 | tenantId: (string) $log->tenant_id, |
| 29 | triggeredById: $log->triggered_by !== null ? (int) $log->triggered_by : null, |
| 30 | triggeredByName: $log->triggeredBy?->name, |
| 31 | listingCount: (int) $log->listing_count, |
| 32 | durationMs: (int) $log->duration_ms, |
| 33 | success: (bool) $log->success, |
| 34 | version: (string) $log->version, |
| 35 | contentHash: $log->content_hash, |
| 36 | errors: $log->errorList(), |
| 37 | warnings: $log->warningList(), |
| 38 | generatedAt: $log->generated_at ?? now(), |
| 39 | )) |
| 40 | ->all(); |
| 41 | } |
| 42 | } |