diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies
new file mode 100644
index 00000000..2e95ca9b
--- /dev/null
+++ b/.flutter-plugins-dependencies
@@ -0,0 +1 @@
+{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_ios","path":"D:\\\\Flutter\\\\flutter_windows_1.22.5-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_ios-2.0.9\\\\","dependencies":[]},{"name":"webview_flutter_wkwebview","path":"D:\\\\Flutter\\\\flutter_windows_1.22.5-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\webview_flutter_wkwebview-2.7.5\\\\","dependencies":[]}],"android":[{"name":"path_provider_android","path":"D:\\\\Flutter\\\\flutter_windows_1.22.5-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_android-2.0.14\\\\","dependencies":[]},{"name":"webview_flutter_android","path":"D:\\\\Flutter\\\\flutter_windows_1.22.5-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\webview_flutter_android-2.8.10\\\\","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"D:\\\\Flutter\\\\flutter_windows_1.22.5-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-2.0.6\\\\","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"D:\\\\Flutter\\\\flutter_windows_1.22.5-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-2.1.6\\\\","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"D:\\\\Flutter\\\\flutter_windows_1.22.5-stable\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-2.0.6\\\\","dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_ios","path_provider_linux","path_provider_macos","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_ios","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"webview_flutter","dependencies":["webview_flutter_android","webview_flutter_wkwebview"]},{"name":"webview_flutter_android","dependencies":[]},{"name":"webview_flutter_wkwebview","dependencies":[]}],"date_created":"2022-06-23 15:27:58.328689","version":"2.10.4"}
\ No newline at end of file
diff --git a/android/app/build.gradle b/android/app/build.gradle
index 8ef25fd0..65a2a263 100755
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -32,7 +32,7 @@ if (keystorePropertiesFile.exists()) {
}
android {
- compileSdkVersion 28
+ compileSdkVersion 31
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
@@ -45,8 +45,8 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.int2.ecommerce_int2"
- minSdkVersion 16
- targetSdkVersion 28
+ minSdkVersion 19
+ targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index fcdfbdc1..7945117d 100755
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -21,13 +21,14 @@
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
-
+
+
diff --git a/android/build.gradle b/android/build.gradle
index 3100ad2d..714549c2 100755
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -1,12 +1,12 @@
buildscript {
- ext.kotlin_version = '1.3.50'
+ ext.kotlin_version = '1.6.10'
repositories {
google()
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.5.0'
+ classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties
index 556d288e..a9282f15 100755
--- a/android/gradle/wrapper/gradle-wrapper.properties
+++ b/android/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
diff --git a/ios/Flutter/Flutter.podspec b/ios/Flutter/Flutter.podspec
deleted file mode 100755
index 5ca30416..00000000
--- a/ios/Flutter/Flutter.podspec
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# NOTE: This podspec is NOT to be published. It is only used as a local source!
-#
-
-Pod::Spec.new do |s|
- s.name = 'Flutter'
- s.version = '1.0.0'
- s.summary = 'High-performance, high-fidelity mobile apps.'
- s.description = <<-DESC
-Flutter provides an easy and productive way to build and deploy high-performance mobile apps for Android and iOS.
- DESC
- s.homepage = 'https://flutter.io'
- s.license = { :type => 'MIT' }
- s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' }
- s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s }
- s.ios.deployment_target = '8.0'
- s.vendored_frameworks = 'Flutter.framework'
-end
diff --git a/ios/Flutter/flutter_export_environment.sh b/ios/Flutter/flutter_export_environment.sh
index 7f60bd78..c9bda9d4 100755
--- a/ios/Flutter/flutter_export_environment.sh
+++ b/ios/Flutter/flutter_export_environment.sh
@@ -1,14 +1,13 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
-export "FLUTTER_ROOT=/Users/macbooki9/Documents/flutter"
-export "FLUTTER_APPLICATION_PATH=/Users/macbooki9/Documents/personal/flutter_ecommerce_template"
+export "FLUTTER_ROOT=D:\Flutter\flutter_windows_1.22.5-stable\flutter"
+export "FLUTTER_APPLICATION_PATH=D:\Workspace\Flutter\do-an\flutter_ecommerce_template"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
-export "FLUTTER_TARGET=/Users/macbooki9/Documents/personal/flutter_ecommerce_template/lib/main.dart"
+export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.1"
export "FLUTTER_BUILD_NUMBER=1.0.1"
-export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
export "DART_OBFUSCATION=false"
-export "TRACK_WIDGET_CREATION=true"
+export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false"
-export "PACKAGE_CONFIG=/Users/macbooki9/Documents/personal/flutter_ecommerce_template/.dart_tool/package_config.json"
+export "PACKAGE_CONFIG=.packages"
diff --git a/lib/data/models/address.model.dart b/lib/data/models/address.model.dart
new file mode 100644
index 00000000..a3430b88
--- /dev/null
+++ b/lib/data/models/address.model.dart
@@ -0,0 +1,36 @@
+class Address {
+ String? id;
+ String? address;
+ String? city;
+ String? country;
+ String? zipCode;
+ bool? isDefault;
+
+ Address(
+ {this.id,
+ this.address,
+ this.city,
+ this.country = "Viet Name",
+ this.zipCode = "+84",
+ this.isDefault = false});
+
+ Address.fromJson(Map json) {
+ id = json['_id'];
+ address = json['address'];
+ city = json['city'];
+ country = json['country'];
+ zipCode = json['zipCode'];
+ isDefault = json['isDefault'] ?? false;
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['id'] = this.id;
+ data['address'] = this.address;
+ data['city'] = this.city;
+ data['country'] = this.country;
+ data['zipCode'] = this.zipCode;
+ data['isDefault'] = this.isDefault;
+ return data;
+ }
+}
diff --git a/lib/data/models/cart.model.dart b/lib/data/models/cart.model.dart
new file mode 100644
index 00000000..369d5383
--- /dev/null
+++ b/lib/data/models/cart.model.dart
@@ -0,0 +1,83 @@
+import 'package:ecommerce_int2/data/models/product.model.dart';
+
+class CartResponse {
+ bool? success;
+ String? message;
+ List? data;
+
+ CartResponse({this.success, this.message, this.data});
+
+ CartResponse.fromJson(Map json) {
+ success = json['success'];
+ message = json['message'];
+ if (json['data'] != null) {
+ data = [];
+ json['data'].forEach((v) {
+ data!.add(new CartModel.fromJson(v));
+ });
+ }
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['success'] = this.success;
+ data['message'] = this.message;
+ if (this.data != null) {
+ data['data'] = this.data!.map((v) => v.toJson()).toList();
+ }
+ return data;
+ }
+}
+
+class CartModel {
+ String? sId;
+ List? products;
+ String? user;
+ String? merchant;
+ int? total;
+ bool? isOrdered;
+ String? created;
+ int? iV;
+
+ CartModel(
+ {this.sId,
+ this.products,
+ this.user,
+ this.merchant,
+ this.total,
+ this.isOrdered,
+ this.created,
+ this.iV});
+
+ CartModel.fromJson(Map json) {
+ sId = json['_id'];
+ if (json['products'] != null) {
+ products = [];
+ json['products'].forEach((v) {
+ products!.add(new Product.fromJson(v));
+ });
+ }
+ user = json['user'];
+ merchant = json['merchant'] != null ?
+ (json['merchant'] is String? ? json['merchant'] : json['merchant']['_id']) : '';
+ total = json['total'];
+ isOrdered = json['isOrdered'];
+ created = json['created'];
+ iV = json['__v'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['_id'] = this.sId;
+ if (this.products != null) {
+ data['products'] = this.products!.map((v) => v.toJson()).toList();
+ }
+ data['user'] = this.user;
+ data['merchant'] = this.merchant;
+ data['total'] = this.total;
+ data['isOrdered'] = this.isOrdered;
+ data['created'] = this.created;
+ data['__v'] = this.iV;
+ return data;
+ }
+}
diff --git a/lib/data/models/category.model.dart b/lib/data/models/category.model.dart
new file mode 100644
index 00000000..3b1816f6
--- /dev/null
+++ b/lib/data/models/category.model.dart
@@ -0,0 +1,100 @@
+class CategoryList {
+ List? data;
+
+ CategoryList({this.data});
+
+ CategoryList.fromJson(Map json) {
+ if (json['data'] != null) {
+ data = [];
+ json['data'].forEach((v) {
+ data!.add(new Category.fromJson(v));
+ });
+ }
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ if (this.data != null) {
+ data['data'] = this.data!.map((v) => v.toJson()).toList();
+ }
+ return data;
+ }
+}
+
+class Category {
+ String? id;
+ String? name;
+ String? description;
+ List? subcategories;
+
+ Category({this.id, this.name, this.description, this.subcategories});
+
+ Category.fromJson(Map json) {
+ id = json['_id'];
+ name = json['name'];
+ description = json['description'];
+ if (json['subcategories'] != null) {
+ subcategories = [];
+ json['subcategories'].forEach((v) {
+ subcategories!.add(new SubCategory.fromJson(v));
+ });
+ }
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['_id'] = this.id;
+ data['name'] = this.name;
+ data['description'] = this.description;
+ if (this.subcategories != null) {
+ data['subcategories'] =
+ this.subcategories!.map((v) => v.toJson()).toList();
+ }
+ return data;
+ }
+}
+
+class SubCategory {
+ String? sId;
+ String? name;
+ String? description;
+ bool? isActive;
+ String? category;
+ String? created;
+ String? slug;
+ int? iV;
+
+ SubCategory(
+ {this.sId,
+ this.name,
+ this.description,
+ this.isActive,
+ this.category,
+ this.created,
+ this.slug,
+ this.iV});
+
+ SubCategory.fromJson(Map json) {
+ sId = json['_id'];
+ name = json['name'];
+ description = json['description'];
+ isActive = json['isActive'];
+ category = json['category'];
+ created = json['created'];
+ slug = json['slug'];
+ iV = json['__v'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['_id'] = this.sId;
+ data['name'] = this.name;
+ data['description'] = this.description;
+ data['isActive'] = this.isActive;
+ data['category'] = this.category;
+ data['created'] = this.created;
+ data['slug'] = this.slug;
+ data['__v'] = this.iV;
+ return data;
+ }
+}
diff --git a/lib/data/models/login.result.dart b/lib/data/models/login.result.dart
new file mode 100644
index 00000000..523f9122
--- /dev/null
+++ b/lib/data/models/login.result.dart
@@ -0,0 +1,18 @@
+import 'package:ecommerce_int2/data/models/user.model.dart';
+import 'package:json_annotation/json_annotation.dart';
+part 'login.result.g.dart';
+
+@JsonSerializable(explicitToJson: true)
+class LoginResult {
+ final String token;
+ final bool success;
+ final UserModel data;
+
+ LoginResult(this.token, this.success, this.data);
+
+
+ factory LoginResult.fromJson(Map json) =>
+ _$LoginResultFromJson(json);
+
+ Map toJson() => _$LoginResultToJson(this);
+}
\ No newline at end of file
diff --git a/lib/data/models/login.result.g.dart b/lib/data/models/login.result.g.dart
new file mode 100644
index 00000000..5b149d6a
--- /dev/null
+++ b/lib/data/models/login.result.g.dart
@@ -0,0 +1,22 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'login.result.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+LoginResult _$LoginResultFromJson(Map json) {
+ return LoginResult(
+ json['token'] as String,
+ json['success'] as bool,
+ UserModel.fromJson(json['data'] as Map),
+ );
+}
+
+Map _$LoginResultToJson(LoginResult instance) =>
+ {
+ 'token': instance.token,
+ 'success': instance.success,
+ 'data': instance.data.toJson(),
+ };
diff --git a/lib/data/models/merchant.model.dart b/lib/data/models/merchant.model.dart
new file mode 100644
index 00000000..05f68179
--- /dev/null
+++ b/lib/data/models/merchant.model.dart
@@ -0,0 +1,157 @@
+import 'package:ecommerce_int2/data/models/product.model.dart';
+
+class MerchantResponse {
+ bool? success;
+ MerchantData? data;
+
+ MerchantResponse({this.success, this.data});
+
+ MerchantResponse.fromJson(Map json) {
+ success = json['success'];
+ data = json['data'] != null ? new MerchantData.fromJson(json['data']) : null;
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['success'] = this.success;
+ if (this.data != null) {
+ data['data'] = this.data!.toJson();
+ }
+ return data;
+ }
+}
+
+class MerchantData {
+ Merchant? merchant;
+ List? products;
+ int? page;
+ int? pages;
+ int? totalProducts;
+
+ MerchantData(
+ {this.merchant,
+ this.products,
+ this.page,
+ this.pages,
+ this.totalProducts});
+
+ MerchantData.fromJson(Map json) {
+ merchant = json['merchant'] != null
+ ? new Merchant.fromJson(json['merchant'])
+ : null;
+ if (json['products'] != null) {
+ products = [];
+ json['products'].forEach((v) {
+ products!.add(new Product.fromJson(v));
+ });
+ }
+ page = json['page'];
+ pages = json['pages'];
+ totalProducts = json['totalProducts'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ if (this.merchant != null) {
+ data['merchant'] = this.merchant!.toJson();
+ }
+ if (this.products != null) {
+ data['products'] = this.products!.map((v) => v.toJson()).toList();
+ }
+ data['page'] = this.page;
+ data['pages'] = this.pages;
+ data['totalProducts'] = this.totalProducts;
+ return data;
+ }
+}
+
+class Merchant {
+ String? sId;
+ String? name;
+ String? email;
+ String? phoneNumber;
+ List? categories;
+ String? business;
+ bool? isActive;
+ String? status;
+ String? created;
+ String? slug;
+ int? iV;
+
+ Merchant(
+ {this.sId,
+ this.name,
+ this.email,
+ this.phoneNumber,
+ this.categories,
+ this.business,
+ this.isActive,
+ this.status,
+ this.created,
+ this.slug,
+ this.iV});
+
+ Merchant.fromJson(Map json) {
+ sId = json['_id'];
+ name = json['name'];
+ email = json['email'];
+ phoneNumber = json['phoneNumber'];
+ if (json['categories'] != null) {
+ categories = [];
+ json['categories'].forEach((v) {
+ categories!.add(new Categories.fromJson(v));
+ });
+ }
+ business = json['business'];
+ isActive = json['isActive'];
+ status = json['status'];
+ created = json['created'];
+ slug = json['slug'];
+ iV = json['__v'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['_id'] = this.sId;
+ data['name'] = this.name;
+ data['email'] = this.email;
+ data['phoneNumber'] = this.phoneNumber;
+ if (this.categories != null) {
+ data['categories'] = this.categories!.map((v) => v.toJson()).toList();
+ }
+ data['business'] = this.business;
+ data['isActive'] = this.isActive;
+ data['status'] = this.status;
+ data['created'] = this.created;
+ data['slug'] = this.slug;
+ data['__v'] = this.iV;
+ return data;
+ }
+}
+
+class Categories {
+ String? sId;
+ String? name;
+ String? slug;
+ String? image;
+
+ Categories({this.sId, this.name, this.slug, this.image});
+
+ Categories.fromJson(Map json) {
+ sId = json['_id'];
+ name = json['name'];
+ slug = json['slug'];
+ image = json['image'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['_id'] = this.sId;
+ data['name'] = this.name;
+ data['slug'] = this.slug;
+ data['image'] = this.image;
+ return data;
+ }
+}
+
+
diff --git a/lib/data/models/order.model.dart b/lib/data/models/order.model.dart
new file mode 100644
index 00000000..9a80233c
--- /dev/null
+++ b/lib/data/models/order.model.dart
@@ -0,0 +1,517 @@
+import 'package:ecommerce_int2/data/models/cart.model.dart';
+import 'package:intl/intl.dart';
+
+class OrderResponse {
+ bool? success;
+ String? message;
+ Order? order;
+
+ OrderResponse({this.success, this.message, this.order});
+
+ OrderResponse.fromJson(Map json) {
+ success = json['success'];
+ message = json['message'];
+ order = json['data'] != null ? new Order.fromJson(json['data']) : null;
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['success'] = this.success;
+ data['message'] = this.message;
+ if (this.order != null) {
+ data['data'] = this.order!.toJson();
+ }
+ return data;
+ }
+}
+
+class Order {
+ String? cart;
+ String? user;
+ String? merchant;
+ String? payment;
+ String? otherAddress;
+ String? phoneNumber;
+ String? status;
+ String? paymentStatus;
+ String? sId;
+ String? created;
+ int? iV;
+
+ String get createdDate {
+ if (created == null) return '';
+ final date = DateTime.tryParse(created!);
+ if (date == null) return '';
+ final res = DateFormat("yyyy-MM-dd HH:mm:ss aa").format(date.toLocal());
+ return res;
+ }
+
+ Order(
+ {this.cart,
+ this.user,
+ this.merchant,
+ this.payment,
+ this.otherAddress,
+ this.phoneNumber,
+ this.status,
+ this.paymentStatus,
+ this.sId,
+ this.created,
+ this.iV});
+
+ Order.fromJson(Map json) {
+ cart = json['cart'] is String ? json['cart']: json['cart']['_id'];
+ user = json['user'];
+ merchant = json['merchant'];
+ payment = json['payment'];
+ otherAddress = json['otherAddress'];
+ phoneNumber = json['phoneNumber'];
+ status = json['status'];
+ paymentStatus = json['paymentStatus'];
+ sId = json['_id'];
+ created = json['created'];
+ iV = json['__v'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['cart'] = this.cart;
+ data['user'] = this.user;
+ data['merchant'] = this.merchant;
+ data['payment'] = this.payment;
+ data['otherAddress'] = this.otherAddress;
+ data['phoneNumber'] = this.phoneNumber;
+ data['status'] = this.status;
+ data['paymentStatus'] = this.paymentStatus;
+ data['_id'] = this.sId;
+ data['created'] = this.created;
+ data['__v'] = this.iV;
+ return data;
+ }
+}
+
+class CompleteOrderParam {
+ String? address;
+ String? otherAddress;
+ String? phoneNumber;
+ String? payment;
+
+ CompleteOrderParam(
+ {this.address, this.otherAddress, this.phoneNumber, this.payment});
+
+ CompleteOrderParam.fromJson(Map json) {
+ address = json['address'];
+ otherAddress = json['otherAddress'];
+ phoneNumber = json['phoneNumber'];
+ payment = json['payment'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['address'] = this.address;
+ data['otherAddress'] = this.otherAddress;
+ data['phoneNumber'] = this.phoneNumber;
+ data['payment'] = this.payment;
+ return data;
+ }
+}
+
+class CompleteOrderResponse {
+ bool? success;
+ String? message;
+ OrderDoc? orderDoc;
+
+ CompleteOrderResponse({this.success, this.message, this.orderDoc});
+
+ CompleteOrderResponse.fromJson(Map json) {
+ success = json['success'];
+ message = json['message'];
+ orderDoc =
+ json['data'] != null ? new OrderDoc.fromJson(json['data']) : null;
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['success'] = this.success;
+ data['message'] = this.message;
+ if (this.orderDoc != null) {
+ data['data'] = this.orderDoc!.toJson();
+ }
+ return data;
+ }
+}
+
+class OrderDoc {
+ String? sId;
+ String? cart;
+ String? user;
+ String? merchant;
+ String? payment;
+ String? otherAddress;
+ String? phoneNumber;
+ String? status;
+ String? paymentStatus;
+ String? created;
+ int? iV;
+
+ OrderDoc(
+ {this.sId,
+ this.cart,
+ this.user,
+ this.merchant,
+ this.payment,
+ this.otherAddress,
+ this.phoneNumber,
+ this.status,
+ this.paymentStatus,
+ this.created,
+ this.iV});
+
+ OrderDoc.fromJson(Map json) {
+ sId = json['_id'];
+ cart = json['cart'];
+ user = json['user'];
+ merchant = json['merchant'];
+ payment = json['payment'];
+ otherAddress = json['otherAddress'];
+ phoneNumber = json['phoneNumber'];
+ status = json['status'];
+ paymentStatus = json['paymentStatus'];
+ created = json['created'];
+ iV = json['__v'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['_id'] = this.sId;
+ data['cart'] = this.cart;
+ data['user'] = this.user;
+ data['merchant'] = this.merchant;
+ data['payment'] = this.payment;
+ data['otherAddress'] = this.otherAddress;
+ data['phoneNumber'] = this.phoneNumber;
+ data['status'] = this.status;
+ data['paymentStatus'] = this.paymentStatus;
+ data['created'] = this.created;
+ data['__v'] = this.iV;
+ return data;
+ }
+}
+
+class AllOrderResponse {
+ bool? success;
+ List? orders;
+
+ AllOrderResponse({this.success, this.orders});
+
+ AllOrderResponse.fromJson(Map json) {
+ success = json['success'];
+ if (json['data'] != null) {
+ orders = [];
+ json['data'].forEach((v) {
+ orders!.add(new Order.fromJson(v));
+ });
+ }
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['success'] = this.success;
+ if (this.orders != null) {
+ data['data'] = this.orders!.map((v) => v.toJson()).toList();
+ }
+ return data;
+ }
+}
+
+class DetailOrderResponse {
+ bool? success;
+ OrderDocDetail? orderDoc;
+
+ DetailOrderResponse({this.success, this.orderDoc});
+
+ DetailOrderResponse.fromJson(Map json) {
+ success = json['success'];
+ orderDoc =
+ json['data'] != null ? new OrderDocDetail.fromJson(json['data']) : null;
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['success'] = this.success;
+ if (this.orderDoc != null) {
+ data['data'] = this.orderDoc!.toJson();
+ }
+ return data;
+ }
+}
+
+class OrderDocDetail {
+ String? sId;
+ CartModel? cart;
+ String? user;
+ String? merchant;
+ String? payment;
+ String? phoneNumber;
+ String? status;
+ String? paymentStatus;
+ String? created;
+ int? iV;
+ String? address;
+
+ String get createdDate {
+ if (created == null) return '';
+ final date = DateTime.tryParse(created!);
+ if (date == null) return '';
+ final res = DateFormat("yyyy-MM-dd HH:mm:ss aa").format(date);
+ return res;
+ }
+
+ bool get isPayWithCash => payment == 'CASH' && canCancel;
+ bool get canConfirmReceive => status == 'DELIVERING';
+
+ bool get canCancel => !(status == 'CANCELLED' || status == 'RECEIVED') ;
+
+ OrderDocDetail(
+ {this.sId,
+ this.cart,
+ this.user,
+ this.merchant,
+ this.payment,
+ this.phoneNumber,
+ this.status,
+ this.paymentStatus,
+ this.created,
+ this.iV,
+ this.address});
+
+ OrderDocDetail.fromJson(Map json) {
+ sId = json['_id'];
+ cart = json['cart'] != null ? new CartModel.fromJson(json['cart']) : null;
+ user = json['user']['_id'];
+ merchant = json['merchant'];
+ payment = json['payment'];
+ phoneNumber = json['phoneNumber'];
+ status = json['status'];
+ paymentStatus = json['paymentStatus'];
+ created = json['created'];
+ iV = json['__v'];
+ address = json['address'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['_id'] = this.sId;
+ if (this.cart != null) {
+ data['cart'] = this.cart!.toJson();
+ }
+ data['user'] = this.user;
+ data['merchant'] = this.merchant;
+ data['payment'] = this.payment;
+ data['phoneNumber'] = this.phoneNumber;
+ data['status'] = this.status;
+ data['paymentStatus'] = this.paymentStatus;
+ data['created'] = this.created;
+ data['__v'] = this.iV;
+ data['address'] = this.address;
+ return data;
+ }
+}
+
+class OrderProceed {
+ bool? success;
+ Data? data;
+
+ OrderProceed({this.success, this.data});
+
+ OrderProceed.fromJson(Map json) {
+ success = json['success'];
+ data = json['data'] != null ? new Data.fromJson(json['data']) : null;
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['success'] = this.success;
+ if (this.data != null) {
+ data['data'] = this.data!.toJson();
+ }
+ return data;
+ }
+}
+
+class Data {
+ Order? order;
+ Payment? payment;
+
+ Data({this.order, this.payment});
+
+ Data.fromJson(Map json) {
+ order = json['order'] != null ? new Order.fromJson(json['order']) : null;
+ payment =
+ json['payment'] != null ? new Payment.fromJson(json['payment']) : null;
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ if (this.order != null) {
+ data['order'] = this.order!.toJson();
+ }
+ if (this.payment != null) {
+ data['payment'] = this.payment!.toJson();
+ }
+ return data;
+ }
+}
+
+
+class Payment {
+ String? id;
+ String? intent;
+ String? state;
+ Payer? payer;
+ List? transactions;
+ String? createTime;
+ List? links;
+ int? httpStatusCode;
+
+ Payment(
+ {this.id,
+ this.intent,
+ this.state,
+ this.payer,
+ this.transactions,
+ this.createTime,
+ this.links,
+ this.httpStatusCode});
+
+ Payment.fromJson(Map json) {
+ id = json['id'];
+ intent = json['intent'];
+ state = json['state'];
+ payer = json['payer'] != null ? new Payer.fromJson(json['payer']) : null;
+ if (json['transactions'] != null) {
+ transactions = [];
+ json['transactions'].forEach((v) {
+ transactions!.add(new Transactions.fromJson(v));
+ });
+ }
+ createTime = json['create_time'];
+ if (json['links'] != null) {
+ links = [];
+ json['links'].forEach((v) {
+ links!.add(new Links.fromJson(v));
+ });
+ }
+ httpStatusCode = json['httpStatusCode'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['id'] = this.id;
+ data['intent'] = this.intent;
+ data['state'] = this.state;
+ if (this.payer != null) {
+ data['payer'] = this.payer!.toJson();
+ }
+ if (this.transactions != null) {
+ data['transactions'] = this.transactions!.map((v) => v.toJson()).toList();
+ }
+ data['create_time'] = this.createTime;
+ if (this.links != null) {
+ data['links'] = this.links!.map((v) => v.toJson()).toList();
+ }
+ data['httpStatusCode'] = this.httpStatusCode;
+ return data;
+ }
+}
+
+class Payer {
+ String? paymentMethod;
+
+ Payer({this.paymentMethod});
+
+ Payer.fromJson(Map json) {
+ paymentMethod = json['payment_method'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['payment_method'] = this.paymentMethod;
+ return data;
+ }
+}
+
+class Transactions {
+ Amount? amount;
+ String? description;
+ List? relatedResources;
+
+ Transactions({this.amount, this.description, this.relatedResources});
+
+ Transactions.fromJson(Map json) {
+ amount =
+ json['amount'] != null ? new Amount.fromJson(json['amount']) : null;
+ description = json['description'];
+ if (json['related_resources'] != null) {
+ relatedResources = [];
+ json['related_resources'].forEach((v) {
+ relatedResources!.add(v);
+ });
+ }
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ if (this.amount != null) {
+ data['amount'] = this.amount!.toJson();
+ }
+ data['description'] = this.description;
+ if (this.relatedResources != null) {
+ data['related_resources'] =
+ this.relatedResources!.map((v) => v.toJson()).toList();
+ }
+ return data;
+ }
+}
+
+class Amount {
+ String? total;
+ String? currency;
+
+ Amount({this.total, this.currency});
+
+ Amount.fromJson(Map json) {
+ total = json['total'];
+ currency = json['currency'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['total'] = this.total;
+ data['currency'] = this.currency;
+ return data;
+ }
+}
+
+class Links {
+ String? href;
+ String? rel;
+ String? method;
+
+ Links({this.href, this.rel, this.method});
+
+ Links.fromJson(Map json) {
+ href = json['href'];
+ rel = json['rel'];
+ method = json['method'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['href'] = this.href;
+ data['rel'] = this.rel;
+ data['method'] = this.method;
+ return data;
+ }
+}
+
diff --git a/lib/data/models/payment.model.dart b/lib/data/models/payment.model.dart
new file mode 100644
index 00000000..b4cf7ac8
--- /dev/null
+++ b/lib/data/models/payment.model.dart
@@ -0,0 +1,163 @@
+class PaymentResponse {
+ bool? success;
+ String? message;
+ Data? data;
+
+ PaymentResponse({this.success, this.message, this.data});
+
+ PaymentResponse.fromJson(Map json) {
+ success = json['success'];
+ message = json['message'];
+ data = json['data'] != null ? new Data.fromJson(json['data']) : null;
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['success'] = this.success;
+ data['message'] = this.message;
+ if (this.data != null) {
+ data['data'] = this.data!.toJson();
+ }
+ return data;
+ }
+}
+
+class Data {
+ String? id;
+ String? intent;
+ String? state;
+ Payer? payer;
+ List? transactions;
+ String? createTime;
+ List? links;
+ int? httpStatusCode;
+
+ Data(
+ {this.id,
+ this.intent,
+ this.state,
+ this.payer,
+ this.transactions,
+ this.createTime,
+ this.links,
+ this.httpStatusCode});
+
+ Data.fromJson(Map json) {
+ id = json['id'];
+ intent = json['intent'];
+ state = json['state'];
+ payer = json['payer'] != null ? new Payer.fromJson(json['payer']) : null;
+ if (json['transactions'] != null) {
+ transactions = [];
+ json['transactions'].forEach((v) {
+ transactions!.add(new Transactions.fromJson(v));
+ });
+ }
+ createTime = json['create_time'];
+ if (json['links'] != null) {
+ links = [];
+ json['links'].forEach((v) {
+ links!.add(new Links.fromJson(v));
+ });
+ }
+ httpStatusCode = json['httpStatusCode'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['id'] = this.id;
+ data['intent'] = this.intent;
+ data['state'] = this.state;
+ if (this.payer != null) {
+ data['payer'] = this.payer!.toJson();
+ }
+ if (this.transactions != null) {
+ data['transactions'] = this.transactions!.map((v) => v.toJson()).toList();
+ }
+ data['create_time'] = this.createTime;
+ if (this.links != null) {
+ data['links'] = this.links!.map((v) => v.toJson()).toList();
+ }
+ data['httpStatusCode'] = this.httpStatusCode;
+ return data;
+ }
+}
+
+class Payer {
+ String? paymentMethod;
+
+ Payer({this.paymentMethod});
+
+ Payer.fromJson(Map json) {
+ paymentMethod = json['payment_method'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['payment_method'] = this.paymentMethod;
+ return data;
+ }
+}
+
+class Transactions {
+ Amount? amount;
+ String? description;
+
+ Transactions({this.amount, this.description});
+
+ Transactions.fromJson(Map json) {
+ amount =
+ json['amount'] != null ? new Amount.fromJson(json['amount']) : null;
+ description = json['description'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ if (this.amount != null) {
+ data['amount'] = this.amount!.toJson();
+ }
+ data['description'] = this.description;
+ return data;
+ }
+}
+
+class Amount {
+ String? total;
+ String? currency;
+
+ Amount({this.total, this.currency});
+
+ Amount.fromJson(Map json) {
+ total = json['total'];
+ currency = json['currency'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['total'] = this.total;
+ data['currency'] = this.currency;
+ return data;
+ }
+}
+
+class Links {
+ String? href;
+ String? rel;
+ String? method;
+
+ Links({this.href, this.rel, this.method});
+
+ Links.fromJson(Map json) {
+ href = json['href'];
+ rel = json['rel'];
+ method = json['method'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['href'] = this.href;
+ data['rel'] = this.rel;
+ data['method'] = this.method;
+ return data;
+ }
+}
diff --git a/lib/data/models/product.model.dart b/lib/data/models/product.model.dart
new file mode 100644
index 00000000..e62f33d2
--- /dev/null
+++ b/lib/data/models/product.model.dart
@@ -0,0 +1,236 @@
+class ProductList {
+ List? products;
+ int? page;
+ int? pages;
+ int? totalProducts;
+
+ List get random => [products!.first, products!.last, products![1]];
+
+ ProductList({this.products, this.page, this.pages, this.totalProducts});
+
+ ProductList.fromJson(Map json) {
+ if (json['products'] != null) {
+ products = [];
+ json['products'].forEach((v) {
+ products!.add(new Product.fromJson(v));
+ });
+ }
+ page = json['page'];
+ pages = json['pages'];
+ totalProducts = json['totalProducts'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ if (this.products != null) {
+ data['products'] = this.products!.map((v) => v.toJson()).toList();
+ }
+ data['page'] = this.page;
+ data['pages'] = this.pages;
+ data['totalProducts'] = this.totalProducts;
+ return data;
+ }
+}
+
+class Product {
+ String? sId;
+ String? name;
+ String? imageUrl;
+ String? imageKey;
+ String? description;
+ int? quantity;
+ int? price;
+ int? purchasePrice;
+ int? totalPrice;
+ bool? isActive;
+ String? merchant;
+ String? category;
+ String? subcategory;
+ String? created;
+ String? slug;
+ int? iV;
+ int? totalRatings;
+ int? totalReviews;
+ int? averageRating;
+
+ Product(
+ {this.sId,
+ this.name,
+ this.imageUrl,
+ this.imageKey,
+ this.description,
+ this.quantity,
+ this.price,
+ this.purchasePrice,
+ this.totalPrice,
+ this.isActive,
+ this.merchant,
+ this.category,
+ this.subcategory,
+ this.created,
+ this.slug,
+ this.iV,
+ this.totalRatings,
+ this.totalReviews,
+ this.averageRating});
+
+ Product.fromJson(Map json) {
+ sId = json['_id'] ?? json['product']['_id'];
+ name = json['name'] ?? json['product']['name'];
+ imageUrl = json['imageUrl'] ?? json['product']['imageUrl'];
+ imageKey = json['imageKey'];
+ description = json['description'];
+ quantity = json['quantity'];
+ price = json['price'];
+ purchasePrice = json['purchasePrice'];
+ totalPrice = json['totalPrice'];
+ isActive = json['isActive'];
+ merchant = json['merchant'];
+ category = json['category'];
+ subcategory = json['subcategory'];
+ created = json['created'];
+ slug = json['slug'];
+ iV = json['__v'];
+ totalRatings = json['totalRatings'];
+ totalReviews = json['totalReviews'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['_id'] = this.sId;
+ data['name'] = this.name;
+ data['imageUrl'] = this.imageUrl;
+ data['imageKey'] = this.imageKey;
+ data['description'] = this.description;
+ data['quantity'] = this.quantity;
+ data['price'] = this.price;
+ data['purchasePrice'] = this.purchasePrice;
+ data['totalPrice'] = this.totalPrice;
+ data['isActive'] = this.isActive;
+ data['merchant'] = this.merchant;
+ data['category'] = this.category;
+ data['subcategory'] = this.subcategory;
+ data['created'] = this.created;
+ data['slug'] = this.slug;
+ data['__v'] = this.iV;
+ data['totalRatings'] = this.totalRatings;
+ data['totalReviews'] = this.totalReviews;
+ data['averageRating'] = this.averageRating;
+ return data;
+ }
+}
+
+class ProductFilter {
+ SortOrder? sortOrder;
+ int? rating;
+ int? max;
+ int? min;
+ String? subcategory;
+ String? name;
+ String? merchant;
+ int? order;
+ int? pageNumber;
+
+ ProductFilter(
+ {this.sortOrder,
+ this.rating,
+ this.max,
+ this.min,
+ this.subcategory,
+ this.name,
+ this.merchant,
+ this.order,
+ this.pageNumber});
+
+ ProductFilter.fromJson(Map json) {
+ sortOrder = json['sortOrder'] != null
+ ? new SortOrder.fromJson(json['sortOrder'])
+ : null;
+ rating = json['rating'];
+ max = json['max'];
+ min = json['min'];
+ subcategory = json['subcategory'];
+ order = json['order'];
+ pageNumber = json['pageNumber'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ if (this.sortOrder != null) {
+ data['sortOrder'] = this.sortOrder!.toJson();
+ }
+ data['rating'] = this.rating;
+ data['max'] = this.max;
+ data['min'] = this.min;
+ data['subcategory'] = this.subcategory;
+ data['name'] = this.name ?? '';
+ data['merchant'] = this.merchant;
+ data['order'] = this.order;
+ data['pageNumber'] = this.pageNumber;
+ return data;
+ }
+}
+
+class SortOrder {
+ int? price;
+
+ SortOrder({this.price});
+
+ SortOrder.fromJson(Map json) {
+ price = json['_id'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['price'] = this.price;
+ return data;
+ }
+}
+
+class AddProductParam {
+ List? products;
+
+ AddProductParam({this.products});
+
+ AddProductParam.fromJson(Map json) {
+ if (json['products'] != null) {
+ products = [];
+ json['products'].forEach((v) {
+ products!.add(new ProductParam.fromJson(v));
+ });
+ }
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ if (this.products != null) {
+ data['products'] = this.products!.map((v) => v.toJson()).toList();
+ }
+ return data;
+ }
+}
+
+class ProductParam {
+ String? product;
+ int? quantity;
+ int? price;
+ String? merchant;
+
+ ProductParam({this.product, this.quantity, this.price, this.merchant});
+
+ ProductParam.fromJson(Map json) {
+ product = json['product'];
+ quantity = json['quantity'];
+ price = json['price'];
+ merchant = json['merchant'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['product'] = this.product;
+ data['quantity'] = this.quantity;
+ data['price'] = this.price;
+ data['merchant'] = this.merchant;
+ return data;
+ }
+}
diff --git a/lib/data/models/review.dart b/lib/data/models/review.dart
new file mode 100644
index 00000000..689181ec
--- /dev/null
+++ b/lib/data/models/review.dart
@@ -0,0 +1,120 @@
+import 'package:intl/intl.dart';
+
+class ReviewResponse {
+ bool? success;
+ List? data;
+
+ ReviewResponse({this.success, this.data});
+
+ ReviewResponse.fromJson(Map json) {
+ success = json['success'];
+ if (json['data'] != null) {
+ data = [];
+ json['data'].forEach((v) {
+ data!.add(new Review.fromJson(v));
+ });
+ }
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['success'] = this.success;
+ if (this.data != null) {
+ data['data'] = this.data!.map((v) => v.toJson()).toList();
+ }
+ return data;
+ }
+}
+
+class Review {
+ String? sId;
+ String? product;
+ User? user;
+ int? rating;
+ String? review;
+ String? created;
+ int? iV;
+
+ String get createdDate {
+ if (created == null) return '';
+ final date = DateTime.tryParse(created!);
+ if (date == null) return '';
+ final res = DateFormat("yyyy-MM-dd HH:mm:ss aa").format(date);
+ return res;
+ }
+
+ Review(
+ {this.sId,
+ this.product,
+ this.user,
+ this.rating,
+ this.review,
+ this.created,
+ this.iV});
+
+ Review.fromJson(Map json) {
+ sId = json['_id'];
+ product = json['product'];
+ user = json['user'] != null ? new User.fromJson(json['user']) : null;
+ rating = json['rating'];
+ review = json['review'];
+ created = json['created'];
+ iV = json['__v'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['_id'] = this.sId;
+ data['product'] = this.product;
+ if (this.user != null) {
+ data['user'] = this.user!.toJson();
+ }
+ data['rating'] = this.rating;
+ data['review'] = this.review;
+ data['created'] = this.created;
+ data['__v'] = this.iV;
+ return data;
+ }
+}
+
+class User {
+ String? sId;
+ String? firstName;
+
+ User({this.sId, this.firstName});
+
+ User.fromJson(Map json) {
+ sId = json['_id'];
+ firstName = json['firstName'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['_id'] = this.sId;
+ data['firstName'] = this.firstName;
+ return data;
+ }
+}
+
+class ReviewParam {
+ String? product;
+ int? rating;
+ String? review;
+
+ ReviewParam({this.product, this.rating, this.review});
+
+ ReviewParam.fromJson(Map json) {
+ product = json['product'];
+ rating = json['rating'];
+ review = json['review'];
+ }
+
+ Map toJson() {
+ final Map data = new Map();
+ data['product'] = this.product;
+ data['rating'] = this.rating;
+ data['review'] = this.review;
+ return data;
+ }
+}
+
diff --git a/lib/data/models/user.model.dart b/lib/data/models/user.model.dart
new file mode 100644
index 00000000..d3d3b3b3
--- /dev/null
+++ b/lib/data/models/user.model.dart
@@ -0,0 +1,21 @@
+import 'package:json_annotation/json_annotation.dart';
+part 'user.model.g.dart';
+
+@JsonSerializable()
+class UserModel {
+ final String? id;
+ final String? firstName;
+ final String? lastName;
+ final String? email;
+ final String? role;
+ final String? resetToken;
+
+ String get name => (firstName ?? '') + ' ' + (lastName ?? '');
+
+ UserModel(this.id, this.firstName, this.lastName, this.email, this.role, this.resetToken);
+
+ factory UserModel.fromJson(Map json) =>
+ _$UserModelFromJson(json);
+
+ Map toJson() => _$UserModelToJson(this);
+}
diff --git a/lib/data/models/user.model.g.dart b/lib/data/models/user.model.g.dart
new file mode 100644
index 00000000..641500ba
--- /dev/null
+++ b/lib/data/models/user.model.g.dart
@@ -0,0 +1,27 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'user.model.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+UserModel _$UserModelFromJson(Map json) {
+ return UserModel(
+ json['id'] as String?,
+ json['firstName'] as String?,
+ json['lastName'] as String?,
+ json['email'] as String?,
+ json['role'] as String?,
+ json['resetPasswordToken'] as String?,
+ );
+}
+
+Map _$UserModelToJson(UserModel instance) => {
+ 'id': instance.id,
+ 'firstName': instance.firstName,
+ 'lastName': instance.lastName,
+ 'email': instance.email,
+ 'role': instance.role,
+ 'resetToken': instance.resetToken,
+ };
diff --git a/lib/data/provider/address.provider.dart b/lib/data/provider/address.provider.dart
new file mode 100644
index 00000000..250cc698
--- /dev/null
+++ b/lib/data/provider/address.provider.dart
@@ -0,0 +1,32 @@
+import 'package:ecommerce_int2/data/models/address.model.dart';
+import 'package:ecommerce_int2/services/network.service.dart';
+import 'package:get_storage/get_storage.dart';
+
+class AddressProvider {
+ final NetWorkService networkService;
+
+ final GetStorage storage = GetStorage();
+
+ AddressProvider(this.networkService);
+
+ final String getAddressUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/address';
+ final String addAddressUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/address/add';
+
+
+ Future getAllAddress() {
+ return networkService
+ .get(getAddressUrl);
+ }
+
+ Future addAddress(
+ Address address) {
+ return networkService.post(addAddressUrl, data: address.toJson());
+ }
+
+ Future updateAddress(
+ Address address) {
+ return networkService.post('$addAddressUrl/${address.id}', data: address.toJson());
+ }
+}
diff --git a/lib/data/provider/auth.provider.dart b/lib/data/provider/auth.provider.dart
new file mode 100644
index 00000000..b793d8eb
--- /dev/null
+++ b/lib/data/provider/auth.provider.dart
@@ -0,0 +1,52 @@
+import 'package:ecommerce_int2/utils/app_properties.dart';
+import 'package:ecommerce_int2/data/models/user.model.dart';
+import 'package:ecommerce_int2/services/network.service.dart';
+import 'package:get_storage/get_storage.dart';
+
+class AuthProvider {
+ final NetWorkService networkService;
+
+ final GetStorage storage = GetStorage();
+
+ AuthProvider(this.networkService);
+
+ final String loginUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/auth/login';
+ final String registerUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/auth/register';
+ final String forgotUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/auth/forgot';
+ final String reset = 'https://ecommerce-api-dut.herokuapp.com/api/auth/reset';
+ final String userInfoUrl = 'https://ecommerce-api-dut.herokuapp.com/api/user';
+
+ Future login(String username, String password) {
+ return networkService
+ .post(loginUrl, data: {"email": username, "password": password});
+ }
+
+ Future getUserInfo() {
+ return networkService.get(userInfoUrl);
+ }
+
+ Future register(
+ String username, String password, String firstName, String lastName) {
+ return networkService.post(registerUrl, data: {
+ "email": username,
+ "password": password,
+ "firstName": firstName,
+ "lastName": lastName
+ });
+ }
+
+ Future forgotPassword(String email) {
+ return networkService.post(forgotUrl, data: {"email": email});
+ }
+
+ Future resetPassword(String password) {
+ final json = storage.read(user);
+ final u = UserModel.fromJson(json);
+ if (u.resetToken == null) throw Exception('Reset token is not available');
+ return networkService
+ .post('$reset/${u.resetToken}', data: {"password": password});
+ }
+}
diff --git a/lib/data/provider/cart.provider.dart b/lib/data/provider/cart.provider.dart
new file mode 100644
index 00000000..c9167365
--- /dev/null
+++ b/lib/data/provider/cart.provider.dart
@@ -0,0 +1,50 @@
+import 'package:ecommerce_int2/data/models/product.model.dart';
+import 'package:ecommerce_int2/services/network.service.dart';
+import 'package:get_storage/get_storage.dart';
+
+class CartProvider {
+ final NetWorkService networkService;
+
+ final GetStorage storage = GetStorage();
+
+ CartProvider(this.networkService);
+
+ final String getAllCartUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/cart';
+
+ final String addProductToCartUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/cart/add';
+
+ final String modifyProductToCartUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/cart/modify';
+
+ final String deleteProductFromCartUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/cart/delete';
+
+ final String checkOutCartUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/order/proceed';
+
+ Future getCarts() {
+ return networkService.get(getAllCartUrl);
+ }
+
+ Future addProduct(AddProductParam param) {
+ return networkService.post(addProductToCartUrl, data: param.toJson());
+ }
+
+ Future modifyProduct(
+ String cartId, String productId, int before, int after) {
+ return networkService.put('$addProductToCartUrl/$cartId/$productId',
+ data: {"previousQuantity": before, "currentQuantity": after});
+ }
+
+ Future deleteProduct(String cartId, String productId) {
+ return networkService
+ .delete('$deleteProductFromCartUrl/$cartId/$productId');
+ }
+
+ Future checkoutCart(String cartId, String merchant) {
+ return networkService
+ .post(checkOutCartUrl, data: {"cart": cartId, "merchant": merchant});
+ }
+}
diff --git a/lib/data/provider/category.provider.dart b/lib/data/provider/category.provider.dart
new file mode 100644
index 00000000..7bdd9d4d
--- /dev/null
+++ b/lib/data/provider/category.provider.dart
@@ -0,0 +1,17 @@
+import 'package:ecommerce_int2/services/network.service.dart';
+import 'package:get_storage/get_storage.dart';
+
+class CategoryProvider {
+ final NetWorkService networkService;
+
+ final GetStorage storage = GetStorage();
+
+ CategoryProvider(this.networkService);
+
+ final String getAllCaegories =
+ 'https://ecommerce-api-dut.herokuapp.com/api/category';
+
+ Future getCategories() {
+ return networkService.get(getAllCaegories);
+ }
+}
diff --git a/lib/data/provider/merchant.provider.dart b/lib/data/provider/merchant.provider.dart
new file mode 100644
index 00000000..3b2b426b
--- /dev/null
+++ b/lib/data/provider/merchant.provider.dart
@@ -0,0 +1,20 @@
+import 'package:ecommerce_int2/services/network.service.dart';
+import 'package:get_storage/get_storage.dart';
+
+class MerchantProvider {
+ final NetWorkService networkService;
+
+ final GetStorage storage = GetStorage();
+
+ MerchantProvider(this.networkService);
+
+ final String getMerchantInfoUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/merchant';
+
+ Future getMerchantInfo(
+ String keyword) {
+ return networkService.get("$getMerchantInfoUrl/$keyword");
+ }
+
+
+}
diff --git a/lib/data/provider/order.provider.dart b/lib/data/provider/order.provider.dart
new file mode 100644
index 00000000..730f5897
--- /dev/null
+++ b/lib/data/provider/order.provider.dart
@@ -0,0 +1,56 @@
+import 'package:ecommerce_int2/data/models/order.model.dart';
+import 'package:ecommerce_int2/services/network.service.dart';
+import 'package:get_storage/get_storage.dart';
+
+class OrderProvider {
+ final NetWorkService networkService;
+
+ final GetStorage storage = GetStorage();
+
+ OrderProvider(this.networkService);
+
+ final String orderUrl = 'https://ecommerce-api-dut.herokuapp.com/api/order';
+
+ final String completeOrderUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/order/';
+
+ final String checkOutCartUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/order/proceed';
+
+ final String cancleOrderUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/order';
+
+ final String confirmReceivedUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/order';
+
+ Future getAllOrders() {
+ return networkService.get(orderUrl);
+ }
+
+ Future completeOrder(String orderId, CompleteOrderParam param) {
+ return networkService.put('$completeOrderUrl/$orderId/',
+ data: param.toJson());
+ }
+
+ Future makePayment(String orderId) {
+ return networkService.post('$completeOrderUrl/$orderId/pay');
+ }
+
+ Future cancleOrder(String orderId) {
+ return networkService.delete('$cancleOrderUrl/$orderId/cancel');
+ }
+
+ Future getOrderDetail(String orderId) {
+ return networkService.get('$orderUrl/$orderId');
+ }
+
+ Future confirmReceived(String orderId) {
+ return networkService.put('$confirmReceivedUrl/$orderId/status',
+ data: {"status": "RECEIVED"});
+ }
+
+ Future payOrder(String orderId) {
+ return networkService.put('$confirmReceivedUrl/$orderId/status',
+ data: {"paymentStatus": "PAID"});
+ }
+}
diff --git a/lib/data/provider/product.provider.dart b/lib/data/provider/product.provider.dart
new file mode 100644
index 00000000..e3d1b707
--- /dev/null
+++ b/lib/data/provider/product.provider.dart
@@ -0,0 +1,30 @@
+import 'package:ecommerce_int2/data/models/product.model.dart';
+import 'package:ecommerce_int2/services/network.service.dart';
+import 'package:get_storage/get_storage.dart';
+
+class ProductProvider {
+ final NetWorkService networkService;
+
+ final GetStorage storage = GetStorage();
+
+ ProductProvider(this.networkService);
+
+ final String getAllProductsUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/product/list';
+
+ final String searchProductUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/product/list/search/';
+
+
+ Future getProducts(
+ ProductFilter filter) {
+ return networkService.post(getAllProductsUrl, data: filter.toJson());
+ }
+
+ Future searchProducts(
+ String keyword) {
+ return networkService.get("$searchProductUrl/$keyword");
+ }
+
+
+}
diff --git a/lib/data/provider/review.provider.dart b/lib/data/provider/review.provider.dart
new file mode 100644
index 00000000..2cf5f019
--- /dev/null
+++ b/lib/data/provider/review.provider.dart
@@ -0,0 +1,30 @@
+import 'package:ecommerce_int2/data/models/review.dart';
+import 'package:ecommerce_int2/services/network.service.dart';
+import 'package:get_storage/get_storage.dart';
+
+class ReviewProvider {
+ final NetWorkService networkService;
+
+ final GetStorage storage = GetStorage();
+
+ ReviewProvider(this.networkService);
+
+ final String addReviewUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/review/add';
+
+ final String getRevAboutProductUrl =
+ 'https://ecommerce-api-dut.herokuapp.com/api/review';
+
+
+ Future addReview(
+ ReviewParam filter) {
+ return networkService.post(addReviewUrl, data: filter.toJson());
+ }
+
+ Future getReviewProduct(
+ String keyword) {
+ return networkService.get("$getRevAboutProductUrl/$keyword");
+ }
+
+
+}
diff --git a/lib/data/repository/address.repository.dart b/lib/data/repository/address.repository.dart
new file mode 100644
index 00000000..d4284fd2
--- /dev/null
+++ b/lib/data/repository/address.repository.dart
@@ -0,0 +1,35 @@
+import 'package:ecommerce_int2/data/models/address.model.dart';
+import 'package:ecommerce_int2/data/provider/address.provider.dart';
+
+class AddressRepository {
+ final AddressProvider provider;
+
+ AddressRepository(this.provider);
+
+ Future> getAllAddress() async {
+ final response = await provider.getAllAddress();
+ if (response.statusCode != 200) {
+ throw Exception("Get address failed");
+ }
+ final result = (response.body['data'] as List).map((i) =>
+ Address.fromJson(i)).toList();
+ return result;
+ }
+
+
+ Future addAddress(Address address) async {
+ final response =
+ await provider.addAddress(address);
+ if (response.statusCode != 200) {
+ throw Exception("Add address failed");
+ }
+ }
+
+ Future updateAddress(Address address) async {
+ final response =
+ await provider.updateAddress(address);
+ if (response.statusCode != 200) {
+ throw Exception("Update address failed");
+ }
+ }
+}
diff --git a/lib/data/repository/auth.repository.dart b/lib/data/repository/auth.repository.dart
new file mode 100644
index 00000000..c6158c56
--- /dev/null
+++ b/lib/data/repository/auth.repository.dart
@@ -0,0 +1,52 @@
+import 'package:ecommerce_int2/data/models/login.result.dart';
+import 'package:ecommerce_int2/data/models/user.model.dart';
+import 'package:ecommerce_int2/data/provider/auth.provider.dart';
+
+class AuthRepository {
+ final AuthProvider provider;
+
+ AuthRepository(this.provider);
+
+ Future login(String username, password) async {
+ final response = await provider.login(username, password);
+ if (response.statusCode != 200) {
+ throw Exception("Login failed");
+ }
+ final result = LoginResult.fromJson(response.body);
+ return result;
+ }
+
+ Future getUserInfo() async {
+ final response = await provider.getUserInfo();
+ if (response.statusCode != 200) {
+ throw Exception("Login failed");
+ }
+ final result = UserModel.fromJson(response.body['user']);
+ return result;
+ }
+
+ Future register(String username, String password, String firstName,
+ String lastName) async {
+ final response =
+ await provider.register(username, password, firstName, lastName);
+ if (response.statusCode != 200) {
+ throw Exception("Register failed");
+ }
+ }
+
+ Future forgotPassword(String email,) async {
+ final response =
+ await provider.forgotPassword(email);
+ if (response.statusCode != 200) {
+ throw Exception("Wrong email");
+ }
+ }
+
+ Future resetPassword(String password) async {
+ final response =
+ await provider.forgotPassword(password);
+ if (response.statusCode != 200) {
+ throw Exception("Wrong email");
+ }
+ }
+}
diff --git a/lib/data/repository/cart.repository.dart b/lib/data/repository/cart.repository.dart
new file mode 100644
index 00000000..f5de1288
--- /dev/null
+++ b/lib/data/repository/cart.repository.dart
@@ -0,0 +1,53 @@
+import 'package:ecommerce_int2/data/models/cart.model.dart';
+import 'package:ecommerce_int2/data/models/order.model.dart';
+import 'package:ecommerce_int2/data/models/product.model.dart';
+import 'package:ecommerce_int2/data/provider/cart.provider.dart';
+
+class CartRepository {
+ final CartProvider provider;
+
+ CartRepository(this.provider);
+
+ Future> getCarts() async {
+ final response = await provider.getCarts();
+ if (response.statusCode != 200) {
+ throw Exception("Get cart failed");
+ }
+ final result = CartResponse.fromJson(response.body);
+ return result.data ?? [];
+ }
+
+ Future addProduct(AddProductParam param) async {
+ final response = await provider.addProduct(param);
+ if (response.statusCode != 200) {
+ throw Exception("Add product failed");
+ }
+ return response.body['_id'] ?? '';
+ }
+
+ Future deleteProduct(String cartId, String productID) async {
+ final response = await provider.deleteProduct(cartId, productID);
+ if (response.statusCode != 200) {
+ throw Exception("Delete product failed");
+ }
+ }
+
+ Future modifyProduct(
+ String cartId, String productId, int before, int after) async {
+ final response =
+ await provider.modifyProduct(cartId, productId, before, after);
+ if (response.statusCode != 200) {
+ throw Exception("Update product failed");
+ }
+ }
+
+ Future> checkOutCart(List carts) async {
+ List orderIds = [];
+ for(CartModel cart in carts) {
+ final response = await provider.checkoutCart(cart.sId!, cart.merchant!);
+ OrderProceed order = OrderProceed.fromJson(response.body);
+ orderIds.add(order);
+ }
+ return orderIds;
+ }
+}
diff --git a/lib/data/repository/category.repository.dart b/lib/data/repository/category.repository.dart
new file mode 100644
index 00000000..15cdd9b0
--- /dev/null
+++ b/lib/data/repository/category.repository.dart
@@ -0,0 +1,18 @@
+import 'package:ecommerce_int2/data/models/category.model.dart';
+import 'package:ecommerce_int2/data/provider/category.provider.dart';
+
+class CategoryRepository {
+ final CategoryProvider provider;
+
+ CategoryRepository(this.provider);
+
+ Future getAllCategories() async {
+ final response = await provider.getCategories();
+ if (response.statusCode != 200) {
+ throw Exception("Get category failed");
+ }
+ final result = CategoryList.fromJson(response.body);
+ return result;
+ }
+
+}
diff --git a/lib/data/repository/merchant.repository.dart b/lib/data/repository/merchant.repository.dart
new file mode 100644
index 00000000..4270d6a1
--- /dev/null
+++ b/lib/data/repository/merchant.repository.dart
@@ -0,0 +1,17 @@
+import 'package:ecommerce_int2/data/models/merchant.model.dart';
+import 'package:ecommerce_int2/data/provider/merchant.provider.dart';
+
+class MerchantRepository {
+ final MerchantProvider provider;
+
+ MerchantRepository(this.provider);
+
+ Future getMerchantInfo(String merchant) async {
+ final response = await provider.getMerchantInfo(merchant);
+ if (response.statusCode != 200) {
+ throw Exception("Get merchant failed");
+ }
+ final result = MerchantResponse.fromJson(response.body);
+ return result.data!;
+ }
+}
diff --git a/lib/data/repository/order.repository.dart b/lib/data/repository/order.repository.dart
new file mode 100644
index 00000000..333c8302
--- /dev/null
+++ b/lib/data/repository/order.repository.dart
@@ -0,0 +1,67 @@
+import 'package:ecommerce_int2/data/models/order.model.dart';
+import 'package:ecommerce_int2/data/models/payment.model.dart';
+import 'package:ecommerce_int2/data/provider/order.provider.dart';
+
+class OrderRepository {
+ final OrderProvider provider;
+
+ OrderRepository(this.provider);
+
+ Future> getAllOrders() async {
+ final response = await provider.getAllOrders();
+ if (response.statusCode != 200) {
+ throw Exception("Complete order failed");
+ }
+ final result = AllOrderResponse.fromJson(response.body);
+ return result.orders ?? [];
+ }
+
+ Future completeOrder(String orderId, CompleteOrderParam param) async {
+ final response = await provider.completeOrder(orderId, param);
+ if (response.statusCode != 200) {
+ throw Exception("Complete order failed");
+ }
+ final result = CompleteOrderResponse.fromJson(response.body);
+ return result.orderDoc!.sId!;
+ }
+
+ Future makePayment(String orderId) async {
+ final response = await provider.makePayment(orderId);
+ if (response.statusCode != 200) {
+ throw Exception("Make payment failed");
+ }
+ final result = PaymentResponse.fromJson(response.body);
+ return result.data!.links?.firstWhere((element) => element.rel == 'approval_url').href ?? '';
+ }
+
+ Future cancleOrder(String orderId) async {
+ final response = await provider.cancleOrder(orderId);
+ if (response.statusCode != 200) {
+ throw Exception("Cancel order failed");
+ }
+ return;
+ }
+
+ Future getOrderDetail(String orderId) async {
+ final response = await provider.getOrderDetail(orderId);
+ if (response.statusCode != 200) {
+ throw Exception("Cancel order failed");
+ }
+ final res = DetailOrderResponse.fromJson(response.body);
+ return res.orderDoc!;
+ }
+
+ Future