Moved post notes controller to routes
This commit is contained in:
parent
d8a4e1ec4e
commit
9de6e7e739
6 changed files with 210 additions and 78 deletions
|
@ -1,77 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Szurubooru\Controllers;
|
|
||||||
use Szurubooru\Controllers\ViewProxies\PostNoteViewProxy;
|
|
||||||
use Szurubooru\FormData\PostNoteFormData;
|
|
||||||
use Szurubooru\Helpers\InputReader;
|
|
||||||
use Szurubooru\Privilege;
|
|
||||||
use Szurubooru\Router;
|
|
||||||
use Szurubooru\Services\PostNotesService;
|
|
||||||
use Szurubooru\Services\PostService;
|
|
||||||
use Szurubooru\Services\PrivilegeService;
|
|
||||||
|
|
||||||
final class PostNotesController extends AbstractController
|
|
||||||
{
|
|
||||||
private $inputReader;
|
|
||||||
private $postService;
|
|
||||||
private $postNotesService;
|
|
||||||
private $privilegeService;
|
|
||||||
private $postNoteViewProxy;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
InputReader $inputReader,
|
|
||||||
PostService $postService,
|
|
||||||
PostNotesService $postNotesService,
|
|
||||||
PrivilegeService $privilegeService,
|
|
||||||
PostNoteViewProxy $postNoteViewProxy)
|
|
||||||
{
|
|
||||||
$this->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);
|
|
||||||
}
|
|
||||||
}
|
|
54
src/Routes/Posts/Notes/AddPostNote.php
Normal file
54
src/Routes/Posts/Notes/AddPostNote.php
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
namespace Szurubooru\Routes\Posts\Notes;
|
||||||
|
use Szurubooru\Controllers\ViewProxies\PostNoteViewProxy;
|
||||||
|
use Szurubooru\FormData\PostNoteFormData;
|
||||||
|
use Szurubooru\Helpers\InputReader;
|
||||||
|
use Szurubooru\Privilege;
|
||||||
|
use Szurubooru\Routes\Posts\AbstractPostRoute;
|
||||||
|
use Szurubooru\Services\PostNotesService;
|
||||||
|
use Szurubooru\Services\PostService;
|
||||||
|
use Szurubooru\Services\PrivilegeService;
|
||||||
|
|
||||||
|
class AddPostNote extends AbstractPostRoute
|
||||||
|
{
|
||||||
|
private $inputReader;
|
||||||
|
private $postService;
|
||||||
|
private $postNotesService;
|
||||||
|
private $privilegeService;
|
||||||
|
private $postNoteViewProxy;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
InputReader $inputReader,
|
||||||
|
PostService $postService,
|
||||||
|
PostNotesService $postNotesService,
|
||||||
|
PrivilegeService $privilegeService,
|
||||||
|
PostNoteViewProxy $postNoteViewProxy)
|
||||||
|
{
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
49
src/Routes/Posts/Notes/DeletePostNote.php
Normal file
49
src/Routes/Posts/Notes/DeletePostNote.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
namespace Szurubooru\Routes\Posts\Notes;
|
||||||
|
use Szurubooru\Controllers\ViewProxies\PostNoteViewProxy;
|
||||||
|
use Szurubooru\Helpers\InputReader;
|
||||||
|
use Szurubooru\Privilege;
|
||||||
|
use Szurubooru\Routes\Posts\AbstractPostRoute;
|
||||||
|
use Szurubooru\Services\PostNotesService;
|
||||||
|
use Szurubooru\Services\PostService;
|
||||||
|
use Szurubooru\Services\PrivilegeService;
|
||||||
|
|
||||||
|
class DeletePostNote extends AbstractPostRoute
|
||||||
|
{
|
||||||
|
private $inputReader;
|
||||||
|
private $postService;
|
||||||
|
private $postNotesService;
|
||||||
|
private $privilegeService;
|
||||||
|
private $postNoteViewProxy;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
InputReader $inputReader,
|
||||||
|
PostService $postService,
|
||||||
|
PostNotesService $postNotesService,
|
||||||
|
PrivilegeService $privilegeService,
|
||||||
|
PostNoteViewProxy $postNoteViewProxy)
|
||||||
|
{
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
49
src/Routes/Posts/Notes/GetPostNotes.php
Normal file
49
src/Routes/Posts/Notes/GetPostNotes.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
namespace Szurubooru\Routes\Posts\Notes;
|
||||||
|
use Szurubooru\Controllers\ViewProxies\PostNoteViewProxy;
|
||||||
|
use Szurubooru\Helpers\InputReader;
|
||||||
|
use Szurubooru\Privilege;
|
||||||
|
use Szurubooru\Routes\Posts\AbstractPostRoute;
|
||||||
|
use Szurubooru\Services\PostNotesService;
|
||||||
|
use Szurubooru\Services\PostService;
|
||||||
|
use Szurubooru\Services\PrivilegeService;
|
||||||
|
|
||||||
|
class GetPostNotes extends AbstractPostRoute
|
||||||
|
{
|
||||||
|
private $inputReader;
|
||||||
|
private $postService;
|
||||||
|
private $postNotesService;
|
||||||
|
private $privilegeService;
|
||||||
|
private $postNoteViewProxy;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
InputReader $inputReader,
|
||||||
|
PostService $postService,
|
||||||
|
PostNotesService $postNotesService,
|
||||||
|
PrivilegeService $privilegeService,
|
||||||
|
PostNoteViewProxy $postNoteViewProxy)
|
||||||
|
{
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
54
src/Routes/Posts/Notes/UpdatePostNote.php
Normal file
54
src/Routes/Posts/Notes/UpdatePostNote.php
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
namespace Szurubooru\Routes\Posts\Notes;
|
||||||
|
use Szurubooru\Controllers\ViewProxies\PostNoteViewProxy;
|
||||||
|
use Szurubooru\FormData\PostNoteFormData;
|
||||||
|
use Szurubooru\Helpers\InputReader;
|
||||||
|
use Szurubooru\Privilege;
|
||||||
|
use Szurubooru\Routes\Posts\AbstractPostRoute;
|
||||||
|
use Szurubooru\Services\PostNotesService;
|
||||||
|
use Szurubooru\Services\PostService;
|
||||||
|
use Szurubooru\Services\PrivilegeService;
|
||||||
|
|
||||||
|
class UpdatePostNote extends AbstractPostRoute
|
||||||
|
{
|
||||||
|
private $inputReader;
|
||||||
|
private $postService;
|
||||||
|
private $postNotesService;
|
||||||
|
private $privilegeService;
|
||||||
|
private $postNoteViewProxy;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
InputReader $inputReader,
|
||||||
|
PostService $postService,
|
||||||
|
PostNotesService $postNotesService,
|
||||||
|
PrivilegeService $privilegeService,
|
||||||
|
PostNoteViewProxy $postNoteViewProxy)
|
||||||
|
{
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -59,7 +59,6 @@ return [
|
||||||
return [
|
return [
|
||||||
$container->get(\Szurubooru\Controllers\UserController::class),
|
$container->get(\Szurubooru\Controllers\UserController::class),
|
||||||
$container->get(\Szurubooru\Controllers\UserAvatarController::class),
|
$container->get(\Szurubooru\Controllers\UserAvatarController::class),
|
||||||
$container->get(\Szurubooru\Controllers\PostNotesController::class),
|
|
||||||
$container->get(\Szurubooru\Controllers\ScoreController::class),
|
$container->get(\Szurubooru\Controllers\ScoreController::class),
|
||||||
$container->get(\Szurubooru\Controllers\TagController::class),
|
$container->get(\Szurubooru\Controllers\TagController::class),
|
||||||
];
|
];
|
||||||
|
@ -87,6 +86,10 @@ return [
|
||||||
$container->get(\Szurubooru\Routes\Posts\GetPostThumbnail::class),
|
$container->get(\Szurubooru\Routes\Posts\GetPostThumbnail::class),
|
||||||
$container->get(\Szurubooru\Routes\Posts\GetPosts::class),
|
$container->get(\Szurubooru\Routes\Posts\GetPosts::class),
|
||||||
$container->get(\Szurubooru\Routes\Posts\UpdatePost::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),
|
||||||
];
|
];
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in a new issue