import 'package:taafee_mobile/core/apis/apis.dart'; import 'package:taafee_mobile/features/auth/data_layer/model/login.dart'; import 'package:taafee_mobile/features/auth/data_layer/model/login_response.dart'; import 'package:taafee_mobile/features/auth/data_layer/model/register.dart'; import 'package:taafee_mobile/features/auth/data_layer/model/reset_token.dart'; import 'package:taafee_mobile/features/auth/data_layer/model/verification_code.dart'; import '../../../../core/network/http.dart'; import '../model/user.dart'; class AuthService { Future register(RegisterModel registerModel) async { Request request = Request( EndPoint.register, RequestMethod.post, body: registerModel.toJson(), ); // no need to use variable (response) await request.sendRequest(); } Future verify(VerificationCodeModel verificationCodeModel) async { Request request = Request( EndPoint.verificationCode, RequestMethod.post, body: verificationCodeModel.toJson(), ); // no need to use variable (response) await request.sendRequest(); } Future login(LoginModel loginModel) async { Request request = Request( EndPoint.login, RequestMethod.post, body: loginModel.toJson(), ); Map response = await request.sendRequest(); return LoginResponseModel.fromJson(response["data"]); } Future logout() async { Request request = Request( EndPoint.logout, RequestMethod.get, authorized: true, ); // no need to use variable (response) await request.sendRequest(); } Future resendCode(String email) async { Request request = Request(EndPoint.resendCode, RequestMethod.post, body: {"email": email}); // no need to use variable (response) await request.sendRequest(); } Future forgotPassword(String email) async { Request request = Request( EndPoint.forgotPassword, RequestMethod.post, body: { "email": email, }, ); // no need to use variable (response) await request.sendRequest(); } Future verifyForgotPassword(String email, String code) async { Request request = Request( EndPoint.verifyForgotPassword, RequestMethod.post, body: { "email": email, "reset_code": code, }, ); Map response = await request.sendRequest(); return ResetToken.fromJson(response); } Future changePassword(String resetToken, String newPassword) async { Request request = Request( EndPoint.changePassword, RequestMethod.post, body: { "reset_token": resetToken, "new_password": newPassword, }, ); // no need to use variable (response) await request.sendRequest(); } Future deleteAccount(String password) async { Request request = Request(EndPoint.deleteAccount, RequestMethod.delete, authorized: true, body: {"password": password}); // no need to use variable (response) await request.sendRequest(); } ///----------------show user profile-------------/// Future showUser({void Function(Object)? onConnectionError}) async { Request request = Request(EndPoint.editAccount, RequestMethod.get, authorized: true, cacheable: true, headers: { 'Accept': 'application/json', }); Map response = await request.sendRequest(onConnectionError: onConnectionError); return User.fromJson(response['data']); } ///---------------guest---------------------/// Future guest() async { Request request = Request(EndPoint.guest, RequestMethod.post); Map response = await request.sendRequest(); return response['token']; } /// ------------- terminate other sessions --------/// Future terminateOtherSessions() async { Request request = Request(EndPoint.terminate, RequestMethod.delete, authorized: true); await request.sendRequest(); } }