Получение каталога-8
This commit is contained in:
parent
f0dca69185
commit
d00f207338
@ -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";
|
||||
|
28
lib/src/data/models/product_model.dart
Normal file
28
lib/src/data/models/product_model.dart
Normal 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"];
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -23,4 +23,6 @@ abstract class Repository {
|
||||
String? dateBirthday,
|
||||
String? gender,
|
||||
);
|
||||
|
||||
Future<List<ProductModel>> getProductList();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -59,5 +59,8 @@ void main() {
|
||||
onError,
|
||||
);
|
||||
});
|
||||
test("ProductList", () async {
|
||||
await useCase.getProductList(onResponse, onError);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user