ad-aures_castoPod/modules/Api/Rest/V1/Controllers/PodcastController.php
Yassine Doghri e5fb676cb6
feat(docker): replace all-in-one image with FrankenPHP and Caddy based image + discard other images
- use serversideup/php as a base image
- remove nginx unit base
- remove app / webserver images
- add bundle stage to remove pipeline dependency
- update docker setup docs
- edit gitlabci rules and release logic
2026-02-17 19:31:24 +00:00

59 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Modules\Api\Rest\V1\Controllers;
use App\Entities\Podcast;
use App\Models\PodcastModel;
use CodeIgniter\HTTP\ResponseInterface;
class PodcastController extends BaseApiController
{
public function __construct()
{
service('restApiExceptions')->initialize();
}
public function list(): ResponseInterface
{
/** @var array<string,mixed> $data */
$data = new PodcastModel()
->findAll();
array_map(static function (Podcast $podcast): void {
self::mapPodcast($podcast);
}, $data);
return $this->respond($data);
}
public function view(int $id): ResponseInterface
{
$podcast = new PodcastModel()
->getPodcastById($id);
if (! $podcast instanceof Podcast) {
return $this->failNotFound('Podcast not found');
}
// @phpstan-ignore-next-line
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);
}
$podcast->categories = $categories;
return $podcast;
}
}