diff --git a/README.md b/README.md index 4a260d8..0460227 100644 --- a/README.md +++ b/README.md @@ -1,39 +1 @@ - - -TODO: Put a short description of the package here that helps potential users -know whether this package might be useful for them. - -## Features - -TODO: List what your package can do. Maybe include images, gifs, or videos. - -## Getting started - -TODO: List prerequisites and provide or point to information on how to -start using the package. - -## Usage - -TODO: Include short and useful examples for package users. Add longer examples -to `/example` folder. - -```dart -const like = 'sample'; -``` - -## Additional information - -TODO: Tell users more about the package: where to find more information, how to -contribute to the package, how to file issues, what response they can expect -from the package authors, and more. +# matule_query diff --git a/lib/src/data/repository/client.dart b/lib/src/data/repository/client.dart index 1230268..1013961 100644 --- a/lib/src/data/repository/client.dart +++ b/lib/src/data/repository/client.dart @@ -13,4 +13,15 @@ class Client extends Repository { ? {"Authorization": "Bearer ${_authModel!.token}"} : null, ); + + @override + Future login(String identity, String password) async { + Response response = await dio.post( + "$apiUrl/collections/users/auth-with-password", + data: {"identity": identity, "password": password}, + options: options, + ); + _authModel = AuthModel.fromJSON(response.data); + return _authModel!; + } } diff --git a/lib/src/data/repository/repository.dart b/lib/src/data/repository/repository.dart index 42fa394..2e4fc8f 100644 --- a/lib/src/data/repository/repository.dart +++ b/lib/src/data/repository/repository.dart @@ -1,6 +1,9 @@ import 'package:dio/dio.dart'; +import 'package:matule_query/matule_query.dart'; abstract class Repository { final Dio dio = Dio(); abstract final String apiUrl; + + Future login(String identity, String password); } diff --git a/lib/src/domain/use_cases/base_use_case.dart b/lib/src/domain/use_cases/base_use_case.dart index e72ca4e..345801c 100644 --- a/lib/src/domain/use_cases/base_use_case.dart +++ b/lib/src/domain/use_cases/base_use_case.dart @@ -6,6 +6,7 @@ class BaseUseCase { final Function(Object?) onResponse; final Function(Exception) onError; final QueryHelper helper; + final Client client = Client(); BaseUseCase({ required this.startLoading, @@ -13,4 +14,12 @@ class BaseUseCase { required this.onResponse, required this.onError, }) : helper = QueryHelper(startLoading: startLoading, endLoading: endLoading); + + Future login(String identity, String password) async { + await helper.request( + () => client.login(identity, password), + onResponse, + onError, + ); + } } diff --git a/test/matule_query_test.dart b/test/matule_query_test.dart index 6846457..618717e 100644 --- a/test/matule_query_test.dart +++ b/test/matule_query_test.dart @@ -20,8 +20,13 @@ BaseUseCase useCase = BaseUseCase( }, ); +final String _email = "example@test.russ"; +final String _password = "stringss"; + void main() { group("Query", () { - test("Authorization", () async {}); + test("Authorization", () async { + await useCase.login(_email, _password); + }); }); }