feat: Updates api controllers to use database client.
This commit is contained in:
@@ -29,7 +29,6 @@ struct UserApiController: RouteCollection {
|
||||
@Sendable
|
||||
func create(req: Request) async throws -> User {
|
||||
// Allow the first user to be created without authentication.
|
||||
// let count = try await User.query(on: req.db).count()
|
||||
let count = try await users.count()
|
||||
if count > 0 {
|
||||
guard req.auth.get(User.self) != nil else {
|
||||
@@ -40,25 +39,14 @@ struct UserApiController: RouteCollection {
|
||||
}
|
||||
|
||||
@Sendable
|
||||
func login(req: Request) async throws -> User {
|
||||
func login(req: Request) async throws -> User.Token {
|
||||
let user = try req.auth.require(User.self)
|
||||
return user
|
||||
// return try await users.login(user)
|
||||
return try await users.token(user.id)
|
||||
}
|
||||
|
||||
// @Sendable
|
||||
// func get(req: Request) async throws -> User.DTO {
|
||||
// guard let id = req.parameters.get("id", as: User.IDValue.self),
|
||||
// let user = users.
|
||||
// }
|
||||
|
||||
@Sendable
|
||||
func delete(req: Request) async throws -> HTTPStatus {
|
||||
// guard let id = req.parameters.get("id", as: User.IDValue.self) else {
|
||||
// throw Abort(.badRequest, reason: "User id not provided")
|
||||
// }
|
||||
let id = try req.ensureIDPathComponent()
|
||||
try await users.delete(id)
|
||||
try await users.delete(req.ensureIDPathComponent())
|
||||
return .ok
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user