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,61 @@
|
||||
import FluentKit
|
||||
import Foundation
|
||||
|
||||
/// A FluentKit model of a single `conversations` row: a buyer and a shop, talking about a listing or the shop at large.
|
||||
final class ConversationRecord: Model, @unchecked Sendable {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
static let schema = "conversations"
|
||||
|
||||
@ID(key: .id)
|
||||
var id: UUID?
|
||||
|
||||
@Parent(key: "buyer_id")
|
||||
var buyer: UserRecord
|
||||
|
||||
@Parent(key: "shop_id")
|
||||
var shop: ShopRecord
|
||||
|
||||
@OptionalParent(key: "listing_id")
|
||||
var listing: ListingRecord?
|
||||
|
||||
@Field(key: "created_at")
|
||||
var createdAt: Date
|
||||
|
||||
/// When the buyer last opened the conversation; what came later is unread to them.
|
||||
@Field(key: "buyer_read_at")
|
||||
var buyerReadAt: Date
|
||||
|
||||
/// When the seller last opened the conversation; what came later is unread to them.
|
||||
@Field(key: "seller_read_at")
|
||||
var sellerReadAt: Date
|
||||
|
||||
@Children(for: \.$conversation)
|
||||
var messages: [MessageRecord]
|
||||
|
||||
@Children(for: \.$conversation)
|
||||
var offers: [OfferRecord]
|
||||
|
||||
@Children(for: \.$conversation)
|
||||
var sales: [SaleRecord]
|
||||
|
||||
// MARK: Initializers
|
||||
|
||||
init() {}
|
||||
|
||||
init(
|
||||
buyerID: UUID,
|
||||
shopID: UUID,
|
||||
listingID: UUID?,
|
||||
at date: Date
|
||||
) {
|
||||
self.$buyer.id = buyerID
|
||||
self.$shop.id = shopID
|
||||
self.$listing.id = listingID
|
||||
self.createdAt = date
|
||||
self.buyerReadAt = date
|
||||
self.sellerReadAt = date
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user