Initial commit
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
import 'package:cargocalculaterapp/features/calculator/data/model/calculate_price_response.dart';
|
||||
import 'package:cargocalculaterapp/features/calculator/data/model/lead_create_response.dart';
|
||||
import 'package:cargocalculaterapp/features/calculator/data/model/lead_create_request.dart';
|
||||
import 'package:cargocalculaterapp/features/calculator/data/model/price_calculate_request.dart';
|
||||
|
||||
abstract class CalculatorRemoteDataSource {
|
||||
Future<CalculatePriceResponse> priceCalculate(PriceCalculateRequest request);
|
||||
Future<LeadCreateResponse> createLead(LeadCreateRequest request);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import 'package:cargocalculaterapp/features/calculator/data/model/calculate_price_response.dart';
|
||||
import 'package:cargocalculaterapp/features/calculator/data/model/price_calculate_request.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import '../../../../constants/constants.dart';
|
||||
import '../../../../core/error/exceptions.dart';
|
||||
import '../../../../core/local_source/local_source.dart';
|
||||
import '../../../../injector_container.dart';
|
||||
import '../model/lead_create_response.dart';
|
||||
import '../model/lead_create_request.dart';
|
||||
import 'calculator_remote_data_source.dart';
|
||||
|
||||
class CalculatorRemoteDataSourceImpl extends CalculatorRemoteDataSource {
|
||||
final Dio dio;
|
||||
|
||||
CalculatorRemoteDataSourceImpl(this.dio);
|
||||
|
||||
@override
|
||||
Future<CalculatePriceResponse> priceCalculate(
|
||||
PriceCalculateRequest request,
|
||||
) async {
|
||||
try {
|
||||
final Response response = await dio.post(
|
||||
Constants.baseUrl + Urls.calculatePrice,
|
||||
options:
|
||||
DioConstants.options
|
||||
..headers = {
|
||||
"Authorization": "Bearer ${sl<LocalSource>().getAccessToken()}",
|
||||
},
|
||||
data: request,
|
||||
);
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
return CalculatePriceResponse.fromJson(response.data);
|
||||
}
|
||||
throw ServerException.fromJson(response.data);
|
||||
} on DioException catch (e) {
|
||||
throw ServerException.fromJson(e.response?.data);
|
||||
} on FormatException {
|
||||
throw ServerException(message: Validations.someThingWentWrong);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LeadCreateResponse> createLead(LeadCreateRequest request) async {
|
||||
try {
|
||||
final Response response = await dio.post(
|
||||
Constants.baseUrl + Urls.lead,
|
||||
options:
|
||||
DioConstants.options
|
||||
..headers = {
|
||||
"Authorization": "Bearer ${sl<LocalSource>().getAccessToken()}",
|
||||
},
|
||||
data: request,
|
||||
);
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
return LeadCreateResponse.fromJson(response.data);
|
||||
}
|
||||
throw ServerException.fromJson(response.data);
|
||||
} on DioException catch (e) {
|
||||
throw ServerException.fromJson(e.response?.data);
|
||||
} on FormatException {
|
||||
throw ServerException(message: Validations.someThingWentWrong);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
class CalculatePriceResponse {
|
||||
CalculatePriceResponse({this.price});
|
||||
|
||||
CalculatePriceResponse.fromJson(dynamic json) {
|
||||
price = double.tryParse(json['price'].toString());
|
||||
}
|
||||
|
||||
double? price;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
map['price'] = price;
|
||||
return map;
|
||||
}
|
||||
}
|
||||
73
lib/features/calculator/data/model/lead_create_request.dart
Normal file
73
lib/features/calculator/data/model/lead_create_request.dart
Normal file
@@ -0,0 +1,73 @@
|
||||
class LeadCreateRequest {
|
||||
LeadCreateRequest({
|
||||
this.warehouseCode,
|
||||
this.wharehouseUz,
|
||||
this.wharehouseRu,
|
||||
this.wharehouseZh,
|
||||
this.nameUz,
|
||||
this.nameRu,
|
||||
this.nameZh,
|
||||
this.userUcode,
|
||||
this.phoneNumber,
|
||||
this.gmail,
|
||||
this.weight,
|
||||
this.price,
|
||||
this.status,
|
||||
this.averageWeightKg,
|
||||
this.m3,
|
||||
});
|
||||
|
||||
LeadCreateRequest.fromJson(dynamic json) {
|
||||
warehouseCode = json['warehouse_code'];
|
||||
wharehouseUz = json['wharehouseUz'];
|
||||
wharehouseRu = json['wharehouseRu'];
|
||||
wharehouseZh = json['wharehouseZh'];
|
||||
nameUz = json['nameUz'];
|
||||
nameRu = json['nameRu'];
|
||||
nameZh = json['nameZh'];
|
||||
userUcode = json['user_ucode'];
|
||||
phoneNumber = json['phone_number'];
|
||||
gmail = json['gmail'];
|
||||
weight = json['weight'];
|
||||
price = json['price'];
|
||||
status = json['status'];
|
||||
averageWeightKg = json['average_weight_kg'];
|
||||
m3 = json['status'];
|
||||
}
|
||||
|
||||
int? warehouseCode;
|
||||
String? wharehouseUz;
|
||||
String? wharehouseRu;
|
||||
String? wharehouseZh;
|
||||
String? nameUz;
|
||||
String? nameRu;
|
||||
String? nameZh;
|
||||
String? userUcode;
|
||||
String? phoneNumber;
|
||||
String? gmail;
|
||||
String? weight;
|
||||
String? price;
|
||||
String? status;
|
||||
String? averageWeightKg;
|
||||
String? m3;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
map['warehouse_code'] = warehouseCode;
|
||||
map['wharehouseUz'] = wharehouseUz;
|
||||
map['wharehouseRu'] = wharehouseRu;
|
||||
map['wharehouseZh'] = wharehouseZh;
|
||||
map['nameUz'] = nameUz;
|
||||
map['nameRu'] = nameRu;
|
||||
map['nameZh'] = nameZh;
|
||||
map['user_ucode'] = userUcode;
|
||||
map['phone_number'] = phoneNumber;
|
||||
map['gmail'] = gmail;
|
||||
map['weight'] = weight;
|
||||
map['price'] = price;
|
||||
map['status'] = status;
|
||||
map['average_weight_kg'] = averageWeightKg;
|
||||
map['m3'] = m3;
|
||||
return map;
|
||||
}
|
||||
}
|
||||
118
lib/features/calculator/data/model/lead_create_response.dart
Normal file
118
lib/features/calculator/data/model/lead_create_response.dart
Normal file
@@ -0,0 +1,118 @@
|
||||
class LeadCreateResponse {
|
||||
LeadCreateResponse({
|
||||
this.userUcode,
|
||||
this.phoneNumber,
|
||||
this.gmail,
|
||||
this.weight,
|
||||
this.status,
|
||||
this.nameUz,
|
||||
this.nameRu,
|
||||
this.nameZh,
|
||||
this.wharehouseUz,
|
||||
this.wharehouseRu,
|
||||
this.wharehouseZh,
|
||||
this.id,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
LeadCreateResponse.fromJson(dynamic json) {
|
||||
userUcode = json['user_ucode'];
|
||||
phoneNumber = json['phone_number'];
|
||||
gmail = json['gmail'];
|
||||
weight = json['weight'];
|
||||
status = json['status'] != null ? Status.fromJson(json['status']) : null;
|
||||
nameUz = json['nameUz'];
|
||||
nameRu = json['nameRu'];
|
||||
nameZh = json['nameZh'];
|
||||
wharehouseUz = json['wharehouseUz'];
|
||||
wharehouseRu = json['wharehouseRu'];
|
||||
wharehouseZh = json['wharehouseZh'];
|
||||
createdAt = json['createdAt'];
|
||||
updatedAt = json['updatedAt'];
|
||||
id = json['id'];
|
||||
}
|
||||
|
||||
String? userUcode;
|
||||
String? phoneNumber;
|
||||
String? gmail;
|
||||
String? weight;
|
||||
Status? status;
|
||||
String? nameUz;
|
||||
String? nameRu;
|
||||
String? nameZh;
|
||||
String? wharehouseUz;
|
||||
String? wharehouseRu;
|
||||
String? wharehouseZh;
|
||||
String? id;
|
||||
String? createdAt;
|
||||
String? updatedAt;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
map['user_ucode'] = userUcode;
|
||||
map['phone_number'] = phoneNumber;
|
||||
map['gmail'] = gmail;
|
||||
map['weight'] = weight;
|
||||
if (status != null) {
|
||||
map['status'] = status?.toJson();
|
||||
}
|
||||
map['nameUz'] = nameUz;
|
||||
map['nameRu'] = nameRu;
|
||||
map['nameZh'] = nameZh;
|
||||
map['wharehouseUz'] = wharehouseUz;
|
||||
map['wharehouseRu'] = wharehouseRu;
|
||||
map['wharehouseZh'] = wharehouseZh;
|
||||
map['createdAt'] = createdAt;
|
||||
map['updatedAt'] = updatedAt;
|
||||
|
||||
map['id'] = id;
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
class Status {
|
||||
Status({this.code, this.translations});
|
||||
|
||||
Status.fromJson(dynamic json) {
|
||||
code = json['code'];
|
||||
translations =
|
||||
json['translations'] != null
|
||||
? Translations.fromJson(json['translations'])
|
||||
: null;
|
||||
}
|
||||
|
||||
String? code;
|
||||
Translations? translations;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
map['code'] = code;
|
||||
if (translations != null) {
|
||||
map['translations'] = translations?.toJson();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
class Translations {
|
||||
Translations({this.uz, this.ru, this.zh});
|
||||
|
||||
Translations.fromJson(dynamic json) {
|
||||
uz = json['uz'];
|
||||
ru = json['ru'];
|
||||
zh = json['zh'];
|
||||
}
|
||||
|
||||
String? uz;
|
||||
String? ru;
|
||||
String? zh;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
map['uz'] = uz;
|
||||
map['ru'] = ru;
|
||||
map['zh'] = zh;
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
class PriceCalculateRequest {
|
||||
PriceCalculateRequest({
|
||||
this.avg,
|
||||
this.m3,});
|
||||
|
||||
PriceCalculateRequest.fromJson(dynamic json) {
|
||||
avg = json['avg'];
|
||||
m3 = json['m3'];
|
||||
}
|
||||
double? avg;
|
||||
double? m3;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
map['avg'] = avg;
|
||||
map['m3'] = m3;
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import 'package:cargocalculaterapp/core/error/failure.dart';
|
||||
import 'package:cargocalculaterapp/features/calculator/data/model/calculate_price_response.dart';
|
||||
import 'package:cargocalculaterapp/features/calculator/data/model/lead_create_response.dart';
|
||||
import 'package:cargocalculaterapp/features/calculator/data/model/lead_create_request.dart';
|
||||
import 'package:cargocalculaterapp/features/calculator/data/model/price_calculate_request.dart';
|
||||
import 'package:cargocalculaterapp/features/calculator/domain/repository/calculator_repository.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
|
||||
import '../data_source/calculator_remote_data_source.dart';
|
||||
|
||||
class CalculatorRepositoryImpl extends CalculatorRepository {
|
||||
final CalculatorRemoteDataSource calculatorRemoteDataSource;
|
||||
|
||||
CalculatorRepositoryImpl(this.calculatorRemoteDataSource);
|
||||
|
||||
@override
|
||||
Future<Either<Failure, CalculatePriceResponse>> calculatePrice(
|
||||
PriceCalculateRequest request,
|
||||
) async {
|
||||
try {
|
||||
final response = await calculatorRemoteDataSource.priceCalculate(request);
|
||||
return Right(response);
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(message: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, LeadCreateResponse>> createLead(LeadCreateRequest request) async {
|
||||
try {
|
||||
final response = await calculatorRemoteDataSource.createLead(request);
|
||||
return Right(response);
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(message: e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user