Skip to content

Commit 60610f4

Browse files
Merge pull request #1322 from cypherstack/feat/shopinbit
fix(shopinbit): defend against API contract drift
2 parents 38d4c3c + 1c515e1 commit 60610f4

6 files changed

Lines changed: 128 additions & 14 deletions

File tree

lib/db/drift/shared_db/shared_database.g.dart

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/db/drift/shared_db/tables/shopin_bit_tickets.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ShopInBitTickets extends Table {
1212

1313
IntColumn get category => intEnum<ShopInBitCategory>()();
1414
IntColumn get status => intEnum<ShopInBitOrderStatus>()();
15+
TextColumn get statusRaw => text().nullable()();
1516

1617
TextColumn get requestDescription => text()();
1718
TextColumn get deliveryCountry => text()();

lib/models/shopinbit/shopinbit_order_model.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,19 @@ class ShopInBitOrderModel extends ChangeNotifier {
142142
}
143143
}
144144

145+
// The most recent raw API state string, persisted alongside _status so that
146+
// we can recover from contract drift (renames / new states) without losing
147+
// history. _status is the parsed/mapped value; _statusRaw is the source of
148+
// truth straight from the API.
149+
String? _statusRaw;
150+
String? get statusRaw => _statusRaw;
151+
set statusRaw(String? value) {
152+
if (_statusRaw != value) {
153+
_statusRaw = value;
154+
notifyListeners();
155+
}
156+
}
157+
145158
String? _offerProductName;
146159
String? get offerProductName => _offerProductName;
147160

@@ -277,6 +290,7 @@ class ShopInBitOrderModel extends ChangeNotifier {
277290
displayName: Value(_displayName),
278291
category: Value(_category ?? ShopInBitCategory.concierge),
279292
status: Value(_status),
293+
statusRaw: Value(_statusRaw),
280294
requestDescription: Value(_requestDescription),
281295
deliveryCountry: Value(_deliveryCountry),
282296
offerProductName: Value(_offerProductName),
@@ -316,6 +330,7 @@ class ShopInBitOrderModel extends ChangeNotifier {
316330
.._apiTicketId = ticket.apiTicketId
317331
.._ticketId = ticket.ticketId
318332
.._status = ticket.status
333+
.._statusRaw = ticket.statusRaw
319334
.._requestDescription = ticket.requestDescription
320335
.._deliveryCountry = ticket.deliveryCountry
321336
.._offerProductName = ticket.offerProductName
@@ -335,7 +350,7 @@ class ShopInBitOrderModel extends ChangeNotifier {
335350
.._messages = messages;
336351
}
337352

338-
static ShopInBitOrderStatus statusFromTicketState(TicketState state) {
353+
static ShopInBitOrderStatus? statusFromTicketState(TicketState state) {
339354
switch (state) {
340355
case TicketState.newTicket:
341356
return ShopInBitOrderStatus.pending;
@@ -360,6 +375,8 @@ class ShopInBitOrderModel extends ChangeNotifier {
360375
return ShopInBitOrderStatus.cancelled;
361376
case TicketState.refunded:
362377
return ShopInBitOrderStatus.refunded;
378+
case TicketState.unknown:
379+
return null;
363380
}
364381
}
365382
}

lib/services/shopinbit/shopinbit_orders_service.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ class ShopInBitOrdersService extends ChangeNotifier {
8282
final newStatus = ShopInBitOrderModel.statusFromTicketState(
8383
statusResp.value!.state,
8484
);
85-
if (model.status != newStatus) {
85+
model.statusRaw = statusResp.value!.stateRaw;
86+
if (model.status != newStatus && newStatus != null) {
8687
model.status = newStatus;
8788
changed = true;
8889
}

0 commit comments

Comments
 (0)