83 lines
1.9 KiB
Swift
83 lines
1.9 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, Equatable {
|
|
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, Equatable {
|
|
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.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
|