feat: get table

This commit is contained in:
efrilm
2025-08-03 23:53:06 +07:00
parent 8431b07057
commit 6afd62b617
14 changed files with 769 additions and 478 deletions
+123 -65
View File
@@ -1,74 +1,132 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'dart:ui';
import 'dart:convert';
class TableResponseModel {
final bool? success;
final TableData? data;
final dynamic errors;
TableResponseModel({
this.success,
this.data,
this.errors,
});
factory TableResponseModel.fromJson(String str) =>
TableResponseModel.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory TableResponseModel.fromMap(Map<String, dynamic> json) =>
TableResponseModel(
success: json["success"],
data: json["data"] == null ? null : TableData.fromMap(json["data"]),
errors: json["errors"],
);
Map<String, dynamic> toMap() => {
"success": success,
"data": data?.toMap(),
"errors": errors,
};
}
class TableData {
final List<TableModel>? tables;
final int? totalCount;
final int? page;
final int? limit;
final int? totalPages;
TableData({
this.tables,
this.totalCount,
this.page,
this.limit,
this.totalPages,
});
factory TableData.fromMap(Map<String, dynamic> json) => TableData(
tables: json["tables"] == null
? []
: List<TableModel>.from(
json["tables"].map((x) => TableModel.fromMap(x))),
totalCount: json["total_count"],
page: json["page"],
limit: json["limit"],
totalPages: json["total_pages"],
);
Map<String, dynamic> toMap() => {
"tables": tables == null
? []
: List<dynamic>.from(tables!.map((x) => x.toMap())),
"total_count": totalCount,
"page": page,
"limit": limit,
"total_pages": totalPages,
};
}
class TableModel {
int? id;
final String tableName;
final String startTime;
final String status;
final int orderId;
final int paymentAmount;
final Offset position;
final String? id;
final String? organizationId;
final String? outletId;
final String? tableName;
final String? status;
final int? paymentAmount;
final double? positionX;
final double? positionY;
final int? capacity;
final bool? isActive;
final DateTime? createdAt;
final DateTime? updatedAt;
TableModel({
this.id,
required this.tableName,
required this.startTime,
required this.status,
required this.orderId,
required this.paymentAmount,
required this.position,
this.organizationId,
this.outletId,
this.tableName,
this.status,
this.paymentAmount,
this.positionX,
this.positionY,
this.capacity,
this.isActive,
this.createdAt,
this.updatedAt,
});
@override
factory TableModel.fromMap(Map<String, dynamic> json) => TableModel(
id: json["id"],
organizationId: json["organization_id"],
outletId: json["outlet_id"],
tableName: json["table_name"],
status: json["status"],
paymentAmount: json["payment_amount"],
positionX: json["position_x"]?.toDouble(),
positionY: json["position_y"]?.toDouble(),
capacity: json["capacity"],
isActive: json["is_active"],
createdAt: json["created_at"] == null
? null
: DateTime.parse(json["created_at"]),
updatedAt: json["updated_at"] == null
? null
: DateTime.parse(json["updated_at"]),
);
// from map
factory TableModel.fromMap(Map<String, dynamic> map) {
return TableModel(
id: map['id'],
tableName: map['table_name'],
startTime: map['start_time'],
status: map['status'],
orderId: map['order_id'],
paymentAmount: map['payment_amount'],
position: Offset(map['x_position'], map['y_position']),
);
}
// to map
Map<String, dynamic> toMap() {
return {
'table_name': tableName,
'status': status,
'start_time': startTime,
'order_id': orderId,
'payment_amount': paymentAmount,
'x_position': position.dx,
'y_position': position.dy,
};
}
@override
bool operator ==(covariant TableModel other) {
if (identical(this, other)) return true;
return other.id == id &&
other.tableName == tableName &&
other.startTime == startTime &&
other.status == status &&
other.orderId == orderId &&
other.paymentAmount == paymentAmount &&
other.position == position;
}
@override
int get hashCode {
return id.hashCode ^
tableName.hashCode ^
startTime.hashCode ^
status.hashCode ^
orderId.hashCode ^
paymentAmount.hashCode ^
position.hashCode;
}
Map<String, dynamic> toMap() => {
"id": id,
"organization_id": organizationId,
"outlet_id": outletId,
"table_name": tableName,
"status": status,
"payment_amount": paymentAmount,
"position_x": positionX,
"position_y": positionY,
"capacity": capacity,
"is_active": isActive,
"created_at": createdAt?.toIso8601String(),
"updated_at": updatedAt?.toIso8601String(),
};
}