update database

This commit is contained in:
Phuoc Nguyen
2025-10-24 11:31:48 +07:00
parent f95fa9d0a6
commit c4272f9a21
126 changed files with 23528 additions and 2234 deletions

View File

@@ -0,0 +1,79 @@
import 'package:hive_ce/hive.dart';
import 'package:worker/core/constants/storage_constants.dart';
part 'cart_item_model.g.dart';
/// Cart Item Model - Type ID: 5
@HiveType(typeId: HiveTypeIds.cartItemModel)
class CartItemModel extends HiveObject {
CartItemModel({
required this.cartItemId,
required this.cartId,
required this.productId,
required this.quantity,
required this.unitPrice,
required this.subtotal,
required this.addedAt,
});
@HiveField(0)
final String cartItemId;
@HiveField(1)
final String cartId;
@HiveField(2)
final String productId;
@HiveField(3)
final double quantity;
@HiveField(4)
final double unitPrice;
@HiveField(5)
final double subtotal;
@HiveField(6)
final DateTime addedAt;
factory CartItemModel.fromJson(Map<String, dynamic> json) {
return CartItemModel(
cartItemId: json['cart_item_id'] as String,
cartId: json['cart_id'] as String,
productId: json['product_id'] as String,
quantity: (json['quantity'] as num).toDouble(),
unitPrice: (json['unit_price'] as num).toDouble(),
subtotal: (json['subtotal'] as num).toDouble(),
addedAt: DateTime.parse(json['added_at'] as String),
);
}
Map<String, dynamic> toJson() => {
'cart_item_id': cartItemId,
'cart_id': cartId,
'product_id': productId,
'quantity': quantity,
'unit_price': unitPrice,
'subtotal': subtotal,
'added_at': addedAt.toIso8601String(),
};
CartItemModel copyWith({
String? cartItemId,
String? cartId,
String? productId,
double? quantity,
double? unitPrice,
double? subtotal,
DateTime? addedAt,
}) => CartItemModel(
cartItemId: cartItemId ?? this.cartItemId,
cartId: cartId ?? this.cartId,
productId: productId ?? this.productId,
quantity: quantity ?? this.quantity,
unitPrice: unitPrice ?? this.unitPrice,
subtotal: subtotal ?? this.subtotal,
addedAt: addedAt ?? this.addedAt,
);
}

View File

@@ -0,0 +1,59 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'cart_item_model.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class CartItemModelAdapter extends TypeAdapter<CartItemModel> {
@override
final typeId = 5;
@override
CartItemModel read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return CartItemModel(
cartItemId: fields[0] as String,
cartId: fields[1] as String,
productId: fields[2] as String,
quantity: (fields[3] as num).toDouble(),
unitPrice: (fields[4] as num).toDouble(),
subtotal: (fields[5] as num).toDouble(),
addedAt: fields[6] as DateTime,
);
}
@override
void write(BinaryWriter writer, CartItemModel obj) {
writer
..writeByte(7)
..writeByte(0)
..write(obj.cartItemId)
..writeByte(1)
..write(obj.cartId)
..writeByte(2)
..write(obj.productId)
..writeByte(3)
..write(obj.quantity)
..writeByte(4)
..write(obj.unitPrice)
..writeByte(5)
..write(obj.subtotal)
..writeByte(6)
..write(obj.addedAt);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is CartItemModelAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}

View File

@@ -0,0 +1,71 @@
import 'package:hive_ce/hive.dart';
import 'package:worker/core/constants/storage_constants.dart';
part 'cart_model.g.dart';
/// Cart Model - Type ID: 4
@HiveType(typeId: HiveTypeIds.cartModel)
class CartModel extends HiveObject {
CartModel({
required this.cartId,
required this.userId,
required this.totalAmount,
required this.isSynced,
required this.lastModified,
required this.createdAt,
});
@HiveField(0)
final String cartId;
@HiveField(1)
final String userId;
@HiveField(2)
final double totalAmount;
@HiveField(3)
final bool isSynced;
@HiveField(4)
final DateTime lastModified;
@HiveField(5)
final DateTime createdAt;
factory CartModel.fromJson(Map<String, dynamic> json) {
return CartModel(
cartId: json['cart_id'] as String,
userId: json['user_id'] as String,
totalAmount: (json['total_amount'] as num).toDouble(),
isSynced: json['is_synced'] as bool? ?? false,
lastModified: DateTime.parse(json['last_modified'] as String),
createdAt: DateTime.parse(json['created_at'] as String),
);
}
Map<String, dynamic> toJson() => {
'cart_id': cartId,
'user_id': userId,
'total_amount': totalAmount,
'is_synced': isSynced,
'last_modified': lastModified.toIso8601String(),
'created_at': createdAt.toIso8601String(),
};
CartModel copyWith({
String? cartId,
String? userId,
double? totalAmount,
bool? isSynced,
DateTime? lastModified,
DateTime? createdAt,
}) => CartModel(
cartId: cartId ?? this.cartId,
userId: userId ?? this.userId,
totalAmount: totalAmount ?? this.totalAmount,
isSynced: isSynced ?? this.isSynced,
lastModified: lastModified ?? this.lastModified,
createdAt: createdAt ?? this.createdAt,
);
}

View File

@@ -0,0 +1,56 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'cart_model.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class CartModelAdapter extends TypeAdapter<CartModel> {
@override
final typeId = 4;
@override
CartModel read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return CartModel(
cartId: fields[0] as String,
userId: fields[1] as String,
totalAmount: (fields[2] as num).toDouble(),
isSynced: fields[3] as bool,
lastModified: fields[4] as DateTime,
createdAt: fields[5] as DateTime,
);
}
@override
void write(BinaryWriter writer, CartModel obj) {
writer
..writeByte(6)
..writeByte(0)
..write(obj.cartId)
..writeByte(1)
..write(obj.userId)
..writeByte(2)
..write(obj.totalAmount)
..writeByte(3)
..write(obj.isSynced)
..writeByte(4)
..write(obj.lastModified)
..writeByte(5)
..write(obj.createdAt);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is CartModelAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}