Move SendingQueueEntity::toArray() to SendingQueuesResponseBuilder::build()

Based on a suggestion during the review of the PR, it was decided that
it makes more sense for the code that was created as
SendingQueueEntity::toArray() tp be moved to
SendingQueuesResponseBuilder::build(). It is used only to build the
format that is send in the API response.

[MAILPOET-4368]
This commit is contained in:
Rodrigo Primo
2023-10-25 10:50:51 -03:00
committed by Aschepikov
parent 69736c5e83
commit d4a80c7230
5 changed files with 59 additions and 38 deletions

View File

@@ -223,36 +223,4 @@ class SendingQueueEntity {
public function setNewsletter(NewsletterEntity $newsletter) {
$this->newsletter = $newsletter;
}
public function toArray(): array {
if (!$this->getTask() instanceof ScheduledTaskEntity) {
throw new \RuntimeException('Invalid state. SendingQueue has no ScheduledTask associated.');
}
return [
'id' => $this->getId(),
'type' => $this->getTask()->getType(),
'status' => $this->getTask()->getStatus(),
'priority' => $this->getTask()->getPriority(),
'scheduled_at' => $this->getFormattedDateOrNull($this->getTask()->getScheduledAt()),
'processed_at' => $this->getFormattedDateOrNull($this->getTask()->getProcessedAt()),
'created_at' => $this->getFormattedDateOrNull($this->getTask()->getCreatedAt()),
'updated_at' => $this->getFormattedDateOrNull($this->getTask()->getUpdatedAt()),
'deleted_at' => $this->getFormattedDateOrNull($this->getTask()->getDeletedAt()),
'in_progress' => $this->getTask()->getInProgress(),
'reschedule_count' => $this->getTask()->getRescheduleCount(),
'meta' => $this->getMeta(),
'task_id' => $this->getTask()->getId(),
'newsletter_id' => ($this->getNewsletter() instanceof NewsletterEntity) ? $this->getNewsletter()->getId() : null,
'newsletter_rendered_body' => $this->getNewsletterRenderedBody(),
'newsletter_rendered_subject' => $this->getNewsletterRenderedSubject(),
'count_total' => $this->getCountTotal(),
'count_processed' => $this->getCountProcessed(),
'count_to_process' => $this->getCountToProcess(),
];
}
private function getFormattedDateOrNull(?\DateTimeInterface $date): ?string {
return $date ? $date->format('Y-m-d H:i:s') : null;
}
}