feat: Begins integrating database client into vapor app.
This commit is contained in:
@@ -2,11 +2,13 @@ import Dependencies
|
||||
import DependenciesMacros
|
||||
import Foundation
|
||||
import SharedModels
|
||||
import Vapor
|
||||
|
||||
public extension DatabaseClient {
|
||||
|
||||
@DependencyClient
|
||||
struct Users: Sendable {
|
||||
public var count: @Sendable () async throws -> Int
|
||||
public var create: @Sendable (User.Create) async throws -> User
|
||||
public var delete: @Sendable (User.ID) async throws -> Void
|
||||
public var fetchAll: @Sendable () async throws -> [User]
|
||||
@@ -16,61 +18,12 @@ public extension DatabaseClient {
|
||||
}
|
||||
}
|
||||
|
||||
public extension DatabaseClient.Users {
|
||||
enum AuthRequest {
|
||||
case basic(BasicAuthorization)
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseClient.Users: TestDependencyKey {
|
||||
public static let testValue: DatabaseClient.Users = Self()
|
||||
}
|
||||
|
||||
public extension User {
|
||||
|
||||
struct Create: Codable, Sendable {
|
||||
public let username: String
|
||||
public let email: String
|
||||
public let password: String
|
||||
public let confirmPassword: String
|
||||
|
||||
public init(
|
||||
username: String,
|
||||
email: String,
|
||||
password: String,
|
||||
confirmPassword: String
|
||||
) {
|
||||
self.username = username
|
||||
self.email = email
|
||||
self.password = password
|
||||
self.confirmPassword = confirmPassword
|
||||
}
|
||||
}
|
||||
|
||||
struct Login: Codable, Sendable {
|
||||
public let username: String?
|
||||
public let email: String?
|
||||
public let password: String
|
||||
|
||||
public init(
|
||||
username: String?,
|
||||
email: String? = nil,
|
||||
password: String
|
||||
) {
|
||||
self.username = username
|
||||
self.email = email
|
||||
self.password = password
|
||||
}
|
||||
}
|
||||
|
||||
struct Token: Codable, Equatable, Identifiable, Sendable {
|
||||
public let id: UUID
|
||||
public let userID: User.ID
|
||||
public let value: String
|
||||
|
||||
public init(
|
||||
id: UUID,
|
||||
userID: User.ID,
|
||||
value: String
|
||||
) {
|
||||
self.id = id
|
||||
self.userID = userID
|
||||
self.value = value
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user