feat: add arch
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
class UserModel {
|
||||
final String token;
|
||||
final String name;
|
||||
|
||||
UserModel({required this.token, required this.name});
|
||||
}
|
||||
@@ -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.'),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class AuthService {
|
||||
Future<Map<String, dynamic>> login(String email, String password) async {
|
||||
// شبیهسازی API Call
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
|
||||
if (email == 'test@example.com' && password == 'password123') {
|
||||
return {'token': 'xyz123', 'name': 'John Doe'};
|
||||
} else {
|
||||
throw Exception('Invalid credentials');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user