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
6 changes: 3 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion flutter.compileSdkVersion
compileSdkVersion 33

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand All @@ -44,8 +44,8 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.mc_crud_test"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
minSdkVersion 28
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
1 change: 1 addition & 0 deletions ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
41 changes: 41 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
136 changes: 136 additions & 0 deletions lib/core/customer/data/datasource/customer_local_datasource.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import 'dart:convert';

import 'package:dartz/dartz.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:mc_crud_test/core/customer/data/dto/customer_dto.dart';
import 'package:mc_crud_test/core/customer/data/keys/shared_keys.dart';
import 'package:mc_crud_test/core/error/failures.dart';
import 'package:mc_crud_test/feature/customer/page/customer_add_page.dart';
import 'package:secure_shared_preferences/secure_shared_pref.dart';

enum CustomerAddedStatus {
added,
exists,
error,
}

enum CustomerUpdatedStatus {
updated,
error,
}

enum CustomerDeletedStatus {
deleted,
error,
}

class CustomerLocalDataSource {
CustomerLocalDataSource();
final SharedPrefKeys _sharedPrefKeys = SharedPrefKeys();
late final Box box;

Future<Either<Failure, CustomerDTO>> getCustomerDetails(
String firstName) async {
throw UnimplementedError();
}

Future<Either<Failure, List<CustomerDTO>>> getCustomerList() async {
late final Box box;
box = Hive.box('customerBox');
List<CustomerDTO> customersObject = [];

try {
Map<dynamic, dynamic> customers = box.toMap();
customers.values.forEach((_) {
customersObject.add(_);
});

return Right(customersObject);
} catch (e) {
return const Right([]);
}
}

Future<Either<Failure, CustomerAddedStatus>> addCustomer(
CustomerDTO customer) async {
late final Box box;
box = Hive.box('customerBox');
Iterable<dynamic> reoccurCustomList = [];

try {
Map<dynamic, dynamic> customers = box.toMap();

if (customers.isNotEmpty) {
reoccurCustomList = box.toMap().values.where(
(element) {
return element.firstName == customer.firstName ||
element.lastName == customer.lastName ||
element.email == customer.email ||
element.bankAcountNumber == customer.bankAcountNumber;
},
);
}
if (reoccurCustomList.isEmpty || customers.isEmpty) {
await box.add(customer);
return const Right(CustomerAddedStatus.added);
} else {
return const Right(CustomerAddedStatus.exists);
}
} catch (e) {
return const Right(CustomerAddedStatus.error);
}
}

Future<Either<Failure, CustomerUpdatedStatus>> updateCustomer(
{required CustomerDTO oldCustomer,
required CustomerDTO customer,
required int index}) async {
late final Box box;
box = Hive.box('customerBox');

try {
Iterable<dynamic> reoccurCustomList = [];

box.deleteAt(index);

reoccurCustomList = box.toMap().values.where(
(element) {
return element.firstName == customer.firstName ||
element.lastName == customer.lastName ||
element.email == customer.email ||
element.bankAcountNumber == customer.bankAcountNumber;
},
);
if (reoccurCustomList.isNotEmpty) {
box.add(CustomerDTO(
firstName: oldCustomerData?.firstName,
lastName: oldCustomerData?.lastName,
dateOfBirth: oldCustomerData?.dateOfBirth,
phoneNumber: oldCustomerData?.phoneNumber,
email: oldCustomerData?.email,
bankAcountNumber: oldCustomerData?.bankAcountNumber));
return const Right(CustomerUpdatedStatus.error);
} else {
box.add(customer);
//box.putAt(index, customer);
return const Right(CustomerUpdatedStatus.updated);
}
} catch (e) {
return const Right(CustomerUpdatedStatus.error);
}
}

Future<Either<Failure, CustomerDeletedStatus>> deleteCustomer(
{required int index}) async {
late final Box box;
box = Hive.box('customerBox');

try {
box.deleteAt(index);

return const Right(CustomerDeletedStatus.deleted);
} catch (e) {
return const Right(CustomerDeletedStatus.error);
}
}
}
46 changes: 46 additions & 0 deletions lib/core/customer/data/dto/customer_dto.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:hive/hive.dart';

part 'customer_dto.g.dart';

@HiveType(typeId: 1)
class CustomerDTO {
CustomerDTO({
this.firstName,
this.lastName,
this.dateOfBirth,
this.phoneNumber,
this.email,
this.bankAcountNumber,
});

@HiveField(0)
String? firstName;
@HiveField(1)
String? lastName;
@HiveField(2)
String? dateOfBirth;
@HiveField(3)
String? phoneNumber;
@HiveField(4)
String? email;
@HiveField(5)
String? bankAcountNumber;

factory CustomerDTO.fromJson(Map<String, dynamic>? json) => CustomerDTO(
firstName: json?["firstName"] ?? "",
lastName: json?["lastName"] ?? "",
dateOfBirth: json?["dateOfBirth"] ?? "",
phoneNumber: json?["phoneNumber"] ?? "",
email: json?["email"] ?? "",
bankAcountNumber: json?["bankAcountNumber"] ?? "",
);

Map<String, dynamic>? toJson() => {
"firstName": firstName,
"lastName": lastName,
"dateOfBirth": dateOfBirth,
"phoneNumber": phoneNumber,
"email": email,
"bankAcountNumber": bankAcountNumber,
};
}
56 changes: 56 additions & 0 deletions lib/core/customer/data/dto/customer_dto.g.dart

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

3 changes: 3 additions & 0 deletions lib/core/customer/data/keys/shared_keys.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class SharedPrefKeys {
final String customers = "customers";
}
47 changes: 47 additions & 0 deletions lib/core/customer/data/mapper/customers_mapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:dartz/dartz.dart';
import 'package:mc_crud_test/core/customer/data/dto/customer_dto.dart';
import 'package:mc_crud_test/core/customer/domain/entity/customer_entity.dart';
import 'package:mc_crud_test/core/customer/domain/usecase/customer/add_customer_usecase.dart';
import 'package:mc_crud_test/core/customer/domain/usecase/customer/delete_customer_usecase.dart';
import 'package:mc_crud_test/core/customer/domain/usecase/customer/get_customer_list_usecase.dart';
import 'package:mc_crud_test/core/customer/domain/usecase/customer/update_customer_usecase.dart';
import 'package:mc_crud_test/core/error/failures.dart';

class CustomerMapper {
CustomerMapper({
this.customerEntity,
this.customerDTO,
this.addCustomerUseCase,
this.updateCustomerUseCase,
this.deleteCustomerUseCase,
});
final CustomerEntity? customerEntity;
final CustomerDTO? customerDTO;
final AddCustomerImpl? addCustomerUseCase;
final GetAllCustomersImpl getAllCustomersUseCase = GetAllCustomersImpl();
final UpdateCustomer? updateCustomerUseCase;
final DeleteCustomer? deleteCustomerUseCase;

Future<Either<Failure, List<CustomerEntity>>> getAllCustomers() async {
try {
var customers = await getAllCustomersUseCase.execute();
List<CustomerDTO>? customerList = customers.getOrElse(() => []);

List<CustomerEntity> customersEntityList = [];
print("lenght = ${customerList.length}");
customerList.forEach((customer) {
customersEntityList.add(CustomerEntity(
firstName: customer.firstName ?? "",
lastName: customer.lastName ?? "",
dateOfBirth: customer.dateOfBirth ?? "",
phoneNumber: customer.phoneNumber ?? "",
email: customer.email ?? "",
bankAcountNumber: customer.bankAcountNumber ?? ""));
});

return Right(customersEntityList);
} catch (e) {
return const Right([]);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:dartz/dartz.dart';
import 'package:mc_crud_test/core/customer/data/dto/customer_dto.dart';
import 'package:mc_crud_test/core/error/failures.dart';

abstract class CustomerRepository {
Future<Either<Failure, List<CustomerDTO>>> getAllCustomers();
Future<Either<Failure, CustomerDTO>> getCustomer(String firstName);
Future<Either<Failure, String>> addCustomer(CustomerDTO data);
Future<Either<Failure, String>> deleteCustomer(String firstName);
Future<Either<Failure, String>> updateCustomer(CustomerDTO data);
}
Loading