feat: Begins moving models into their own module.

This commit is contained in:
2025-01-12 22:43:25 -05:00
parent 8228b1dfff
commit 540b3e771a
5 changed files with 99 additions and 0 deletions

View File

@@ -42,6 +42,12 @@ let package = Package(
.product(name: "VaporTesting", package: "vapor") .product(name: "VaporTesting", package: "vapor")
], ],
swiftSettings: swiftSettings swiftSettings: swiftSettings
),
.target(
name: "SharedModels",
dependencies: [
.product(name: "Dependencies", package: "swift-dependencies")
]
) )
], ],
swiftLanguageModes: [.v5] swiftLanguageModes: [.v5]

View File

@@ -0,0 +1,31 @@
import Dependencies
import Foundation
public struct Employee: Equatable, Identifiable, Sendable {
public var id: UUID
public var active: Bool
public var createdAt: Date
public var firstName: String
public var lastName: String
public var updatedAt: Date
public init(
id: UUID?,
active: Bool = true,
createdAt: Date? = nil,
firstName: String,
lastName: String,
updatedAt: Date? = nil
) {
@Dependency(\.date) var date
@Dependency(\.uuid) var uuid
self.id = id ?? uuid()
self.active = active
self.createdAt = createdAt ?? date()
self.firstName = firstName
self.lastName = lastName
self.updatedAt = updatedAt ?? date()
}
}

View File

@@ -0,0 +1,38 @@
import Dependencies
import Foundation
public struct User: Identifiable, Codable, Sendable {
public var id: UUID
public var createdAt: Date
public var email: String
public var updatedAt: Date
public var username: String
public init(
id: UUID? = nil,
createdAt: Date? = nil,
email: String,
updatedAt: Date? = nil,
username: String
) {
@Dependency(\.date) var date
@Dependency(\.uuid) var uuid
self.id = id ?? uuid()
self.createdAt = createdAt ?? date()
self.email = email
self.updatedAt = updatedAt ?? date()
self.username = username
}
}
public extension User {
static var mocks: [Self] {
[
.init(email: "blob@test.com", username: "blob"),
.init(email: "blob-jr@test.com", username: "blob-jr"),
.init(email: "blob-sr@test.com", username: "blob-sr")
]
}
}

View File

@@ -0,0 +1,24 @@
import Dependencies
import Foundation
public struct Vendor: Identifiable, Equatable, Sendable {
public var id: UUID
public var createdAt: Date
public var name: String
public var updatedAt: Date
public init(
id: UUID? = nil,
createdAt: Date? = nil,
name: String,
updatedAt: Date? = nil
) {
@Dependency(\.date) var date
@Dependency(\.uuid) var uuid
self.id = id ?? uuid()
self.createdAt = createdAt ?? date()
self.name = name
self.updatedAt = updatedAt ?? date()
}
}

View File