I am working on a PlayFramework application written in Scala.
Problem is that in a rest controller I need a list of elements (books) and for each element list of its subelements (chapters).
Book repository:
def findAll(): Future[Seq[Book]]
Chapter repository:
def findByBookId(bookId: UUID): Future[Seq[Chapter]]
I wanted to do something like
val books = bookRepository.findAll
val result = for {
bookList <- books
book <- bookList
chapters <- chapterRepository.findByBookdId(book.id)
} yield (book, chapters)
I want to have a tuple of book and its chapters so I can latter map it to a json. What I am doing wrong, because I get error:
[error] required: scala.collection.GenTraversableOnce[?]
Or what would be a better approach how to iterate over future of collection and for each element load another future of collection?