/** * Returns thread feed * @param $threadId * @return Ok * @throws NotFoundException */ public function getFeed($threadId) { $formatter = new ThreadFeedFormatter(); try { $thread = $this->threadRepository->getThreadById($threadId); return new Ok($formatter->format($thread)); } catch (\OutOfBoundsException $e) { throw new NotFoundException($e->getMessage()); } }
/** * Returns threads by board * @param $boardId * @param SeekableInterface $seek * @return Ok */ public function getByBoardId($boardId, SeekableInterface $seek) { $board = $this->boardRepository->getBoardById($boardId); $threadsQuery = new ThreadListQuery($board, $seek); $threadsQuery->withAllPosts(); $threadsQueryList = $this->threadRepository->getThreads($threadsQuery); $jsonResponse = ['items' => [], 'total' => $threadsQueryList->getTotal()]; foreach ($threadsQueryList->getItems() as $thread) { $jsonResponse['items'][] = $this->convertThreadToJSON($thread); } return new Ok($jsonResponse); }
/** * Reply to thread * @param ThreadReplyQuery $replyQuery * @throws \Exception */ public function reply(ThreadReplyQuery $replyQuery) { $em = $this->entityManager; $em->beginTransaction(); try { $post = $replyQuery->getPost(); $thread = $this->threadRepository->getThreadById($replyQuery->getThreadId()); $thread->getPosts()->add($post); $uploadQuery = $this->uploadService->createQuery($replyQuery->getPost(), $replyQuery->getUploadFiles()); $uploadQuery->validate(); $em->persist($post); $em->flush(); $post->setAttachments(array_merge_recursive($post->getAttachments(), $uploadQuery->process())); $em->persist($post); $em->flush(); $em->commit(); } catch (Exception $e) { $em->rollback(); throw $e; } }