@@ -3,11 +3,15 @@ import 'package:dio/dio.dart';
33import 'package:dipantau_desktop_client/core/error/failure.dart' ;
44import 'package:dipantau_desktop_client/core/network/network_info.dart' ;
55import 'package:dipantau_desktop_client/feature/data/datasource/auth/auth_remote_data_source.dart' ;
6+ import 'package:dipantau_desktop_client/feature/data/model/forgot_password/forgot_password_body.dart' ;
7+ import 'package:dipantau_desktop_client/feature/data/model/general/general_response.dart' ;
68import 'package:dipantau_desktop_client/feature/data/model/login/login_body.dart' ;
79import 'package:dipantau_desktop_client/feature/data/model/login/login_response.dart' ;
810import 'package:dipantau_desktop_client/feature/data/model/refresh_token/refresh_token_body.dart' ;
11+ import 'package:dipantau_desktop_client/feature/data/model/reset_password/reset_password_body.dart' ;
912import 'package:dipantau_desktop_client/feature/data/model/sign_up/sign_up_body.dart' ;
1013import 'package:dipantau_desktop_client/feature/data/model/sign_up/sign_up_response.dart' ;
14+ import 'package:dipantau_desktop_client/feature/data/model/verify_forgot_password/verify_forgot_password_body.dart' ;
1115import 'package:dipantau_desktop_client/feature/domain/repository/auth/auth_repository.dart' ;
1216
1317class AuthRepositoryImpl implements AuthRepository {
@@ -109,4 +113,94 @@ class AuthRepositoryImpl implements AuthRepository {
109113 return Left (ConnectionFailure ());
110114 }
111115 }
116+
117+ @override
118+ Future <({Failure ? failure, GeneralResponse ? response})> forgotPassword (ForgotPasswordBody body) async {
119+ Failure ? failure;
120+ GeneralResponse ? response;
121+ final isConnected = await networkInfo.isConnected;
122+ if (isConnected) {
123+ try {
124+ response = await remoteDataSource.forgotPassword (body);
125+ } on DioException catch (error) {
126+ final message = error.message ?? error.toString ();
127+ if (error.response == null ) {
128+ failure = ServerFailure (message);
129+ } else {
130+ final errorMessage = getErrorMessageFromEndpoint (
131+ error.response? .data,
132+ message,
133+ error.response? .statusCode,
134+ );
135+ failure = ServerFailure (errorMessage);
136+ }
137+ } on TypeError catch (error) {
138+ final errorMessage = error.toString ();
139+ failure = ParsingFailure (errorMessage);
140+ }
141+ } else {
142+ failure = ConnectionFailure ();
143+ }
144+ return (failure: failure, response: response);
145+ }
146+
147+ @override
148+ Future <({Failure ? failure, GeneralResponse ? response})> verifyForgotPassword (VerifyForgotPasswordBody body) async {
149+ Failure ? failure;
150+ GeneralResponse ? response;
151+ final isConnected = await networkInfo.isConnected;
152+ if (isConnected) {
153+ try {
154+ response = await remoteDataSource.verifyForgotPassword (body);
155+ } on DioException catch (error) {
156+ final message = error.message ?? error.toString ();
157+ if (error.response == null ) {
158+ failure = ServerFailure (message);
159+ } else {
160+ final errorMessage = getErrorMessageFromEndpoint (
161+ error.response? .data,
162+ message,
163+ error.response? .statusCode,
164+ );
165+ failure = ServerFailure (errorMessage);
166+ }
167+ } on TypeError catch (error) {
168+ final errorMessage = error.toString ();
169+ failure = ParsingFailure (errorMessage);
170+ }
171+ } else {
172+ failure = ConnectionFailure ();
173+ }
174+ return (failure: failure, response: response);
175+ }
176+
177+ @override
178+ Future <({Failure ? failure, GeneralResponse ? response})> resetPassword (ResetPasswordBody body) async {
179+ Failure ? failure;
180+ GeneralResponse ? response;
181+ final isConnected = await networkInfo.isConnected;
182+ if (isConnected) {
183+ try {
184+ response = await remoteDataSource.resetPassword (body);
185+ } on DioException catch (error) {
186+ final message = error.message ?? error.toString ();
187+ if (error.response == null ) {
188+ failure = ServerFailure (message);
189+ } else {
190+ final errorMessage = getErrorMessageFromEndpoint (
191+ error.response? .data,
192+ message,
193+ error.response? .statusCode,
194+ );
195+ failure = ServerFailure (errorMessage);
196+ }
197+ } on TypeError catch (error) {
198+ final errorMessage = error.toString ();
199+ failure = ParsingFailure (errorMessage);
200+ }
201+ } else {
202+ failure = ConnectionFailure ();
203+ }
204+ return (failure: failure, response: response);
205+ }
112206}
0 commit comments