diff --git a/Modules/Sources/Storage/Model/Booking/Booking+CoreDataClass.swift b/Modules/Sources/Storage/Model/Booking/Booking+CoreDataClass.swift new file mode 100644 index 00000000000..a90b5a15d5c --- /dev/null +++ b/Modules/Sources/Storage/Model/Booking/Booking+CoreDataClass.swift @@ -0,0 +1,7 @@ +import Foundation +import CoreData + +@objc(Booking) +public class Booking: NSManagedObject { + +} diff --git a/Modules/Sources/Storage/Model/Booking/Booking+CoreDataProperties.swift b/Modules/Sources/Storage/Model/Booking/Booking+CoreDataProperties.swift new file mode 100644 index 00000000000..d02abc70e58 --- /dev/null +++ b/Modules/Sources/Storage/Model/Booking/Booking+CoreDataProperties.swift @@ -0,0 +1,24 @@ +import Foundation +import CoreData + +extension Booking { + + @NSManaged public var bookingID: Int64 + @NSManaged public var siteID: Int64 + @NSManaged public var parentID: Int64 + @NSManaged public var productID: Int64 + @NSManaged public var orderID: Int64 + @NSManaged public var resourceID: Int64 + @NSManaged public var allDay: Bool + @NSManaged public var cost: String? + @NSManaged public var customerID: Int64 + @NSManaged public var dateCreated: Date? + @NSManaged public var dateModified: Date? + @NSManaged public var endDate: Date? + @NSManaged public var startDate: Date? + @NSManaged public var googleCalendarEventID: String? + @NSManaged public var orderItemID: Int64 + @NSManaged public var statusKey: String? + @NSManaged public var localTimezone: String? + +} diff --git a/Modules/Sources/Storage/Model/MIGRATIONS.md b/Modules/Sources/Storage/Model/MIGRATIONS.md index 4f75348ec89..30662cfe9f2 100644 --- a/Modules/Sources/Storage/Model/MIGRATIONS.md +++ b/Modules/Sources/Storage/Model/MIGRATIONS.md @@ -2,6 +2,10 @@ This file documents changes in the WCiOS Storage data model. Please explain any changes to the data model as well as any custom migrations. +## Model 127 (Release 23.4.0.0) +- @itsmeichigo 2025-09-23 + - Added new `Booking` entity. + ## Model 126 (Release 23.3.0.0) - @rafaelkayumov 2025-09-15 - Added `isGarden` attribute to `Site` entity. diff --git a/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion index 014e45c214a..b0c2ba22f43 100644 --- a/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion +++ b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion @@ -3,6 +3,6 @@ _XCCurrentVersionName - Model 126.xcdatamodel + Model 127.xcdatamodel diff --git a/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 127.xcdatamodel/contents b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 127.xcdatamodel/contents new file mode 100644 index 00000000000..1e752320269 --- /dev/null +++ b/Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 127.xcdatamodel/contents @@ -0,0 +1,1127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Modules/Sources/Yosemite/Model/Booking/Booking+ReadOnlyConvertible.swift b/Modules/Sources/Yosemite/Model/Booking/Booking+ReadOnlyConvertible.swift new file mode 100644 index 00000000000..aa573436a25 --- /dev/null +++ b/Modules/Sources/Yosemite/Model/Booking/Booking+ReadOnlyConvertible.swift @@ -0,0 +1,52 @@ +import Foundation +import Storage + + +// MARK: - Storage.Booking: ReadOnlyConvertible +// +extension Storage.Booking: ReadOnlyConvertible { + + /// Updates the Storage.Booking with the a ReadOnly. + /// + public func update(with booking: Yosemite.Booking) { + siteID = booking.siteID + bookingID = booking.bookingID + allDay = booking.allDay + cost = booking.cost + customerID = booking.customerID + dateCreated = booking.dateCreated + dateModified = booking.dateModified + endDate = booking.endDate + googleCalendarEventID = booking.googleCalendarEventID + orderID = booking.orderID + orderItemID = booking.orderItemID + parentID = booking.parentID + productID = booking.productID + resourceID = booking.resourceID + startDate = booking.startDate + statusKey = booking.statusKey + localTimezone = booking.localTimezone + } + + /// Returns a ReadOnly version of the receiver. + /// + public func toReadOnly() -> Yosemite.Booking { + Booking(siteID: siteID, + bookingID: bookingID, + allDay: allDay, + cost: cost ?? "", + customerID: customerID, + dateCreated: dateCreated ?? Date(), + dateModified: dateModified ?? Date(), + endDate: endDate ?? Date(), + googleCalendarEventID: googleCalendarEventID, + orderID: orderID, + orderItemID: orderItemID, + parentID: parentID, + productID: productID, + resourceID: resourceID, + startDate: startDate ?? Date(), + statusKey: statusKey ?? "", + localTimezone: localTimezone ?? "") + } +} diff --git a/Modules/Sources/Yosemite/Model/Model.swift b/Modules/Sources/Yosemite/Model/Model.swift index 3c97dc6f6e9..f87a23a533d 100644 --- a/Modules/Sources/Yosemite/Model/Model.swift +++ b/Modules/Sources/Yosemite/Model/Model.swift @@ -25,6 +25,7 @@ public typealias BlazeTargetLanguage = Networking.BlazeTargetLanguage public typealias BlazeTargetOptions = Networking.BlazeTargetOptions public typealias BlazeTargetLocation = Networking.BlazeTargetLocation public typealias BlazeTargetTopic = Networking.BlazeTargetTopic +public typealias Booking = Networking.Booking public typealias CreateBlazeCampaign = Networking.CreateBlazeCampaign public typealias FallibleCancelable = Hardware.FallibleCancelable public typealias CommentStatus = Networking.CommentStatus @@ -265,6 +266,8 @@ public typealias StorageBlazeCampaignListItem = Storage.BlazeCampaignListItem public typealias StorageBlazeTargetDevice = Storage.BlazeTargetDevice public typealias StorageBlazeTargetLanguage = Storage.BlazeTargetLanguage public typealias StorageBlazeTargetTopic = Storage.BlazeTargetTopic +// periphery:ignore - will be used later +public typealias StorageBooking = Storage.Booking public typealias StorageCardReaderType = Storage.CardReaderType public typealias StorageCoupon = Storage.Coupon public typealias StorageCustomer = Storage.Customer diff --git a/Modules/Tests/StorageTests/CoreData/MigrationTests.swift b/Modules/Tests/StorageTests/CoreData/MigrationTests.swift index 17855577abf..56754b9c05c 100644 --- a/Modules/Tests/StorageTests/CoreData/MigrationTests.swift +++ b/Modules/Tests/StorageTests/CoreData/MigrationTests.swift @@ -2755,6 +2755,32 @@ final class MigrationTests: XCTestCase { let updatedCategory = migratedLabel.value(forKey: "hazmatCategory") as? String XCTAssertEqual(updatedCategory, category) } + + func test_migrating_126_to_127_adds_new_booking_entity() throws { + // Given + let sourceContainer = try startPersistentContainer("Model 126") + let sourceContext = sourceContainer.viewContext + + try sourceContext.save() + + // Confidence Check. Booking should not exist in Model 126 + XCTAssertNil(NSEntityDescription.entity(forEntityName: "Booking", in: sourceContext)) + + // When + let targetContainer = try migrate(sourceContainer, to: "Model 127") + let targetContext = targetContainer.viewContext + + // Then + XCTAssertEqual(try targetContext.count(entityName: "Booking"), 0) + + let booking = insertBooking(to: targetContext) + XCTAssertNoThrow(try targetContext.save()) + + XCTAssertEqual(try targetContext.count(entityName: "Booking"), 1) + let insertedBooking = try XCTUnwrap(targetContext.firstObject(ofType: Booking.self)) + XCTAssertEqual(insertedBooking, booking) + XCTAssertEqual(insertedBooking.parentID, 0) // default value + } } // MARK: - Persistent Store Setup and Migrations @@ -3679,4 +3705,12 @@ private extension MigrationTests { "id": "test-address" ]) } + + @discardableResult + func insertBooking(to context: NSManagedObjectContext) -> NSManagedObject { + context.insert(entityName: "Booking", properties: [ + "siteID": 1, + "bookingID": 23 + ]) + } }