feat: add arch
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import 'package:tm_app/core/utils/result.dart';
|
||||
|
||||
import '../../core/utils/app_exceptions.dart';
|
||||
import '../models/user_model.dart';
|
||||
import '../services/auth_service.dart';
|
||||
|
||||
class AuthRepository {
|
||||
final AuthService _authService;
|
||||
|
||||
AuthRepository(this._authService);
|
||||
|
||||
Future<Result<UserModel>> login(String email, String password) async {
|
||||
try {
|
||||
final response = await _authService.login(email, password);
|
||||
final user = UserModel(token: response['token'], name: response['name']);
|
||||
return Result.ok(user); // در حالت موفقیت، یک Ok برمیگرداند
|
||||
} catch (e) {
|
||||
// در حالت خطا، یک Error برمیگرداند
|
||||
return Result.error(
|
||||
AuthenticationException('Email or password is not correct.'),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user