From 0c06f60ab19b8ea6ed09e3c377bf2c44345fde3a Mon Sep 17 00:00:00 2001 From: PROF25-FINAL Date: Tue, 27 May 2025 10:08:54 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=B0=D0=BA=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 31 +++++++++++ .metadata | 10 ++++ README.md | 40 +++++++++++++- analysis_options.yaml | 4 ++ lib/matule_query.dart | 11 ++++ lib/src/data/models/auth_model.dart | 12 +++++ lib/src/data/models/metadata_model.dart | 28 ++++++++++ lib/src/data/repository/client.dart | 16 ++++++ lib/src/data/repository/repository.dart | 6 +++ lib/src/domain/services/query_helper.dart | 22 ++++++++ lib/src/domain/use_cases/base_use_case.dart | 16 ++++++ pubspec.yaml | 58 +++++++++++++++++++++ test/matule_query_test.dart | 27 ++++++++++ 13 files changed, 280 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 .metadata create mode 100644 analysis_options.yaml create mode 100644 lib/matule_query.dart create mode 100644 lib/src/data/models/auth_model.dart create mode 100644 lib/src/data/models/metadata_model.dart create mode 100644 lib/src/data/repository/client.dart create mode 100644 lib/src/data/repository/repository.dart create mode 100644 lib/src/domain/services/query_helper.dart create mode 100644 lib/src/domain/use_cases/base_use_case.dart create mode 100644 pubspec.yaml create mode 100644 test/matule_query_test.dart diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb6c05c --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +build/ diff --git a/.metadata b/.metadata new file mode 100644 index 0000000..91a5e0b --- /dev/null +++ b/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: "be698c48a6750c8cb8e61c740ca9991bb947aba2" + channel: "stable" + +project_type: package diff --git a/README.md b/README.md index a31f192..4a260d8 100644 --- a/README.md +++ b/README.md @@ -1 +1,39 @@ -# matule_query \ No newline at end of file + + +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. diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..a5744c1 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:flutter_lints/flutter.yaml + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/lib/matule_query.dart b/lib/matule_query.dart new file mode 100644 index 0000000..1386b1e --- /dev/null +++ b/lib/matule_query.dart @@ -0,0 +1,11 @@ +library; + +export "src/data/models/auth_model.dart"; +export "src/data/models/metadata_model.dart"; + +export "src/data/repository/client.dart"; +export "src/data/repository/repository.dart"; + +export "src/domain/services/query_helper.dart"; + +export "src/domain/use_cases/base_use_case.dart"; diff --git a/lib/src/data/models/auth_model.dart b/lib/src/data/models/auth_model.dart new file mode 100644 index 0000000..c60af9e --- /dev/null +++ b/lib/src/data/models/auth_model.dart @@ -0,0 +1,12 @@ +import 'package:matule_query/matule_query.dart'; + +class AuthModel { + final String token; + final MetadataModel record; + + AuthModel({required this.token, required this.record}); + + AuthModel.fromJSON(Map json) + : token = json["token"], + record = MetadataModel.fromJSON(json["record"]); +} diff --git a/lib/src/data/models/metadata_model.dart b/lib/src/data/models/metadata_model.dart new file mode 100644 index 0000000..94602c3 --- /dev/null +++ b/lib/src/data/models/metadata_model.dart @@ -0,0 +1,28 @@ +class MetadataModel { + final String email; + final String dateBirthday; + final String firstName; + final String gender; + final String id; + final String lastName; + final String secondName; + + MetadataModel({ + required this.email, + required this.dateBirthday, + required this.firstName, + required this.gender, + required this.id, + required this.lastName, + required this.secondName, + }); + + MetadataModel.fromJSON(Map json) + : email = json["email"], + dateBirthday = json["dateBirthday"], + firstName = json["firstname"], + gender = json["gender"], + id = json["id"], + lastName = json["lastname"], + secondName = json["secondname"]; +} diff --git a/lib/src/data/repository/client.dart b/lib/src/data/repository/client.dart new file mode 100644 index 0000000..1230268 --- /dev/null +++ b/lib/src/data/repository/client.dart @@ -0,0 +1,16 @@ +import 'package:dio/dio.dart'; + +import '../../../matule_query.dart'; + +class Client extends Repository { + @override + String get apiUrl => "https://api.matule.ru/api"; + + AuthModel? _authModel; + + Options get options => Options( + headers: (_authModel != null) + ? {"Authorization": "Bearer ${_authModel!.token}"} + : null, + ); +} diff --git a/lib/src/data/repository/repository.dart b/lib/src/data/repository/repository.dart new file mode 100644 index 0000000..42fa394 --- /dev/null +++ b/lib/src/data/repository/repository.dart @@ -0,0 +1,6 @@ +import 'package:dio/dio.dart'; + +abstract class Repository { + final Dio dio = Dio(); + abstract final String apiUrl; +} diff --git a/lib/src/domain/services/query_helper.dart b/lib/src/domain/services/query_helper.dart new file mode 100644 index 0000000..067e4e0 --- /dev/null +++ b/lib/src/domain/services/query_helper.dart @@ -0,0 +1,22 @@ +class QueryHelper { + final Function() startLoading; + final Function() endLoading; + + QueryHelper({required this.startLoading, required this.endLoading}); + + Future request( + Future Function() request, + void Function(ResponseT) onResponse, + void Function(Exception) onError, + ) async { + try { + startLoading(); + ResponseT response = await request(); + endLoading(); + onResponse(response); + } on Exception catch (e) { + endLoading(); + onError(e); + } + } +} diff --git a/lib/src/domain/use_cases/base_use_case.dart b/lib/src/domain/use_cases/base_use_case.dart new file mode 100644 index 0000000..e72ca4e --- /dev/null +++ b/lib/src/domain/use_cases/base_use_case.dart @@ -0,0 +1,16 @@ +import 'package:matule_query/matule_query.dart'; + +class BaseUseCase { + final Function() startLoading; + final Function() endLoading; + final Function(Object?) onResponse; + final Function(Exception) onError; + final QueryHelper helper; + + BaseUseCase({ + required this.startLoading, + required this.endLoading, + required this.onResponse, + required this.onError, + }) : helper = QueryHelper(startLoading: startLoading, endLoading: endLoading); +} diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..dcff319 --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,58 @@ +name: matule_query +description: "A new Flutter package project." +version: 0.0.1 +publish_to: "none" + +environment: + sdk: ^3.8.0 + flutter: ">=1.17.0" + +dependencies: + connectivity_plus: ^6.1.4 + dio: ^5.8.0+1 + intl: ^0.20.2 + flutter: + sdk: flutter + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^5.0.0 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + uses-material-design: true + + # To add assets to your package, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + # + # For details regarding assets in packages, see + # https://flutter.dev/to/asset-from-package + # + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/to/resolution-aware-images + + # To add custom fonts to your package, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts in packages, see + # https://flutter.dev/to/font-from-package diff --git a/test/matule_query_test.dart b/test/matule_query_test.dart new file mode 100644 index 0000000..6846457 --- /dev/null +++ b/test/matule_query_test.dart @@ -0,0 +1,27 @@ +import 'dart:io'; + +import 'package:flutter_test/flutter_test.dart'; +import "package:dio/dio.dart"; +import 'package:matule_query/matule_query.dart'; + +String get testString => DateTime.now().millisecondsSinceEpoch.toString(); + +Options get options => Options(headers: {}); + +BaseUseCase useCase = BaseUseCase( + startLoading: () {}, + endLoading: () {}, + onResponse: (Object? obj) { + stdout.writeln(obj.toString()); + assert(true); + }, + onError: (Exception e) { + fail(e.toString()); + }, +); + +void main() { + group("Query", () { + test("Authorization", () async {}); + }); +}