Skip to content

Commit 82c7879

Browse files
authored
Bookings: Add new Core Data entity for bookings (#16167)
2 parents 261ddc5 + 8d60c5d commit 82c7879

File tree

8 files changed

+1252
-1
lines changed

8 files changed

+1252
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Foundation
2+
import CoreData
3+
4+
@objc(Booking)
5+
public class Booking: NSManagedObject {
6+
7+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Foundation
2+
import CoreData
3+
4+
extension Booking {
5+
6+
@NSManaged public var bookingID: Int64
7+
@NSManaged public var siteID: Int64
8+
@NSManaged public var parentID: Int64
9+
@NSManaged public var productID: Int64
10+
@NSManaged public var orderID: Int64
11+
@NSManaged public var resourceID: Int64
12+
@NSManaged public var allDay: Bool
13+
@NSManaged public var cost: String?
14+
@NSManaged public var customerID: Int64
15+
@NSManaged public var dateCreated: Date?
16+
@NSManaged public var dateModified: Date?
17+
@NSManaged public var endDate: Date?
18+
@NSManaged public var startDate: Date?
19+
@NSManaged public var googleCalendarEventID: String?
20+
@NSManaged public var orderItemID: Int64
21+
@NSManaged public var statusKey: String?
22+
@NSManaged public var localTimezone: String?
23+
24+
}

Modules/Sources/Storage/Model/MIGRATIONS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
This file documents changes in the WCiOS Storage data model. Please explain any changes to the data model as well as any custom migrations.
44

5+
## Model 127 (Release 23.4.0.0)
6+
- @itsmeichigo 2025-09-23
7+
- Added new `Booking` entity.
8+
59
## Model 126 (Release 23.3.0.0)
610
- @rafaelkayumov 2025-09-15
711
- Added `isGarden` attribute to `Site` entity.

Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<plist version="1.0">
44
<dict>
55
<key>_XCCurrentVersionName</key>
6-
<string>Model 126.xcdatamodel</string>
6+
<string>Model 127.xcdatamodel</string>
77
</dict>
88
</plist>

Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/Model 127.xcdatamodel/contents

Lines changed: 1127 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import Foundation
2+
import Storage
3+
4+
5+
// MARK: - Storage.Booking: ReadOnlyConvertible
6+
//
7+
extension Storage.Booking: ReadOnlyConvertible {
8+
9+
/// Updates the Storage.Booking with the a ReadOnly.
10+
///
11+
public func update(with booking: Yosemite.Booking) {
12+
siteID = booking.siteID
13+
bookingID = booking.bookingID
14+
allDay = booking.allDay
15+
cost = booking.cost
16+
customerID = booking.customerID
17+
dateCreated = booking.dateCreated
18+
dateModified = booking.dateModified
19+
endDate = booking.endDate
20+
googleCalendarEventID = booking.googleCalendarEventID
21+
orderID = booking.orderID
22+
orderItemID = booking.orderItemID
23+
parentID = booking.parentID
24+
productID = booking.productID
25+
resourceID = booking.resourceID
26+
startDate = booking.startDate
27+
statusKey = booking.statusKey
28+
localTimezone = booking.localTimezone
29+
}
30+
31+
/// Returns a ReadOnly version of the receiver.
32+
///
33+
public func toReadOnly() -> Yosemite.Booking {
34+
Booking(siteID: siteID,
35+
bookingID: bookingID,
36+
allDay: allDay,
37+
cost: cost ?? "",
38+
customerID: customerID,
39+
dateCreated: dateCreated ?? Date(),
40+
dateModified: dateModified ?? Date(),
41+
endDate: endDate ?? Date(),
42+
googleCalendarEventID: googleCalendarEventID,
43+
orderID: orderID,
44+
orderItemID: orderItemID,
45+
parentID: parentID,
46+
productID: productID,
47+
resourceID: resourceID,
48+
startDate: startDate ?? Date(),
49+
statusKey: statusKey ?? "",
50+
localTimezone: localTimezone ?? "")
51+
}
52+
}

Modules/Sources/Yosemite/Model/Model.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public typealias BlazeTargetLanguage = Networking.BlazeTargetLanguage
2525
public typealias BlazeTargetOptions = Networking.BlazeTargetOptions
2626
public typealias BlazeTargetLocation = Networking.BlazeTargetLocation
2727
public typealias BlazeTargetTopic = Networking.BlazeTargetTopic
28+
public typealias Booking = Networking.Booking
2829
public typealias CreateBlazeCampaign = Networking.CreateBlazeCampaign
2930
public typealias FallibleCancelable = Hardware.FallibleCancelable
3031
public typealias CommentStatus = Networking.CommentStatus
@@ -265,6 +266,8 @@ public typealias StorageBlazeCampaignListItem = Storage.BlazeCampaignListItem
265266
public typealias StorageBlazeTargetDevice = Storage.BlazeTargetDevice
266267
public typealias StorageBlazeTargetLanguage = Storage.BlazeTargetLanguage
267268
public typealias StorageBlazeTargetTopic = Storage.BlazeTargetTopic
269+
// periphery:ignore - will be used later
270+
public typealias StorageBooking = Storage.Booking
268271
public typealias StorageCardReaderType = Storage.CardReaderType
269272
public typealias StorageCoupon = Storage.Coupon
270273
public typealias StorageCustomer = Storage.Customer

Modules/Tests/StorageTests/CoreData/MigrationTests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,6 +2755,32 @@ final class MigrationTests: XCTestCase {
27552755
let updatedCategory = migratedLabel.value(forKey: "hazmatCategory") as? String
27562756
XCTAssertEqual(updatedCategory, category)
27572757
}
2758+
2759+
func test_migrating_126_to_127_adds_new_booking_entity() throws {
2760+
// Given
2761+
let sourceContainer = try startPersistentContainer("Model 126")
2762+
let sourceContext = sourceContainer.viewContext
2763+
2764+
try sourceContext.save()
2765+
2766+
// Confidence Check. Booking should not exist in Model 126
2767+
XCTAssertNil(NSEntityDescription.entity(forEntityName: "Booking", in: sourceContext))
2768+
2769+
// When
2770+
let targetContainer = try migrate(sourceContainer, to: "Model 127")
2771+
let targetContext = targetContainer.viewContext
2772+
2773+
// Then
2774+
XCTAssertEqual(try targetContext.count(entityName: "Booking"), 0)
2775+
2776+
let booking = insertBooking(to: targetContext)
2777+
XCTAssertNoThrow(try targetContext.save())
2778+
2779+
XCTAssertEqual(try targetContext.count(entityName: "Booking"), 1)
2780+
let insertedBooking = try XCTUnwrap(targetContext.firstObject(ofType: Booking.self))
2781+
XCTAssertEqual(insertedBooking, booking)
2782+
XCTAssertEqual(insertedBooking.parentID, 0) // default value
2783+
}
27582784
}
27592785

27602786
// MARK: - Persistent Store Setup and Migrations
@@ -3679,4 +3705,12 @@ private extension MigrationTests {
36793705
"id": "test-address"
36803706
])
36813707
}
3708+
3709+
@discardableResult
3710+
func insertBooking(to context: NSManagedObjectContext) -> NSManagedObject {
3711+
context.insert(entityName: "Booking", properties: [
3712+
"siteID": 1,
3713+
"bookingID": 23
3714+
])
3715+
}
36823716
}

0 commit comments

Comments
 (0)