I have the following method of a controller:
def edit(bookId: Int): Action[AnyContent] = messagesAction {implicit request => {
val books = Book.getBookId(bookId)
if(books.nonEmpty) Ok(views.html.book.create(bookForm.fill(books.head)))
else NotFound("Book is not found.")
}}
But I'm not satisfied with how I'm doing this.
Actually, I would like to not test the emptiness of the list (the books val).
I tried something like :
def edit2(bookId: Int): Action[AnyContent] = messagesAction {implicit request => {
Book.getBookId(bookId).foreach(book => Ok(views.html.book.create(bookForm.fill(book))))
NotFound("Book is not found.")
}}
It does compile but I have the NOtFound redirection every time.
How could I do this?