November 2018
Intermediate to advanced
404 pages
10h 16m
English
Define a new path that lists all the accounts:
let accountsPage = "/journal/account/all"
Create the new AccountsContext Encodable context for the getAccounts() handler:
struct AccountsContext : Encodable { let isAdmin: Bool let title: String let author: String let count: String let admins: [Admin]}
The context contains all the information required by the accounts.leaf template.
Continue to implement the getAccounts() handler:
func getAccounts(_ req: Request) throws -> Future<View> { return Admin.query(on: req).all().flatMap(to: View.self) { admins in let isAdmin = try req.isAuthenticated(Admin.self) let context = AccountsContext(isAdmin: isAdmin, title: self.title, author: self.author, count: String(admins.count), admins: ...Read now
Unlock full access