Получение каталога-8

This commit is contained in:
PROF25-FINAL 2025-05-27 11:31:25 +03:00
parent f0dca69185
commit d00f207338
6 changed files with 52 additions and 0 deletions

View File

@ -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";

View File

@ -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<String, dynamic> json)
: approximateCost = json["approximate_cost"],
description = json["description"],
id = json["id"],
price = json["price"],
title = json["title"],
type = json["type"],
typeCloses = json["typeCloses"];
}

View File

@ -67,4 +67,15 @@ class Client extends Repository {
);
return MetadataModel.fromJSON(response.data);
}
@override
Future<List<ProductModel>> 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();
}
}

View File

@ -23,4 +23,6 @@ abstract class Repository {
String? dateBirthday,
String? gender,
);
Future<List<ProductModel>> getProductList();
}

View File

@ -63,4 +63,11 @@ class BaseUseCase {
onError,
);
}
Future<void> getProductList(
Function(List<ProductModel>) onResponse,
Function(Exception) onError,
) async {
await helper.request(() => client.getProductList(), onResponse, onError);
}
}

View File

@ -59,5 +59,8 @@ void main() {
onError,
);
});
test("ProductList", () async {
await useCase.getProductList(onResponse, onError);
});
});
}