diff --git a/src/Controllers/PostNotesController.php b/src/Controllers/PostNotesController.php deleted file mode 100644 index 83124ded..00000000 --- a/src/Controllers/PostNotesController.php +++ /dev/null @@ -1,77 +0,0 @@ -inputReader = $inputReader; - $this->postService = $postService; - $this->postNotesService = $postNotesService; - $this->privilegeService = $privilegeService; - $this->postNoteViewProxy = $postNoteViewProxy; - } - - public function registerRoutes(Router $router) - { - $router->get('/api/notes/:postNameOrId', [$this, 'getPostNotes']); - $router->post('/api/notes/:postNameOrId', [$this, 'addPostNote']); - $router->put('/api/notes/:postNoteId', [$this, 'editPostNote']); - $router->delete('/api/notes/:postNoteId', [$this, 'deletePostNote']); - } - - public function getPostNotes($postNameOrId) - { - $post = $this->postService->getByNameOrId($postNameOrId); - $postNotes = $this->postNotesService->getByPost($post); - return $this->postNoteViewProxy->fromArray($postNotes); - } - - public function addPostNote($postNameOrId) - { - $post = $this->postService->getByNameOrId($postNameOrId); - - $this->privilegeService->assertPrivilege(Privilege::ADD_POST_NOTES); - - $formData = new PostNoteFormData($this->inputReader); - $postNote = $this->postNotesService->createPostNote($post, $formData); - return $this->postNoteViewProxy->fromEntity($postNote); - } - - public function editPostNote($postNoteId) - { - $postNote = $this->postNotesService->getById($postNoteId); - - $this->privilegeService->assertPrivilege(Privilege::EDIT_POST_NOTES); - - $formData = new PostNoteFormData($this->inputReader); - $postNote = $this->postNotesService->updatePostNote($postNote, $formData); - return $this->postNoteViewProxy->fromEntity($postNote); - } - - public function deletePostNote($postNoteId) - { - $postNote = $this->postNotesService->getById($postNoteId); - $this->privilegeService->assertPrivilege(Privilege::DELETE_POST_NOTES); - return $this->postNotesService->deletePostNote($postNote); - } -} diff --git a/src/Routes/Posts/Notes/AddPostNote.php b/src/Routes/Posts/Notes/AddPostNote.php new file mode 100644 index 00000000..07d4e42c --- /dev/null +++ b/src/Routes/Posts/Notes/AddPostNote.php @@ -0,0 +1,54 @@ +inputReader = $inputReader; + $this->postService = $postService; + $this->postNotesService = $postNotesService; + $this->privilegeService = $privilegeService; + $this->postNoteViewProxy = $postNoteViewProxy; + } + + public function getMethods() + { + return ['POST']; + } + + public function getUrl() + { + return '/api/notes/:postNameOrId'; + } + + public function work() + { + $post = $this->postService->getByNameOrId($this->getArgument('postNameOrId')); + + $this->privilegeService->assertPrivilege(Privilege::ADD_POST_NOTES); + + $formData = new PostNoteFormData($this->inputReader); + $postNote = $this->postNotesService->createPostNote($post, $formData); + return $this->postNoteViewProxy->fromEntity($postNote); + } +} diff --git a/src/Routes/Posts/Notes/DeletePostNote.php b/src/Routes/Posts/Notes/DeletePostNote.php new file mode 100644 index 00000000..1579fb63 --- /dev/null +++ b/src/Routes/Posts/Notes/DeletePostNote.php @@ -0,0 +1,49 @@ +inputReader = $inputReader; + $this->postService = $postService; + $this->postNotesService = $postNotesService; + $this->privilegeService = $privilegeService; + $this->postNoteViewProxy = $postNoteViewProxy; + } + + public function getMethods() + { + return ['DELETE']; + } + + public function getUrl() + { + return '/api/notes/:postNoteId'; + } + + public function work() + { + $postNote = $this->postNotesService->getById($this->getArgument('postNoteId')); + $this->privilegeService->assertPrivilege(Privilege::DELETE_POST_NOTES); + return $this->postNotesService->deletePostNote($postNote); + } +} diff --git a/src/Routes/Posts/Notes/GetPostNotes.php b/src/Routes/Posts/Notes/GetPostNotes.php new file mode 100644 index 00000000..929dd75a --- /dev/null +++ b/src/Routes/Posts/Notes/GetPostNotes.php @@ -0,0 +1,49 @@ +inputReader = $inputReader; + $this->postService = $postService; + $this->postNotesService = $postNotesService; + $this->privilegeService = $privilegeService; + $this->postNoteViewProxy = $postNoteViewProxy; + } + + public function getMethods() + { + return ['GET']; + } + + public function getUrl() + { + return '/api/notes/:postNameOrId'; + } + + public function work() + { + $post = $this->postService->getByNameOrId($this->getArgument('postNameOrId')); + $postNotes = $this->postNotesService->getByPost($post); + return $this->postNoteViewProxy->fromArray($postNotes); + } +} diff --git a/src/Routes/Posts/Notes/UpdatePostNote.php b/src/Routes/Posts/Notes/UpdatePostNote.php new file mode 100644 index 00000000..11ee7825 --- /dev/null +++ b/src/Routes/Posts/Notes/UpdatePostNote.php @@ -0,0 +1,54 @@ +inputReader = $inputReader; + $this->postService = $postService; + $this->postNotesService = $postNotesService; + $this->privilegeService = $privilegeService; + $this->postNoteViewProxy = $postNoteViewProxy; + } + + public function getMethods() + { + return ['PUT']; + } + + public function getUrl() + { + return '/api/notes/:postNoteId'; + } + + public function work() + { + $postNote = $this->postNotesService->getById($this->getArgument('postNoteId')); + + $this->privilegeService->assertPrivilege(Privilege::EDIT_POST_NOTES); + + $formData = new PostNoteFormData($this->inputReader); + $postNote = $this->postNotesService->updatePostNote($postNote, $formData); + return $this->postNoteViewProxy->fromEntity($postNote); + } +} diff --git a/src/di.php b/src/di.php index 912237a7..5f671570 100644 --- a/src/di.php +++ b/src/di.php @@ -59,7 +59,6 @@ return [ return [ $container->get(\Szurubooru\Controllers\UserController::class), $container->get(\Szurubooru\Controllers\UserAvatarController::class), - $container->get(\Szurubooru\Controllers\PostNotesController::class), $container->get(\Szurubooru\Controllers\ScoreController::class), $container->get(\Szurubooru\Controllers\TagController::class), ]; @@ -87,6 +86,10 @@ return [ $container->get(\Szurubooru\Routes\Posts\GetPostThumbnail::class), $container->get(\Szurubooru\Routes\Posts\GetPosts::class), $container->get(\Szurubooru\Routes\Posts\UpdatePost::class), + $container->get(\Szurubooru\Routes\Posts\Notes\AddPostNote::class), + $container->get(\Szurubooru\Routes\Posts\Notes\DeletePostNote::class), + $container->get(\Szurubooru\Routes\Posts\Notes\GetPostNotes::class), + $container->get(\Szurubooru\Routes\Posts\Notes\UpdatePostNote::class), ]; }), ];