feat : profile and map
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import 'package:rasadyar_inspection/data/model/response/auth/auth_response_model.dart';
|
||||
import 'package:rasadyar_inspection/data/model/response/captcha/captcha_response_model.dart';
|
||||
|
||||
abstract class AuthRemote {
|
||||
Future<AuthResponseModel?> login({required Map<String, dynamic> authRequest});
|
||||
|
||||
Future<CaptchaResponseModel?> captcha();
|
||||
|
||||
Future<void> logout();
|
||||
|
||||
Future<bool> hasAuthenticated();
|
||||
|
||||
Future<AuthResponseModel?> loginWithRefreshToken({required Map<String, dynamic> authRequest});
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_inspection/data/model/response/auth/auth_response_model.dart';
|
||||
import 'package:rasadyar_inspection/data/model/response/captcha/captcha_response_model.dart';
|
||||
import 'package:rasadyar_inspection/data/model/response/user_profile/user_profile_model.dart';
|
||||
|
||||
import 'auth_remote.dart';
|
||||
|
||||
class AuthRemoteImp extends AuthRemote {
|
||||
final DioRemote _httpClient;
|
||||
final String _BASE_URL = 'auth/api/v1/';
|
||||
|
||||
AuthRemoteImp(this._httpClient);
|
||||
|
||||
@override
|
||||
Future<AuthResponseModel?> login({required Map<String, dynamic> authRequest}) async {
|
||||
var res = await _httpClient.post<AuthResponseModel?>(
|
||||
'${_BASE_URL}login/',
|
||||
data: authRequest,
|
||||
fromJson: AuthResponseModel.fromJson,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
);
|
||||
return res.data;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<CaptchaResponseModel?> captcha() async {
|
||||
var res = await _httpClient.post<CaptchaResponseModel?>(
|
||||
'captcha/',
|
||||
fromJson: CaptchaResponseModel.fromJson,
|
||||
);
|
||||
return res.data;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<AuthResponseModel?> loginWithRefreshToken({
|
||||
required Map<String, dynamic> authRequest,
|
||||
}) async {
|
||||
var res = await _httpClient.post<AuthResponseModel>(
|
||||
'$_BASE_URL/login/',
|
||||
data: authRequest,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
);
|
||||
return res.data;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> logout() {
|
||||
// TODO: implement logout
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> hasAuthenticated() async {
|
||||
final response = await _httpClient.get<bool>(
|
||||
'$_BASE_URL/login/',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
);
|
||||
|
||||
return response.data ?? false;
|
||||
}
|
||||
|
||||
/* @override
|
||||
Future<UserProfileModel?> getUserInfo(String phoneNumber) async {
|
||||
var res = await _httpClient.post<UserProfileModel?>(
|
||||
'https://userbackend.rasadyaar.ir/api/send_otp/',
|
||||
data: {"mobile": phoneNumber, "state": ""},
|
||||
fromJson: UserProfileModel.fromJson,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
);
|
||||
return res.data;
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:rasadyar_inspection/data/model/response/poultry_location/poultry_location_model.dart';
|
||||
|
||||
abstract class InspectionRemoteDataSource {
|
||||
/// Fetches the inspection data for a given [inspectionId].
|
||||
///
|
||||
/// Returns a `Future` that resolves to a `Map<String, dynamic>` containing
|
||||
/// the inspection data.
|
||||
Future<Map<String, dynamic>> fetchInspectionData(String inspectionId);
|
||||
|
||||
/// Fetches the list of inspections for a given [userId].
|
||||
///
|
||||
/// Returns a `Future` that resolves to a `List<Map<String, dynamic>>`
|
||||
/// containing the list of inspections.
|
||||
Future<List<Map<String, dynamic>>> fetchInspections(String userId);
|
||||
|
||||
|
||||
Future<List<PoultryLocationModel>?> getNearbyLocation({
|
||||
double? centerLat,
|
||||
double? centerLng,
|
||||
double? radius,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_inspection/data/data_source/remote/inspection/inspection_remote.dart';
|
||||
import 'package:rasadyar_inspection/data/model/response/poultry_location/poultry_location_model.dart';
|
||||
|
||||
class InspectionRemoteDataSourceImp implements InspectionRemoteDataSource {
|
||||
final DioRemote _httpClient;
|
||||
final String _BASE_URL = 'auth/api/v1/';
|
||||
|
||||
InspectionRemoteDataSourceImp(this._httpClient);
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> fetchInspectionData(String inspectionId) {
|
||||
// TODO: implement fetchInspectionData
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Map<String, dynamic>>> fetchInspections(String userId) {
|
||||
// TODO: implement fetchInspections
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<PoultryLocationModel>?> getNearbyLocation({
|
||||
double? centerLat,
|
||||
double? centerLng,
|
||||
double? radius,
|
||||
}) async {
|
||||
DioRemote dioRemote = DioRemote(baseUrl: 'https://habackend.rasadyaar.ir/');
|
||||
await dioRemote.init();
|
||||
|
||||
var res = await dioRemote.get<List<PoultryLocationModel>>(
|
||||
'poultry-loc/',
|
||||
queryParameters: {'center_lat': centerLat, 'center_lng': centerLng, 'radius': radius},
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
fromJsonList: (json) =>
|
||||
json.map((item) => PoultryLocationModel.fromJson(item as Map<String, dynamic>)).toList(),
|
||||
);
|
||||
|
||||
return res.data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
import 'package:rasadyar_inspection/data/model/response/user_profile/user_profile_model.dart';
|
||||
|
||||
abstract class UserRemoteDataSource {
|
||||
|
||||
Future<UserProfileModel?> getProfile({required String token});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_inspection/data/data_source/remote/user/user_data_source.dart';
|
||||
import 'package:rasadyar_inspection/data/model/response/user_profile/user_profile_model.dart';
|
||||
|
||||
class UserRemoteDataSourceImp extends UserRemoteDataSource {
|
||||
final DioRemote _httpClient;
|
||||
final String _BASE_URL = 'auth/api/v1/';
|
||||
|
||||
UserRemoteDataSourceImp(this._httpClient);
|
||||
|
||||
@override
|
||||
Future<UserProfileModel?> getProfile({required String token}) async {
|
||||
var res = await _httpClient.get<UserProfileModel>(
|
||||
'${_BASE_URL}user/profile/',
|
||||
fromJson: UserProfileModel.fromJson,
|
||||
headers: {'Content-Type': 'application/json', 'Authorization': 'Bearer $token'},
|
||||
);
|
||||
|
||||
if (res.data == null) {
|
||||
throw Exception('Failed to load user profile');
|
||||
}
|
||||
|
||||
return res.data!;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user