From 193d1c5f7af3e0a0673e3377739769b886f22148 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Fri, 21 Nov 2014 11:27:51 +0100 Subject: [PATCH] Moved post content controller to routes --- .../Posts/GetPostContent.php} | 33 +++++------- src/Routes/Posts/GetPostThumbnail.php | 50 +++++++++++++++++++ src/di.php | 3 +- 3 files changed, 65 insertions(+), 21 deletions(-) rename src/{Controllers/PostContentController.php => Routes/Posts/GetPostContent.php} (52%) create mode 100644 src/Routes/Posts/GetPostThumbnail.php diff --git a/src/Controllers/PostContentController.php b/src/Routes/Posts/GetPostContent.php similarity index 52% rename from src/Controllers/PostContentController.php rename to src/Routes/Posts/GetPostContent.php index ae8c58d7..1c53007c 100644 --- a/src/Controllers/PostContentController.php +++ b/src/Routes/Posts/GetPostContent.php @@ -1,45 +1,45 @@ config = $config; $this->fileDao = $fileDao; $this->postService = $postService; $this->networkingService = $networkingService; - $this->postThumbnailService = $postThumbnailService; } - public function registerRoutes(Router $router) + public function getMethods() { - $router->get('/api/posts/:postName/content', [$this, 'getPostContent']); - $router->get('/api/posts/:postName/thumbnail/:size', [$this, 'getPostThumbnail']); + return ['GET']; } - public function getPostContent($postName) + public function getUrl() { - $post = $this->postService->getByName($postName); + return '/api/posts/:postName/content'; + } + + public function work() + { + $post = $this->postService->getByName($this->getArgument('postName')); $customFileName = sprintf('%s_%s.%s', $this->config->basic->serviceName, @@ -54,11 +54,4 @@ final class PostContentController extends AbstractController $this->networkingService->serveFile($this->fileDao->getFullPath($post->getContentPath()), $customFileName); } - - public function getPostThumbnail($postName, $size) - { - $post = $this->postService->getByName($postName); - $thumbnailName = $this->postThumbnailService->generateIfNeeded($post, $size, $size); - $this->networkingService->serveFile($this->fileDao->getFullPath($thumbnailName)); - } } diff --git a/src/Routes/Posts/GetPostThumbnail.php b/src/Routes/Posts/GetPostThumbnail.php new file mode 100644 index 00000000..253d662f --- /dev/null +++ b/src/Routes/Posts/GetPostThumbnail.php @@ -0,0 +1,50 @@ +config = $config; + $this->fileDao = $fileDao; + $this->postService = $postService; + $this->networkingService = $networkingService; + $this->postThumbnailService = $postThumbnailService; + } + + public function getMethods() + { + return ['GET']; + } + + public function getUrl() + { + return '/api/posts/:postName/thumbnail/:size'; + } + + public function work() + { + $size = $this->getArgument('size'); + $post = $this->postService->getByName($this->getArgument('postName')); + $thumbnailName = $this->postThumbnailService->generateIfNeeded($post, $size, $size); + $this->networkingService->serveFile($this->fileDao->getFullPath($thumbnailName)); + } +} diff --git a/src/di.php b/src/di.php index c71e2586..d2bb4c16 100644 --- a/src/di.php +++ b/src/di.php @@ -60,7 +60,6 @@ return [ $container->get(\Szurubooru\Controllers\UserController::class), $container->get(\Szurubooru\Controllers\UserAvatarController::class), $container->get(\Szurubooru\Controllers\PostController::class), - $container->get(\Szurubooru\Controllers\PostContentController::class), $container->get(\Szurubooru\Controllers\PostNotesController::class), $container->get(\Szurubooru\Controllers\ScoreController::class), $container->get(\Szurubooru\Controllers\TagController::class), @@ -80,6 +79,8 @@ return [ $container->get(\Szurubooru\Routes\Favorites\GetFavoriteUsers::class), $container->get(\Szurubooru\Routes\Favorites\AddToFavorites::class), $container->get(\Szurubooru\Routes\Favorites\RemoveFromFavorites::class), + $container->get(\Szurubooru\Routes\Posts\GetPostContent::class), + $container->get(\Szurubooru\Routes\Posts\GetPostThumbnail::class), ]; }), ];