feat : request tagging
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
import 'package:rasadyar_livestock/data/model/response/address/address.dart';
|
||||
|
||||
abstract class LivestockRemoteDataSource {
|
||||
Future<LocationDetails> getLocationDetailsByLatLng({required double latitude, required double longitude});
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_livestock/data/data_source/remote/livestock/livestock_remote.dart';
|
||||
import 'package:rasadyar_livestock/data/model/response/address/address.dart';
|
||||
|
||||
class LivestockRemoteDataSourceImp implements LivestockRemoteDataSource {
|
||||
@override
|
||||
Future<LocationDetails> getLocationDetailsByLatLng({
|
||||
required double latitude,
|
||||
required double longitude,
|
||||
}) async {
|
||||
try {
|
||||
Dio dio = Dio();
|
||||
dio.options.baseUrl = 'https://nominatim.openstreetmap.org/';
|
||||
dio.options.headers['User-Agent'] = 'RasadyarLivestock/2.0';
|
||||
final response = await dio.get(
|
||||
'reverse',
|
||||
queryParameters: {'lat': latitude, 'lon': longitude, 'format': 'json'},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final data = response.data;
|
||||
return LocationDetails.fromJson(data);
|
||||
} else {
|
||||
throw Exception('Failed to load address');
|
||||
}
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,14 +10,14 @@ _LoginRequestModel _$LoginRequestModelFromJson(Map<String, dynamic> json) =>
|
||||
_LoginRequestModel(
|
||||
username: json['username'] as String?,
|
||||
password: json['password'] as String?,
|
||||
captchaCode: json['captcha_code'] as String?,
|
||||
captchaKey: json['captcha_key'] as String?,
|
||||
captchaCode: json['captchaCode'] as String?,
|
||||
captchaKey: json['captchaKey'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$LoginRequestModelToJson(_LoginRequestModel instance) =>
|
||||
<String, dynamic>{
|
||||
'username': instance.username,
|
||||
'password': instance.password,
|
||||
'captcha_code': instance.captchaCode,
|
||||
'captcha_key': instance.captchaKey,
|
||||
'captchaCode': instance.captchaCode,
|
||||
'captchaKey': instance.captchaKey,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'address.freezed.dart';
|
||||
|
||||
part 'address.g.dart';
|
||||
|
||||
@freezed
|
||||
abstract class Address with _$Address {
|
||||
const factory Address({
|
||||
String? road,
|
||||
String? neighbourhood,
|
||||
String? suburb,
|
||||
String? state,
|
||||
String? borough,
|
||||
String? city,
|
||||
String? district,
|
||||
String? county,
|
||||
String? province,
|
||||
String? ISO3166_2_lvl4,
|
||||
String? postcode,
|
||||
String? country,
|
||||
String? country_code,
|
||||
}) = _Address;
|
||||
|
||||
factory Address.fromJson(Map<String, dynamic> json) => _$AddressFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class LocationDetails with _$LocationDetails {
|
||||
const factory LocationDetails({
|
||||
int? place_id,
|
||||
String? licence,
|
||||
String? osm_type,
|
||||
int? osm_id,
|
||||
String? lat,
|
||||
String? lon,
|
||||
String? class_,
|
||||
String? type,
|
||||
int? place_rank,
|
||||
double? importance,
|
||||
String? addresstype,
|
||||
String? name,
|
||||
String? display_name,
|
||||
Address? address,
|
||||
List<String>? boundingbox,
|
||||
}) = _LocationDetails;
|
||||
|
||||
factory LocationDetails.fromJson(Map<String, dynamic> json) => _$LocationDetailsFromJson(json);
|
||||
}
|
||||
@@ -10,12 +10,12 @@ _AuthResponseModel _$AuthResponseModelFromJson(Map<String, dynamic> json) =>
|
||||
_AuthResponseModel(
|
||||
refresh: json['refresh'] as String?,
|
||||
access: json['access'] as String?,
|
||||
otpStatus: json['otp_status'] as bool?,
|
||||
otpStatus: json['otpStatus'] as bool?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$AuthResponseModelToJson(_AuthResponseModel instance) =>
|
||||
<String, dynamic>{
|
||||
'refresh': instance.refresh,
|
||||
'access': instance.access,
|
||||
'otp_status': instance.otpStatus,
|
||||
'otpStatus': instance.otpStatus,
|
||||
};
|
||||
|
||||
@@ -9,17 +9,17 @@ part of 'captcha_response_model.dart';
|
||||
_CaptchaResponseModel _$CaptchaResponseModelFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _CaptchaResponseModel(
|
||||
captchaKey: json['captcha_key'] as String?,
|
||||
captchaImage: json['captcha_image'] as String?,
|
||||
imageType: json['image_type'] as String?,
|
||||
imageDecode: json['image_decode'] as String?,
|
||||
captchaKey: json['captchaKey'] as String?,
|
||||
captchaImage: json['captchaImage'] as String?,
|
||||
imageType: json['imageType'] as String?,
|
||||
imageDecode: json['imageDecode'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$CaptchaResponseModelToJson(
|
||||
_CaptchaResponseModel instance,
|
||||
) => <String, dynamic>{
|
||||
'captcha_key': instance.captchaKey,
|
||||
'captcha_image': instance.captchaImage,
|
||||
'image_type': instance.imageType,
|
||||
'image_decode': instance.imageDecode,
|
||||
'captchaKey': instance.captchaKey,
|
||||
'captchaImage': instance.captchaImage,
|
||||
'imageType': instance.imageType,
|
||||
'imageDecode': instance.imageDecode,
|
||||
};
|
||||
|
||||
@@ -26,12 +26,12 @@ _User _$UserFromJson(Map<String, dynamic> json) => _User(
|
||||
id: (json['id'] as num).toInt(),
|
||||
username: json['username'] as String,
|
||||
password: json['password'] as String,
|
||||
firstName: json['first_name'] as String,
|
||||
lastName: json['last_name'] as String,
|
||||
isActive: json['is_active'] as bool,
|
||||
firstName: json['firstName'] as String,
|
||||
lastName: json['lastName'] as String,
|
||||
isActive: json['isActive'] as bool,
|
||||
mobile: json['mobile'] as String,
|
||||
phone: json['phone'] as String,
|
||||
nationalCode: json['national_code'] as String,
|
||||
nationalCode: json['nationalCode'] as String,
|
||||
birthdate: DateTime.parse(json['birthdate'] as String),
|
||||
nationality: json['nationality'] as String,
|
||||
ownership: json['ownership'] as String,
|
||||
@@ -39,21 +39,21 @@ _User _$UserFromJson(Map<String, dynamic> json) => _User(
|
||||
photo: json['photo'] as String,
|
||||
province: (json['province'] as num).toInt(),
|
||||
city: (json['city'] as num).toInt(),
|
||||
otpStatus: json['otp_status'] as bool,
|
||||
cityName: json['city_name'] as String,
|
||||
provinceName: json['province_name'] as String,
|
||||
otpStatus: json['otpStatus'] as bool,
|
||||
cityName: json['cityName'] as String,
|
||||
provinceName: json['provinceName'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$UserToJson(_User instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'username': instance.username,
|
||||
'password': instance.password,
|
||||
'first_name': instance.firstName,
|
||||
'last_name': instance.lastName,
|
||||
'is_active': instance.isActive,
|
||||
'firstName': instance.firstName,
|
||||
'lastName': instance.lastName,
|
||||
'isActive': instance.isActive,
|
||||
'mobile': instance.mobile,
|
||||
'phone': instance.phone,
|
||||
'national_code': instance.nationalCode,
|
||||
'nationalCode': instance.nationalCode,
|
||||
'birthdate': instance.birthdate.toIso8601String(),
|
||||
'nationality': instance.nationality,
|
||||
'ownership': instance.ownership,
|
||||
@@ -61,14 +61,14 @@ Map<String, dynamic> _$UserToJson(_User instance) => <String, dynamic>{
|
||||
'photo': instance.photo,
|
||||
'province': instance.province,
|
||||
'city': instance.city,
|
||||
'otp_status': instance.otpStatus,
|
||||
'city_name': instance.cityName,
|
||||
'province_name': instance.provinceName,
|
||||
'otpStatus': instance.otpStatus,
|
||||
'cityName': instance.cityName,
|
||||
'provinceName': instance.provinceName,
|
||||
};
|
||||
|
||||
_Role _$RoleFromJson(Map<String, dynamic> json) => _Role(
|
||||
id: (json['id'] as num).toInt(),
|
||||
roleName: json['role_name'] as String,
|
||||
roleName: json['roleName'] as String,
|
||||
description: json['description'] as String,
|
||||
type: RoleType.fromJson(json['type'] as Map<String, dynamic>),
|
||||
permissions: json['permissions'] as List<dynamic>,
|
||||
@@ -76,7 +76,7 @@ _Role _$RoleFromJson(Map<String, dynamic> json) => _Role(
|
||||
|
||||
Map<String, dynamic> _$RoleToJson(_Role instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'role_name': instance.roleName,
|
||||
'roleName': instance.roleName,
|
||||
'description': instance.description,
|
||||
'type': instance.type,
|
||||
'permissions': instance.permissions,
|
||||
@@ -91,14 +91,14 @@ Map<String, dynamic> _$RoleTypeToJson(_RoleType instance) => <String, dynamic>{
|
||||
};
|
||||
|
||||
_Permission _$PermissionFromJson(Map<String, dynamic> json) => _Permission(
|
||||
pageName: json['page_name'] as String,
|
||||
pageAccess: (json['page_access'] as List<dynamic>)
|
||||
pageName: json['pageName'] as String,
|
||||
pageAccess: (json['pageAccess'] as List<dynamic>)
|
||||
.map((e) => e as String)
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$PermissionToJson(_Permission instance) =>
|
||||
<String, dynamic>{
|
||||
'page_name': instance.pageName,
|
||||
'page_access': instance.pageAccess,
|
||||
'pageName': instance.pageName,
|
||||
'pageAccess': instance.pageAccess,
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:rasadyar_livestock/data/model/response/address/address.dart';
|
||||
import 'package:rasadyar_livestock/data/model/response/auth/auth_response_model.dart';
|
||||
import 'package:rasadyar_livestock/data/model/response/captcha/captcha_response_model.dart';
|
||||
|
||||
@@ -11,4 +12,6 @@ abstract class AuthRepository {
|
||||
Future<bool> hasAuthenticated();
|
||||
|
||||
Future<AuthResponseModel?> loginWithRefreshToken({required Map<String, dynamic> authRequest});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:rasadyar_livestock/data/data_source/remote/auth/auth_remote.dart';
|
||||
import 'package:rasadyar_livestock/data/data_source/remote/livestock/livestock_remote.dart';
|
||||
import 'package:rasadyar_livestock/data/model/response/address/address.dart';
|
||||
import 'package:rasadyar_livestock/data/model/response/auth/auth_response_model.dart';
|
||||
import 'package:rasadyar_livestock/data/model/response/captcha/captcha_response_model.dart';
|
||||
|
||||
@@ -7,7 +9,8 @@ import 'auth_repository.dart';
|
||||
class AuthRepositoryImp implements AuthRepository {
|
||||
final AuthRemoteDataSource authRemote;
|
||||
|
||||
AuthRepositoryImp(this.authRemote);
|
||||
|
||||
AuthRepositoryImp({required this.authRemote});
|
||||
|
||||
@override
|
||||
Future<AuthResponseModel?> login({required Map<String, dynamic> authRequest}) async =>
|
||||
@@ -34,4 +37,6 @@ class AuthRepositoryImp implements AuthRepository {
|
||||
Future<bool> hasAuthenticated() async {
|
||||
return await authRemote.hasAuthenticated();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import 'package:rasadyar_livestock/data/model/response/address/address.dart';
|
||||
import 'package:rasadyar_livestock/data/model/response/auth/auth_response_model.dart';
|
||||
import 'package:rasadyar_livestock/data/model/response/captcha/captcha_response_model.dart';
|
||||
|
||||
abstract class LivestockRepository {
|
||||
Future<LocationDetails?> getLocationDetails({
|
||||
required double latitude,
|
||||
required double longitude,
|
||||
});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:rasadyar_livestock/data/data_source/remote/livestock/livestock_remote.dart';
|
||||
import 'package:rasadyar_livestock/data/model/response/address/address.dart';
|
||||
|
||||
import 'livestock_repository.dart';
|
||||
|
||||
class LivestockRepositoryImp implements LivestockRepository {
|
||||
final LivestockRemoteDataSource livestockRemote;
|
||||
|
||||
LivestockRepositoryImp({required this.livestockRemote});
|
||||
|
||||
@override
|
||||
Future<LocationDetails?> getLocationDetails({required double latitude, required double longitude}) async {
|
||||
return await livestockRemote.getLocationDetailsByLatLng(
|
||||
latitude: latitude,
|
||||
longitude: longitude,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user