feat: Adds middleware to routes
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
import DatabaseClient
|
||||
import DatabaseClientLive
|
||||
import Dependencies
|
||||
import Fluent
|
||||
import SharedModels
|
||||
import Vapor
|
||||
|
||||
private let apiMiddleware: [any Middleware] = [
|
||||
UserPasswordAuthenticator(),
|
||||
UserTokenAuthenticator(),
|
||||
User.guardMiddleware()
|
||||
]
|
||||
|
||||
extension ApiRoute {
|
||||
var middleware: [any Middleware]? { apiMiddleware }
|
||||
|
||||
func handle(request: Request) async throws -> any AsyncResponseEncodable {
|
||||
switch self {
|
||||
case let .employee(route):
|
||||
@@ -22,6 +30,7 @@ extension ApiRoute {
|
||||
}
|
||||
|
||||
extension ApiRoute.EmployeeApiRoute {
|
||||
|
||||
func handle(request: Request) async throws -> any AsyncResponseEncodable {
|
||||
@Dependency(\.database) var database
|
||||
switch self {
|
||||
@@ -44,6 +53,7 @@ extension ApiRoute.EmployeeApiRoute {
|
||||
}
|
||||
|
||||
extension ApiRoute.PurchaseOrderApiRoute {
|
||||
|
||||
func handle(request: Request) async throws -> any AsyncResponseEncodable {
|
||||
@Dependency(\.database.purchaseOrders) var purchaseOrders
|
||||
switch self {
|
||||
@@ -67,6 +77,7 @@ extension ApiRoute.PurchaseOrderApiRoute {
|
||||
|
||||
// TODO: Add Login.
|
||||
extension ApiRoute.UserApiRoute {
|
||||
|
||||
func handle(request: Request) async throws -> any AsyncResponseEncodable {
|
||||
@Dependency(\.database.users) var users
|
||||
switch self {
|
||||
|
||||
Reference in New Issue
Block a user