Skip to content

Commit

Permalink
Small adjustments to structure and add middleware to movie poster routes
Browse files Browse the repository at this point in the history
  • Loading branch information
leepeuker committed Nov 12, 2023
1 parent de102cc commit 1f77d27
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
14 changes: 10 additions & 4 deletions settings/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ function addWebRoutes(RouterService $routerService, FastRoute\RouteCollector $ro
$routes->add('PUT', '/settings/radarr/feed', [RadarrController::class, 'regenerateRadarrFeedUrl'], [Web\Middleware\UserIsAuthenticated::class]);
$routes->add('DELETE', '/settings/radarr/feed', [RadarrController::class, 'deleteRadarrFeedUrl'], [Web\Middleware\UserIsAuthenticated::class]);


##########
# Movies #
##########
Expand All @@ -160,8 +159,15 @@ function addWebRoutes(RouterService $routerService, FastRoute\RouteCollector $ro
$routes->add('GET', '/movies/{id:[0-9]+}/watch-providers', [Web\Movie\MovieWatchProviderController::class, 'getWatchProviders']);
$routes->add('GET', '/movies/{id:[0-9]+}/add-watchlist', [Web\Movie\MovieWatchlistController::class, 'addToWatchlist'], [Web\Middleware\UserIsAuthenticated::class]);
$routes->add('GET', '/movies/{id:[0-9]+}/remove-watchlist', [Web\Movie\MovieWatchlistController::class, 'removeFromWatchlist'], [Web\Middleware\UserIsAuthenticated::class]);
$routes->add('GET', '/movies/{id:[0-9]+}/search-posters', [Web\Movie\MovieController::class, 'getPosters']);
$routes->add('PUT', '/movies/{id:[0-9]+}/update-poster', [Web\Movie\MovieController::class, 'updatePoster']);
$routes->add('GET', '/movies/{id:[0-9]+}/search-posters', [Web\Movie\MovieController::class, 'searchPosters'], [
Web\Middleware\UserIsAuthenticated::class,
Web\Middleware\UserIsAdmin::class
]);
$routes->add('PUT', '/movies/{id:[0-9]+}/update-poster', [Web\Movie\MovieController::class, 'updatePoster'], [
Web\Middleware\UserIsAuthenticated::class,
Web\Middleware\UserIsAdmin::class
]);

##########
# Person #
##########
Expand Down Expand Up @@ -228,7 +234,7 @@ function addApiRoutes(RouterService $routerService, FastRoute\RouteCollector $ro
$routes->add('POST', '/webhook/jellyfin/{id:.+}', [Api\JellyfinController::class, 'handleJellyfinWebhook']);
$routes->add('POST', '/webhook/emby/{id:.+}', [Api\EmbyController::class, 'handleEmbyWebhook']);

$routes->add('GET', '/feed/radarr/{id:.+}', [Api\RadarrController::class, 'renderRadarrFeed']);
$routes->add('GET', '/feed/radarr/{id:.+}', [Api\RadarrController::class, 'renderRadarrFeed']);

$routerService->addRoutesToRouteCollector($routeCollector, $routes);
}
20 changes: 13 additions & 7 deletions src/HttpController/Web/Movie/MovieController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,34 +105,40 @@ public function renderPage(Request $request) : Response
);
}

public function getPosters(Request $request) : Response
public function searchPosters(Request $request) : Response
{
$movieId = (int)$request->getRouteParameters()['id'];

$movie = $this->movieApi->findById($movieId);
if($movie === null) {
if ($movie === null) {
return Response::createNotFound();
}

$tmdbId = $movie->getTmdbId();
if($tmdbId === null) {
return Response::createBadRequest();
}

$images = $this->tmdbApi->getImages($tmdbId)['posters'];

return Response::createJson(Json::encode($images));
}

public function updatePoster(Request $request) : Response
{
$movieId = (int)$request->getRouteParameters()['id'];

$movie = $this->movieApi->findById($movieId);
if($movie === null) {
if ($movie === null) {
return Response::createNotFound();
}

$posterFilepath = $request->getBody();
$oldPosterPath = $movie->getPosterPath();
if($posterFilepath === $movie->getTmdbPosterPath()) {

if ($posterFilepath === $movie->getTmdbPosterPath()) {
return Response::createBadRequest();
}

$this->movieApi->updatePosterPath($movieId, $posterFilepath, $oldPosterPath);

return Response::createOk();
}
}

0 comments on commit 1f77d27

Please sign in to comment.