It's difficult to give you an answer using the code in your question, but hopefully this will give you enough pointers to get you going.
Create a structure to hold the information you want to send to the view from your query results to the View
. Make sure it is Encodable
. I haven't got a simple example using Future
, but something like the following could easily include [Future<Location>]
struct AllLocationsContext: Encodable {
let title: String
let hideInactiveLocations: Bool
let locations: [Location]
}
Then add a flatMap
to your query and embed both the creation of your parameters structure and the return
that creates the View
.
locations.get("/")
{
request -> Future<View> in
let title = "Events (Active and Inactive)"
return Location.query(on:request).sort(\.name).all().flatMap(to: View.self) {
locations in
let context = AllLocationsContext(title: title, hideInactiveLocations: hideInactiveLocations, locations: locations)
return try request.view().render("locations",context)
}
}