/** * 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); }
/** * @inheritDoc */ public function getThreads(ThreadListQuery $threadListQuery) { $repository = $this->repositories->threads(); $criteria = ['board' => $threadListQuery->getBoard()]; $limit = $threadListQuery->getSeek()->getLimit(); $offset = $threadListQuery->getSeek()->getOffset(); $threads = $repository->findBy($criteria, null, $limit, $offset); $countQuery = $repository->createQueryBuilder('t'); $countQuery->select('count(t.id)')->where('t.board = :board')->setParameter('board', $threadListQuery->getBoard()); $total = (int) $countQuery->getQuery()->getSingleScalarResult(); return new QueryList($threads, $total); }