Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/models/isar/models/shopinbit_ticket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class ShopInBitTicket {
late ShopInBitCategory category;
@enumerated
late ShopInBitOrderStatus status;
// Raw API state string (e.g. "OFFER AVAILABLE") preserved alongside the
// mapped enum. If ShopinBit renames a state or adds a new one, the enum
// will read as `pending` but `statusRaw` retains the canonical string so a
// future client update can re-derive the correct status via migration.
String? statusRaw;
late String requestDescription;
late String deliveryCountry;
late String? offerProductName;
Expand Down
221 changes: 218 additions & 3 deletions lib/models/isar/models/shopinbit_ticket.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion lib/models/shopinbit/shopinbit_order_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ class ShopInBitOrderModel extends ChangeNotifier {
}
}

// The most recent raw API state string, persisted alongside _status so that
// we can recover from contract drift (renames / new states) without losing
// history. _status is the parsed/mapped value; _statusRaw is the source of
// truth straight from the API.
String? _statusRaw;
String? get statusRaw => _statusRaw;
set statusRaw(String? value) {
if (_statusRaw != value) {
_statusRaw = value;
notifyListeners();
}
}

String? _offerProductName;
String? get offerProductName => _offerProductName;

Expand Down Expand Up @@ -236,6 +249,7 @@ class ShopInBitOrderModel extends ChangeNotifier {
..displayName = _displayName
..category = _category ?? ShopInBitCategory.concierge
..status = _status
..statusRaw = _statusRaw
..requestDescription = _requestDescription
..deliveryCountry = _deliveryCountry
..offerProductName = _offerProductName
Expand Down Expand Up @@ -271,6 +285,7 @@ class ShopInBitOrderModel extends ChangeNotifier {
.._apiTicketId = ticket.apiTicketId
.._ticketId = ticket.ticketId
.._status = ticket.status
.._statusRaw = ticket.statusRaw
.._requestDescription = ticket.requestDescription
.._deliveryCountry = ticket.deliveryCountry
.._offerProductName = ticket.offerProductName
Expand Down Expand Up @@ -298,7 +313,11 @@ class ShopInBitOrderModel extends ChangeNotifier {
.toList();
}

static ShopInBitOrderStatus statusFromTicketState(TicketState state) {
// Returns null when the API state cannot be mapped (TicketState.unknown).
// Callers MUST treat null as "do not overwrite the locally stored status":
// silently coercing an unknown API state to a default (e.g. pending)
// would mask contract drift and look like data regression to the user.
static ShopInBitOrderStatus? statusFromTicketState(TicketState state) {
switch (state) {
case TicketState.newTicket:
return ShopInBitOrderStatus.pending;
Expand All @@ -323,6 +342,8 @@ class ShopInBitOrderModel extends ChangeNotifier {
return ShopInBitOrderStatus.cancelled;
case TicketState.refunded:
return ShopInBitOrderStatus.refunded;
case TicketState.unknown:
return null;
}
}
}
6 changes: 5 additions & 1 deletion lib/pages/shopinbit/shopinbit_ticket_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,13 @@ class _ShopInBitTicketDetailState extends State<ShopInBitTicketDetail> {
}

if (!statusResp.hasError && statusResp.value != null) {
widget.model.status = ShopInBitOrderModel.statusFromTicketState(
final mapped = ShopInBitOrderModel.statusFromTicketState(
statusResp.value!.state,
);
// Always preserve the raw API string, even when mapping fails, so
// it can be recovered later.
widget.model.statusRaw = statusResp.value!.stateRaw;
if (mapped != null) widget.model.status = mapped;
}

if (widget.model.status == ShopInBitOrderStatus.offerAvailable &&
Expand Down
4 changes: 3 additions & 1 deletion lib/pages/shopinbit/shopinbit_tickets_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ class _ShopInBitTicketsViewState extends State<ShopInBitTicketsView> {
final statusResp = await service.client.getTicketStatus(ref.id);
if (statusResp.hasError || statusResp.value == null) continue;

_tickets[localIdx].status = ShopInBitOrderModel.statusFromTicketState(
final mapped = ShopInBitOrderModel.statusFromTicketState(
statusResp.value!.state,
);
_tickets[localIdx].statusRaw = statusResp.value!.stateRaw;
if (mapped != null) _tickets[localIdx].status = mapped;

if (_tickets[localIdx].status == ShopInBitOrderStatus.offerAvailable &&
(_tickets[localIdx].offerProductName == null ||
Expand Down
Loading
Loading