Оформление заказа-8

This commit is contained in:
PROF25-FINAL 2025-05-27 12:57:11 +03:00
parent a724d955e6
commit a41b9840aa
4 changed files with 40 additions and 0 deletions

View File

@ -155,4 +155,18 @@ class Client extends Repository {
); );
return CartModel.fromJSON(response.data); return CartModel.fromJSON(response.data);
} }
@override
Future<CartModel> createOrder(CartModel cartModel) async {
Response response = await dio.post(
"$apiUrl/collections/orders/records",
options: options,
data: {
"user_id": cartModel.userId,
"product_id": cartModel.productId,
"count": cartModel.count,
},
);
return CartModel.fromJSON(response.data);
}
} }

View File

@ -39,4 +39,6 @@ abstract class Repository {
Future<CartModel> addCart(CreateCartModel createCartModel); Future<CartModel> addCart(CreateCartModel createCartModel);
Future<CartModel> editCart(CartModel cartModel); Future<CartModel> editCart(CartModel cartModel);
Future<CartModel> createOrder(CartModel cartModel);
} }

View File

@ -136,4 +136,16 @@ class BaseUseCase {
) async { ) async {
await helper.request(() => client.editCart(cartModel), onResponse, onError); await helper.request(() => client.editCart(cartModel), onResponse, onError);
} }
Future<void> createOrder(
CartModel cartModel,
Function(CartModel) onResponse,
Function(Exception) onError,
) async {
await helper.request(
() => client.createOrder(cartModel),
onResponse,
onError,
);
}
} }

View File

@ -116,5 +116,17 @@ void main() {
onError, onError,
); );
}); });
test("CreateOrder", () async {
await useCase.createOrder(
CartModel(
id: cartModel.id,
userId: _userId,
productId: _productId,
count: 8,
),
onResponse,
onError,
);
});
}); });
} }