Moved post scoring to API
This commit is contained in:
parent
2eaab49d35
commit
ee79e1753e
3 changed files with 36 additions and 10 deletions
|
@ -93,6 +93,7 @@ $postValidation =
|
|||
\Chibi\Router::register(['PostController', 'unhideAction'], 'POST', '/post/{id}/unhide', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'removeFavoriteAction'], 'POST', '/post/{id}/rem-fav', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'addFavoriteAction'], 'POST', '/post/{id}/add-fav', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'scoreAction'], 'POST', '/post/{id}/score/{score}', $postValidation);
|
||||
|
||||
\Chibi\Router::register(['CommentController', 'listView'], 'GET', '/comments');
|
||||
\Chibi\Router::register(['CommentController', 'listView'], 'GET', '/comments/{page}', ['page' => '\d+']);
|
||||
|
@ -107,7 +108,6 @@ foreach (['GET', 'POST'] as $method)
|
|||
\Chibi\Router::register(['PostController', 'retrieveAction'], $method, '/post/{name}/retrieve', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'thumbAction'], $method, '/post/{name}/thumb', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'featureAction'], $method, '/post/{id}/feature', $postValidation);
|
||||
\Chibi\Router::register(['PostController', 'scoreAction'], $method, '/post/{id}/score/{score}', $postValidation);
|
||||
|
||||
$tagValidation =
|
||||
[
|
||||
|
|
|
@ -207,15 +207,9 @@ class PostController
|
|||
|
||||
public function scoreAction($id, $score)
|
||||
{
|
||||
$context = getContext();
|
||||
$post = PostModel::findByIdOrName($id);
|
||||
Access::assert(Privilege::ScorePost, Access::getIdentity($post->getUploader()));
|
||||
Access::assertAuthentication();
|
||||
|
||||
if (!InputHelper::get('submit'))
|
||||
return;
|
||||
|
||||
UserModel::updateUserScore(Auth::getCurrentUser(), $post, $score);
|
||||
Api::run(new ScorePostJob(), [
|
||||
ScorePostJob::POST_ID => $id,
|
||||
ScorePostJob::SCORE => $score]);
|
||||
}
|
||||
|
||||
public function featureAction($id)
|
||||
|
|
32
src/Jobs/ScorePostJob.php
Normal file
32
src/Jobs/ScorePostJob.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
class ScorePostJob extends AbstractPostEditJob
|
||||
{
|
||||
const SCORE = 'score';
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$post = $this->post;
|
||||
$score = intval($this->getArgument(self::SCORE));
|
||||
|
||||
UserModel::updateUserScore(Auth::getCurrentUser(), $post, $score);
|
||||
}
|
||||
|
||||
public function requiresPrivilege()
|
||||
{
|
||||
return
|
||||
[
|
||||
Privilege::ScorePost,
|
||||
Access::getIdentity($this->post->getUploader())
|
||||
];
|
||||
}
|
||||
|
||||
public function requiresAuthentication()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function requiresConfirmedEmail()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue