initialize(); } public function list(): Response { $data = (new PodcastModel())->findAll(); array_map(static function ($podcast): void { self::mapPodcast($podcast); }, $data); return $this->respond($data); } public function view(int $id): Response { $podcast = (new PodcastModel())->getPodcastById($id); if (! $podcast instanceof Podcast) { return $this->failNotFound('Podcast not found'); } return $this->respond(self::mapPodcast($podcast)); } protected static function mapPodcast(Podcast $podcast): Podcast { $podcast->feed_url = $podcast->getFeedUrl(); $podcast->actor_display_name = $podcast->getActor() ->display_name; $podcast->cover_url = $podcast->getCover() ->file_url; $categories = [$podcast->getCategory(), ...$podcast->getOtherCategories()]; foreach ($categories as $category) { $category->translated = lang('Podcast.category_options.' . $category->code, [], null, false); } $podcast->categories = $categories; return $podcast; } }