feat: Begins breaking database out into it's own module, using dependencies
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import Dependencies
|
||||
import Foundation
|
||||
|
||||
public struct Employee: Equatable, Identifiable, Sendable {
|
||||
public struct Employee: Codable, Equatable, Identifiable, Sendable {
|
||||
public var id: UUID
|
||||
public var active: Bool
|
||||
public var createdAt: Date
|
||||
@@ -10,7 +10,7 @@ public struct Employee: Equatable, Identifiable, Sendable {
|
||||
public var updatedAt: Date
|
||||
|
||||
public init(
|
||||
id: UUID?,
|
||||
id: UUID? = nil,
|
||||
active: Bool = true,
|
||||
createdAt: Date? = nil,
|
||||
firstName: String,
|
||||
@@ -22,10 +22,20 @@ public struct Employee: Equatable, Identifiable, Sendable {
|
||||
|
||||
self.id = id ?? uuid()
|
||||
self.active = active
|
||||
self.createdAt = createdAt ?? date()
|
||||
self.createdAt = createdAt ?? date.now
|
||||
self.firstName = firstName
|
||||
self.lastName = lastName
|
||||
self.updatedAt = updatedAt ?? date()
|
||||
self.updatedAt = updatedAt ?? date.now
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public extension Employee {
|
||||
static var mocks: [Self] {
|
||||
[
|
||||
.init(firstName: "Michael", lastName: "Housh"),
|
||||
.init(firstName: "Blob", lastName: "Esquire"),
|
||||
.init(firstName: "Testy", lastName: "McTestface")
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
40
Sources/SharedModels/PurchaseOrder.swift
Normal file
40
Sources/SharedModels/PurchaseOrder.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
import Dependencies
|
||||
import Foundation
|
||||
|
||||
public struct PurchaseOrder: Codable, Equatable, Identifiable, Sendable {
|
||||
|
||||
public let id: Int
|
||||
public var workOrder: Int?
|
||||
public var materials: String
|
||||
public var customer: String
|
||||
public var truckStock: Bool
|
||||
public var createdBy: User
|
||||
public var createdFor: Employee
|
||||
public var vendorBranch: VendorBranch
|
||||
public var createdAt: Date?
|
||||
public var updatedAt: Date?
|
||||
|
||||
public init(
|
||||
id: Int,
|
||||
workOrder: Int? = nil,
|
||||
materials: String,
|
||||
customer: String,
|
||||
truckStock: Bool,
|
||||
createdBy: User,
|
||||
createdFor: Employee,
|
||||
vendorBranch: VendorBranch,
|
||||
createdAt: Date?,
|
||||
updatedAt: Date?
|
||||
) {
|
||||
self.id = id
|
||||
self.workOrder = workOrder
|
||||
self.materials = materials
|
||||
self.customer = customer
|
||||
self.truckStock = truckStock
|
||||
self.createdBy = createdBy
|
||||
self.createdFor = createdFor
|
||||
self.vendorBranch = vendorBranch
|
||||
self.createdAt = createdAt
|
||||
self.updatedAt = updatedAt
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import Dependencies
|
||||
import Foundation
|
||||
|
||||
public struct User: Identifiable, Codable, Sendable {
|
||||
public struct User: Codable, Equatable, Identifiable, Sendable {
|
||||
|
||||
public var id: UUID
|
||||
public var createdAt: Date
|
||||
@@ -20,9 +20,9 @@ public struct User: Identifiable, Codable, Sendable {
|
||||
@Dependency(\.uuid) var uuid
|
||||
|
||||
self.id = id ?? uuid()
|
||||
self.createdAt = createdAt ?? date()
|
||||
self.createdAt = createdAt ?? date.now
|
||||
self.email = email
|
||||
self.updatedAt = updatedAt ?? date()
|
||||
self.updatedAt = updatedAt ?? date.now
|
||||
self.username = username
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,38 @@
|
||||
import Dependencies
|
||||
import Foundation
|
||||
|
||||
public struct Vendor: Identifiable, Equatable, Sendable {
|
||||
public struct Vendor: Codable, Equatable, Identifiable, Sendable {
|
||||
public var id: UUID
|
||||
public var createdAt: Date
|
||||
public var name: String
|
||||
public var branches: [VendorBranch]?
|
||||
public var createdAt: Date
|
||||
public var updatedAt: Date
|
||||
|
||||
public init(
|
||||
id: UUID? = nil,
|
||||
createdAt: Date? = nil,
|
||||
name: String,
|
||||
branches: [VendorBranch]? = nil,
|
||||
createdAt: Date? = nil,
|
||||
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()
|
||||
self.branches = branches
|
||||
self.createdAt = createdAt ?? date.now
|
||||
self.updatedAt = updatedAt ?? date.now
|
||||
}
|
||||
}
|
||||
|
||||
public extension Vendor {
|
||||
|
||||
static var mocks: [Self] {
|
||||
[
|
||||
.init(name: "Corken"),
|
||||
.init(name: "Johnstone"),
|
||||
.init(name: "Winstel Controls")
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import Dependencies
|
||||
import Foundation
|
||||
|
||||
public struct VendorBranch: Codable, Equatable, Identifiable, Sendable {
|
||||
public var id: UUID
|
||||
public var name: String
|
||||
public var vendorID: Vendor.ID
|
||||
public var createdAt: Date
|
||||
public var updatedAt: Date
|
||||
|
||||
public init(
|
||||
id: UUID? = nil,
|
||||
name: String,
|
||||
vendorID: Vendor.ID,
|
||||
createdAt: Date? = nil,
|
||||
updatedAt: Date? = nil
|
||||
) {
|
||||
@Dependency(\.date) var date
|
||||
@Dependency(\.uuid) var uuid
|
||||
|
||||
self.id = id ?? uuid()
|
||||
self.name = name
|
||||
self.vendorID = vendorID
|
||||
self.createdAt = createdAt ?? date.now
|
||||
self.updatedAt = updatedAt ?? date.now
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user