feat: Reorganizing views

This commit is contained in:
2025-01-08 18:10:26 -05:00
parent f5dbd7e121
commit e414afd95b
20 changed files with 55 additions and 61 deletions

View File

@@ -37,7 +37,7 @@ struct ViewController: RouteCollection {
}
@Sendable
func postLogin(req: Request) async throws -> View {
func postLogin(req: Request) async throws -> Response {
let content = try req.content.decode(UserForm.self)
guard let user = try await User.query(on: req.db)
.filter(\.$username == content.username)
@@ -62,18 +62,11 @@ struct ViewController: RouteCollection {
}
@Sendable
func home(req: Request) async throws -> View {
var route: HomeRoute?
if let loginParams = try? req.query.decode(LoginParameter.self),
let next = loginParams.next.split(separator: "/").last
{
route = HomeRoute(rawValue: String(next))
} else if let routeString = req.parameters.getCatchall().first {
route = HomeRoute(rawValue: routeString)
func home(req: Request) async throws -> Response {
if let loginParams = try? req.query.decode(LoginParameter.self) {
return req.redirect(to: loginParams.next)
}
return try await req.view.render("home", HomeCTX(route: route))
return try await req.view.render("home").encodeResponse(for: req)
}
@Sendable