/**
  * POST /comments
  * @param PostsInterface $postsInterface
  * @param CommentsTransformer $commentsTransformer
  * @return mixed
  */
 public function store(PostsInterface $postsInterface, CommentsTransformer $commentsTransformer)
 {
     validate(['post_id' => 'required|integer', 'content' => 'required']);
     $user = user();
     $post = $postsInterface->findPostWithException(inputGet('post_id'));
     $parentId = inputGet('parent_id');
     if ($parentId) {
         $parent = $this->commentsInterface->findCommentWithException($parentId);
     } else {
         $parent = null;
     }
     $comment = $this->commentsInterface->createComment($user, $post, inputGet('content'), $parent);
     return respondWithItem($comment, $commentsTransformer);
 }
Beispiel #2
0
 /**
  * 用户动态
  * GET /posts/user_timeline
  * @param PostsInterface $postInterface
  * @return mixed
  */
 public function getUserTimeline(PostsInterface $postInterface)
 {
     $maxId = maxId();
     $sinceId = sinceId();
     $pageSize = pageSize();
     $userId = inputGet('user_id');
     // if null
     if ($userId) {
         $data = $postInterface->getUserPosts($userId, $sinceId, $maxId, $pageSize);
         return respondWithCollection($data, new PostsTransformer());
     }
     $user = user();
     if (is_null($user)) {
         errorUnauthorized();
     }
     $data = $postInterface->getMyPosts($user->id, $sinceId, $maxId, $pageSize);
     return respondWithCollection($data, new MyPostsTransformer());
 }