func userHandler(_ req: Request) throws -> Future<View> {
// 2
return try req.parameters.next(User.self)
.flatMap(to: View.self) { user in
// 3
return try user.acronyms
.query(on: req)
.all()
.flatMap(to: View.self) { acronyms in
// 4
let context = UserContext(
title: user.name,
user: user,
acronyms: acronyms)
return try req.view().render("user", context)
}
} }
In this code example, flatMap(to: View.self) happens twice. I was wondering why and if that is needed? I understand that you need to unwrap the user, and then unwrap the acronyms. But do both need to be flatMapped to a View.self? Thank you.