116 lines
2.7 KiB
Swift
116 lines
2.7 KiB
Swift
import Dependencies
|
|
import Foundation
|
|
|
|
public struct Employee: Codable, 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,
|
|
firstName: String,
|
|
lastName: String,
|
|
updatedAt: Date
|
|
) {
|
|
self.id = id
|
|
self.active = active
|
|
self.createdAt = createdAt
|
|
self.firstName = firstName
|
|
self.lastName = lastName
|
|
self.updatedAt = updatedAt
|
|
}
|
|
|
|
public var fullName: String {
|
|
"\(firstName.capitalized) \(lastName.capitalized)"
|
|
}
|
|
}
|
|
|
|
public extension Employee {
|
|
struct Create: Codable, Sendable {
|
|
public let firstName: String
|
|
public let lastName: String
|
|
public let active: Bool?
|
|
|
|
public init(
|
|
firstName: String,
|
|
lastName: String,
|
|
active: Bool? = nil
|
|
) {
|
|
self.firstName = firstName
|
|
self.lastName = lastName
|
|
self.active = active
|
|
}
|
|
}
|
|
|
|
struct Update: Codable, Sendable {
|
|
public let firstName: String?
|
|
public let lastName: String?
|
|
public let active: Bool?
|
|
|
|
public init(
|
|
firstName: String? = nil,
|
|
lastName: String? = nil,
|
|
active: Bool? = nil
|
|
) {
|
|
self.firstName = firstName
|
|
self.lastName = lastName
|
|
self.active = active
|
|
}
|
|
}
|
|
}
|
|
|
|
#if DEBUG
|
|
//
|
|
// public extension Employee {
|
|
//
|
|
// static func generateMocks(count: Int = 10) -> [Self] {
|
|
// @Dependency(\.date.now) var now
|
|
// @Dependency(\.uuid) var uuid
|
|
//
|
|
// var output = [Self]()
|
|
//
|
|
// for _ in 0 ... count {
|
|
// output.append(.init(
|
|
// id: uuid(),
|
|
// active: Bool.random(),
|
|
// createdAt: now,
|
|
// firstName: RandomNames.firstNames.randomElement()!,
|
|
// lastName: RandomNames.lastNames.randomElement()!,
|
|
// updatedAt: now
|
|
// ))
|
|
// }
|
|
//
|
|
// return output
|
|
// }
|
|
// }
|
|
|
|
public extension Employee.Create {
|
|
|
|
static func generateMocks(count: Int = 5) -> [Self] {
|
|
(0 ... count).reduce(into: [Self]()) { array, _ in
|
|
array.append(.init(
|
|
firstName: RandomNames.firstNames.randomElement()! + String(RandomNames.characterString.randomElement()!),
|
|
lastName: RandomNames.lastNames.randomElement()! + String(RandomNames.characterString.randomElement()!),
|
|
active: Bool.random()
|
|
))
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|
|
// public extension Employee {
|
|
// static var mocks: [Self] {
|
|
// [
|
|
// .init(firstName: "Michael", lastName: "Housh"),
|
|
// .init(firstName: "Blob", lastName: "Esquire"),
|
|
// .init(firstName: "Testy", lastName: "McTestface")
|
|
// ]
|
|
// }
|
|
// }
|