/**
  * Returns thread by Id
  * @param $id
  * @return Ok
  * @throws NotFoundException
  */
 public function getById($id)
 {
     try {
         $thread = $this->threadRepository->getThreadById($id);
     } catch (\OutOfBoundsException $e) {
         throw new NotFoundException($e->getMessage());
     }
     return new Ok($this->convertThreadToJSON($thread));
 }
 /**
  * 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());
     }
 }
 /**
  * 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;
     }
 }