feat: Updates to use swift-validations for database.
All checks were successful
CI / Linux Tests (push) Successful in 6m28s

This commit is contained in:
2026-02-01 00:55:44 -05:00
parent a3fb87f86e
commit 9276f88426
20 changed files with 667 additions and 361 deletions

View File

@@ -1,6 +1,7 @@
import Dependencies
import DependenciesMacros
import Fluent
import Foundation
import ManualDCore
import Vapor
@@ -10,6 +11,7 @@ extension DatabaseClient.Users: TestDependencyKey {
public static func live(database: any Database) -> Self {
.init(
create: { request in
try request.validate()
let model = try request.toModel()
try await model.save(on: database)
return try model.toDTO()
@@ -118,21 +120,8 @@ extension User {
extension User.Create {
func toModel() throws -> UserModel {
try validate()
return try .init(email: email, passwordHash: User.hashPassword(password))
}
func validate() throws {
guard !email.isEmpty else {
throw ValidationError("Email should not be empty")
}
guard password.count > 8 else {
throw ValidationError("Password should be more than 8 characters long.")
}
guard password == confirmPassword else {
throw ValidationError("Passwords do not match.")
}
}
}
final class UserModel: Model, @unchecked Sendable {