feat: add remote pull and push
This commit is contained in:
@@ -7,6 +7,7 @@ class BarTab {
|
||||
final String status;
|
||||
final DateTime openedAt;
|
||||
final DateTime? closedAt;
|
||||
final int version;
|
||||
final List<TabItem> items;
|
||||
|
||||
const BarTab({
|
||||
@@ -14,6 +15,7 @@ class BarTab {
|
||||
required this.customerName,
|
||||
required this.status,
|
||||
required this.openedAt,
|
||||
this.version = 0,
|
||||
required this.items,
|
||||
this.closedAt,
|
||||
});
|
||||
@@ -41,6 +43,7 @@ class BarTab {
|
||||
status == other.status &&
|
||||
openedAt == other.openedAt &&
|
||||
closedAt == other.closedAt &&
|
||||
version == other.version &&
|
||||
listEquals(items, other.items);
|
||||
|
||||
@override
|
||||
@@ -50,6 +53,7 @@ class BarTab {
|
||||
status,
|
||||
openedAt,
|
||||
closedAt,
|
||||
version,
|
||||
Object.hashAll(items),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
enum PaymentMethod {
|
||||
cash('cash', 'Cash', 'Cash payment'),
|
||||
payconiq('payconiq', 'Payconiq', 'Payconiq QR payment');
|
||||
payconiq('payconiq', 'Payconiq', 'Payconiq QR payment'),
|
||||
paymentPending('payment_pending', 'Payment pending', 'Unpaid remote close');
|
||||
|
||||
final String value;
|
||||
final String label;
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
class RemoteCommand {
|
||||
final String id;
|
||||
final String type;
|
||||
final String tabId;
|
||||
final int expectedVersion;
|
||||
final String paymentMethod;
|
||||
final String requestedBy;
|
||||
final DateTime createdAt;
|
||||
|
||||
const RemoteCommand({
|
||||
required this.id,
|
||||
required this.type,
|
||||
required this.tabId,
|
||||
required this.expectedVersion,
|
||||
required this.paymentMethod,
|
||||
required this.requestedBy,
|
||||
required this.createdAt,
|
||||
});
|
||||
|
||||
factory RemoteCommand.fromJson(Map<String, dynamic> json) {
|
||||
return RemoteCommand(
|
||||
id: json['id'] as String,
|
||||
type: json['type'] as String,
|
||||
tabId: json['tabId'] as String,
|
||||
expectedVersion: json['expectedVersion'] as int,
|
||||
paymentMethod: json['paymentMethod'] as String? ?? 'cash',
|
||||
requestedBy: json['requestedBy'] as String? ?? '',
|
||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
bool get isExpired {
|
||||
final cutoff = DateTime.now().subtract(const Duration(hours: 24));
|
||||
return createdAt.isBefore(cutoff);
|
||||
}
|
||||
}
|
||||
|
||||
class SyncResponse {
|
||||
final List<RemoteCommand> commands;
|
||||
final String? cursor;
|
||||
final List<String> plannedTabNames;
|
||||
|
||||
SyncResponse({
|
||||
required this.commands,
|
||||
this.cursor,
|
||||
this.plannedTabNames = const [],
|
||||
});
|
||||
|
||||
factory SyncResponse.fromJson(Map<String, dynamic> json) {
|
||||
final commandsList = (json['commands'] as List<dynamic>?)
|
||||
?.map((e) => RemoteCommand.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[];
|
||||
return SyncResponse(
|
||||
commands: commandsList,
|
||||
cursor: json['cursor'] as String?,
|
||||
plannedTabNames: (json['plannedTabNames'] as List<dynamic>?)
|
||||
?.map((e) => e as String)
|
||||
.toList() ??
|
||||
[],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SnapshotTab {
|
||||
final String id;
|
||||
final String customerName;
|
||||
final int version;
|
||||
final int totalInCents;
|
||||
final int itemCount;
|
||||
|
||||
const SnapshotTab({
|
||||
required this.id,
|
||||
required this.customerName,
|
||||
required this.version,
|
||||
required this.totalInCents,
|
||||
required this.itemCount,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'id': id,
|
||||
'customerName': customerName,
|
||||
'version': version,
|
||||
'totalInCents': totalInCents,
|
||||
'itemCount': itemCount,
|
||||
};
|
||||
}
|
||||
|
||||
class SyncRequest {
|
||||
final String deviceId;
|
||||
final String? cursor;
|
||||
final List<SnapshotTab> openTabs;
|
||||
|
||||
const SyncRequest({
|
||||
required this.deviceId,
|
||||
this.cursor,
|
||||
required this.openTabs,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'deviceId': deviceId,
|
||||
if (cursor != null) 'cursor': cursor,
|
||||
'openTabs': openTabs.map((t) => t.toJson()).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
class CommandAck {
|
||||
final String commandId;
|
||||
final String status;
|
||||
final String? result;
|
||||
|
||||
const CommandAck({
|
||||
required this.commandId,
|
||||
required this.status,
|
||||
this.result,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'commandId': commandId,
|
||||
'status': status,
|
||||
if (result != null) 'result': result,
|
||||
};
|
||||
}
|
||||
|
||||
enum RemoteSyncEventType {
|
||||
tabClosedRemotely,
|
||||
syncCompleted,
|
||||
syncFailed,
|
||||
conflict,
|
||||
}
|
||||
|
||||
class RemoteSyncEvent {
|
||||
final RemoteSyncEventType type;
|
||||
final String? tabCustomerName;
|
||||
final String? requestedBy;
|
||||
final String? message;
|
||||
|
||||
const RemoteSyncEvent({
|
||||
required this.type,
|
||||
this.tabCustomerName,
|
||||
this.requestedBy,
|
||||
this.message,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Venue {
|
||||
final String id;
|
||||
final String name;
|
||||
|
||||
const Venue({required this.id, required this.name});
|
||||
|
||||
factory Venue.fromJson(Map<String, dynamic> json) => Venue(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user