first commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/constants/dio_constant.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/network/api_endpoint.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/network/dio_client.dart';
|
||||
import 'package:frontend_eccp_mobile/modules/profile/data/model/logout/logout_response.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
@lazySingleton
|
||||
class ProfileRemoteDataSource {
|
||||
final Dio _dio = DioClient.getInstance();
|
||||
|
||||
Future<LogoutResponse> logout() async {
|
||||
try {
|
||||
final response = await _dio.post<Map<String, dynamic>>(
|
||||
ApiEndpoint.logout,
|
||||
options: Options(
|
||||
extra: {DioExtraKey.noAuth: false},
|
||||
),
|
||||
);
|
||||
|
||||
final data = response.data;
|
||||
if (data == null) {
|
||||
throw Exception('EMPTY_RESPONSE');
|
||||
}
|
||||
|
||||
return LogoutResponse.fromJson(data);
|
||||
} on DioException catch (e) {
|
||||
final responseData = e.response?.data;
|
||||
if (responseData is Map<String, dynamic>) {
|
||||
return LogoutResponse.fromJson(responseData);
|
||||
}
|
||||
throw Exception(e.error?.toString() ?? 'LOGOUT_FAILED');
|
||||
}
|
||||
}
|
||||
}
|
||||
16
lib/modules/profile/data/model/logout/logout_response.dart
Normal file
16
lib/modules/profile/data/model/logout/logout_response.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
class LogoutResponse {
|
||||
LogoutResponse({
|
||||
required this.status,
|
||||
required this.message,
|
||||
});
|
||||
|
||||
factory LogoutResponse.fromJson(Map<String, dynamic> json) {
|
||||
return LogoutResponse(
|
||||
status: json['status']?.toString() ?? '',
|
||||
message: json['message']?.toString() ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
final String status;
|
||||
final String message;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:frontend_eccp_mobile/modules/profile/data/datasources/profile_remote_datasource.dart';
|
||||
import 'package:frontend_eccp_mobile/modules/profile/data/model/logout/logout_response.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
@lazySingleton
|
||||
class ProfileRepository {
|
||||
ProfileRepository(this._remoteDatasource);
|
||||
|
||||
final ProfileRemoteDataSource _remoteDatasource;
|
||||
|
||||
Future<LogoutResponse> logout() async {
|
||||
return _remoteDatasource.logout();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user