Moved post scoring to API

This commit is contained in:
Marcin Kurczewski 2014-05-03 19:50:35 +02:00
parent 2eaab49d35
commit ee79e1753e
3 changed files with 36 additions and 10 deletions

View file

@ -93,6 +93,7 @@ $postValidation =
\Chibi\Router::register(['PostController', 'unhideAction'], 'POST', '/post/{id}/unhide', $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', 'removeFavoriteAction'], 'POST', '/post/{id}/rem-fav', $postValidation);
\Chibi\Router::register(['PostController', 'addFavoriteAction'], 'POST', '/post/{id}/add-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');
\Chibi\Router::register(['CommentController', 'listView'], 'GET', '/comments/{page}', ['page' => '\d+']); \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', 'retrieveAction'], $method, '/post/{name}/retrieve', $postValidation);
\Chibi\Router::register(['PostController', 'thumbAction'], $method, '/post/{name}/thumb', $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', 'featureAction'], $method, '/post/{id}/feature', $postValidation);
\Chibi\Router::register(['PostController', 'scoreAction'], $method, '/post/{id}/score/{score}', $postValidation);
$tagValidation = $tagValidation =
[ [

View file

@ -207,15 +207,9 @@ class PostController
public function scoreAction($id, $score) public function scoreAction($id, $score)
{ {
$context = getContext(); Api::run(new ScorePostJob(), [
$post = PostModel::findByIdOrName($id); ScorePostJob::POST_ID => $id,
Access::assert(Privilege::ScorePost, Access::getIdentity($post->getUploader())); ScorePostJob::SCORE => $score]);
Access::assertAuthentication();
if (!InputHelper::get('submit'))
return;
UserModel::updateUserScore(Auth::getCurrentUser(), $post, $score);
} }
public function featureAction($id) public function featureAction($id)

32
src/Jobs/ScorePostJob.php Normal file
View 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;
}
}