Added the catalogue models and seed to support phase 3 of the POC prototype in the Persistence package.
This commit is contained in:
1 parent
43dcc03da6
commit
b1ceed7790
20 files changed
+2035
-8
No files matched your search
@@ -0,0 +1,116 @@
|
||||
import FluentKit
|
||||
import Foundation
|
||||
|
||||
/// A FluentKit model of a single `sales` row: the record of an agreement and of its handshake.
|
||||
final class SaleRecord: Model, @unchecked Sendable {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
static let schema = "sales"
|
||||
|
||||
@ID(key: .id)
|
||||
var id: UUID?
|
||||
|
||||
@Field(key: "number")
|
||||
var number: Int
|
||||
|
||||
@Parent(key: "conversation_id")
|
||||
var conversation: ConversationRecord
|
||||
|
||||
@Parent(key: "listing_id")
|
||||
var listing: ListingRecord
|
||||
|
||||
@Parent(key: "buyer_id")
|
||||
var buyer: UserRecord
|
||||
|
||||
@Parent(key: "seller_id")
|
||||
var seller: UserRecord
|
||||
|
||||
@Field(key: "price_cents")
|
||||
var priceCents: Int
|
||||
|
||||
@Field(key: "asked_cents")
|
||||
var askedCents: Int
|
||||
|
||||
@Field(key: "shipping_cents")
|
||||
var shippingCents: Int
|
||||
|
||||
@Field(key: "declared_grade")
|
||||
var declaredGrade: String
|
||||
|
||||
@OptionalField(key: "declared_page_quality")
|
||||
var declaredPageQuality: String?
|
||||
|
||||
@Field(key: "declared_printing")
|
||||
var declaredPrinting: String
|
||||
|
||||
@Field(key: "declared_notes")
|
||||
var declaredNotes: String
|
||||
|
||||
@Field(key: "agreed_at")
|
||||
var agreedAt: Date
|
||||
|
||||
@OptionalField(key: "paid_at")
|
||||
var paidAt: Date?
|
||||
|
||||
@OptionalField(key: "payment_note")
|
||||
var paymentNote: String?
|
||||
|
||||
@OptionalField(key: "sent_at")
|
||||
var sentAt: Date?
|
||||
|
||||
@OptionalField(key: "shipping_note")
|
||||
var shippingNote: String?
|
||||
|
||||
@OptionalField(key: "received_at")
|
||||
var receivedAt: Date?
|
||||
|
||||
@OptionalField(key: "buyer_rating")
|
||||
var buyerRating: Int?
|
||||
|
||||
@OptionalField(key: "seller_rating")
|
||||
var sellerRating: Int?
|
||||
|
||||
// MARK: Initializers
|
||||
|
||||
init() {}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Extensions
|
||||
|
||||
extension SaleRecord {
|
||||
|
||||
// MARK: Computed
|
||||
|
||||
/// The `Sendable` snapshot of the saved record; its buyer, its seller, and its listing with its shop must be eager-loaded.
|
||||
var snapshot: Sale {
|
||||
get throws {
|
||||
.init(
|
||||
number: number,
|
||||
conversationID: $conversation.id,
|
||||
listing: listing.snapshot,
|
||||
buyer: try buyer.snapshot,
|
||||
seller: try seller.snapshot,
|
||||
priceCents: priceCents,
|
||||
askedCents: askedCents,
|
||||
shippingCents: shippingCents,
|
||||
declared: .init(
|
||||
grade: declaredGrade,
|
||||
pageQuality: declaredPageQuality,
|
||||
printing: declaredPrinting,
|
||||
notes: declaredNotes
|
||||
),
|
||||
agreedAt: agreedAt,
|
||||
paidAt: paidAt,
|
||||
paymentNote: paymentNote,
|
||||
sentAt: sentAt,
|
||||
shippingNote: shippingNote,
|
||||
receivedAt: receivedAt,
|
||||
buyerRating: buyerRating,
|
||||
sellerRating: sellerRating
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user