From d00f20733853ee1af56efd7c0438e4172df5684d Mon Sep 17 00:00:00 2001 From: PROF25-FINAL Date: Tue, 27 May 2025 11:31:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=B0=D1=82=D0=B0=D0=BB=D0=BE=D0=B3=D0=B0?= =?UTF-8?q?-8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/matule_query.dart | 1 + lib/src/data/models/product_model.dart | 28 +++++++++++++++++++++ lib/src/data/repository/client.dart | 11 ++++++++ lib/src/data/repository/repository.dart | 2 ++ lib/src/domain/use_cases/base_use_case.dart | 7 ++++++ test/matule_query_test.dart | 3 +++ 6 files changed, 52 insertions(+) create mode 100644 lib/src/data/models/product_model.dart diff --git a/lib/matule_query.dart b/lib/matule_query.dart index 1386b1e..96040a8 100644 --- a/lib/matule_query.dart +++ b/lib/matule_query.dart @@ -2,6 +2,7 @@ library; export "src/data/models/auth_model.dart"; export "src/data/models/metadata_model.dart"; +export "src/data/models/product_model.dart"; export "src/data/repository/client.dart"; export "src/data/repository/repository.dart"; diff --git a/lib/src/data/models/product_model.dart b/lib/src/data/models/product_model.dart new file mode 100644 index 0000000..968a29d --- /dev/null +++ b/lib/src/data/models/product_model.dart @@ -0,0 +1,28 @@ +class ProductModel { + final String approximateCost; + final String description; + final String id; + final int price; + final String title; + final String type; + final String typeCloses; + + ProductModel({ + required this.approximateCost, + required this.description, + required this.id, + required this.price, + required this.title, + required this.type, + required this.typeCloses, + }); + + ProductModel.fromJSON(Map json) + : approximateCost = json["approximate_cost"], + description = json["description"], + id = json["id"], + price = json["price"], + title = json["title"], + type = json["type"], + typeCloses = json["typeCloses"]; +} diff --git a/lib/src/data/repository/client.dart b/lib/src/data/repository/client.dart index cf885f5..cab942d 100644 --- a/lib/src/data/repository/client.dart +++ b/lib/src/data/repository/client.dart @@ -67,4 +67,15 @@ class Client extends Repository { ); return MetadataModel.fromJSON(response.data); } + + @override + Future> getProductList() async { + Response response = await dio.get( + "$apiUrl/collections/products/records", + options: options, + ); + return (response.data["items"] as List) + .map((e) => ProductModel.fromJSON(e)) + .toList(); + } } diff --git a/lib/src/data/repository/repository.dart b/lib/src/data/repository/repository.dart index 52974be..50979fc 100644 --- a/lib/src/data/repository/repository.dart +++ b/lib/src/data/repository/repository.dart @@ -23,4 +23,6 @@ abstract class Repository { String? dateBirthday, String? gender, ); + + Future> getProductList(); } diff --git a/lib/src/domain/use_cases/base_use_case.dart b/lib/src/domain/use_cases/base_use_case.dart index 2f67d45..31bf68e 100644 --- a/lib/src/domain/use_cases/base_use_case.dart +++ b/lib/src/domain/use_cases/base_use_case.dart @@ -63,4 +63,11 @@ class BaseUseCase { onError, ); } + + Future getProductList( + Function(List) onResponse, + Function(Exception) onError, + ) async { + await helper.request(() => client.getProductList(), onResponse, onError); + } } diff --git a/test/matule_query_test.dart b/test/matule_query_test.dart index d3aac9e..74c8661 100644 --- a/test/matule_query_test.dart +++ b/test/matule_query_test.dart @@ -59,5 +59,8 @@ void main() { onError, ); }); + test("ProductList", () async { + await useCase.getProductList(onResponse, onError); + }); }); }