Оформление заказа-8
This commit is contained in:
parent
a724d955e6
commit
a41b9840aa
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user