fix: Change url for posts
This commit is contained in:
parent
bc19399064
commit
7a4a8c8f68
|
@ -29,7 +29,7 @@ class ServerApi {
|
|||
(final HttpClient client) {
|
||||
client.badCertificateCallback =
|
||||
(final X509Certificate cert, final String host, final int port) =>
|
||||
true;
|
||||
true;
|
||||
return client;
|
||||
};
|
||||
|
||||
|
@ -49,8 +49,7 @@ class ServerApi {
|
|||
return dio;
|
||||
}
|
||||
|
||||
BaseOptions get options =>
|
||||
BaseOptions(
|
||||
BaseOptions get options => BaseOptions(
|
||||
baseUrl: 'http://10.100.0.6:8888/api/v1',
|
||||
connectTimeout: 10000,
|
||||
receiveTimeout: 10000,
|
||||
|
@ -78,8 +77,12 @@ class ServerApi {
|
|||
// Create an item
|
||||
Future<ApiResponse<Item>> createItem(final Item item) async {
|
||||
final Dio client = await getClient();
|
||||
final Response response = await client.post('/items', data: item.toJson(),);
|
||||
final Item createdItem = Item.fromJson(response.data as Map<String, dynamic>);
|
||||
final Response response = await client.post(
|
||||
'/items/',
|
||||
data: item.toJson(),
|
||||
);
|
||||
final Item createdItem =
|
||||
Item.fromJson(response.data as Map<String, dynamic>);
|
||||
return ApiResponse<Item>(
|
||||
statusCode: response.statusCode ?? 0,
|
||||
data: createdItem,
|
||||
|
@ -89,12 +92,16 @@ class ServerApi {
|
|||
// Update an item
|
||||
Future<ApiResponse<Item>> updateItem(final Item item) async {
|
||||
final Dio client = await getClient();
|
||||
final Response response = await client.put('/items/${item.id}', data: {
|
||||
'title': item.title,
|
||||
'description': item.description,
|
||||
'price': item.price,
|
||||
},);
|
||||
final Item updatedItem = Item.fromJson(response.data as Map<String, dynamic>);
|
||||
final Response response = await client.put(
|
||||
'/items/${item.id}',
|
||||
data: {
|
||||
'title': item.title,
|
||||
'description': item.description,
|
||||
'price': item.price,
|
||||
},
|
||||
);
|
||||
final Item updatedItem =
|
||||
Item.fromJson(response.data as Map<String, dynamic>);
|
||||
return ApiResponse<Item>(
|
||||
statusCode: response.statusCode ?? 0,
|
||||
data: updatedItem,
|
||||
|
@ -105,7 +112,8 @@ class ServerApi {
|
|||
Future<ApiResponse<Item>> deleteItem(final Item item) async {
|
||||
final Dio client = await getClient();
|
||||
final Response response = await client.delete('/items/${item.id}');
|
||||
final Item deletedItem = Item.fromJson(response.data as Map<String, dynamic>);
|
||||
final Item deletedItem =
|
||||
Item.fromJson(response.data as Map<String, dynamic>);
|
||||
return ApiResponse<Item>(
|
||||
statusCode: response.statusCode ?? 0,
|
||||
data: deletedItem,
|
||||
|
@ -139,8 +147,12 @@ class ServerApi {
|
|||
// Add a courier
|
||||
Future<ApiResponse<Courier>> addCourier(final Courier courier) async {
|
||||
final Dio client = await getClient();
|
||||
final Response response = await client.post('/couriers', data: courier.toJson(),);
|
||||
final Courier createdCourier = Courier.fromJson(response.data as Map<String, dynamic>);
|
||||
final Response response = await client.post(
|
||||
'/couriers/',
|
||||
data: courier.toJson(),
|
||||
);
|
||||
final Courier createdCourier =
|
||||
Courier.fromJson(response.data as Map<String, dynamic>);
|
||||
return ApiResponse<Courier>(
|
||||
statusCode: response.statusCode ?? 0,
|
||||
data: createdCourier,
|
||||
|
@ -150,8 +162,12 @@ class ServerApi {
|
|||
// Update a courier
|
||||
Future<ApiResponse<Courier>> updateCourier(final Courier courier) async {
|
||||
final Dio client = await getClient();
|
||||
final Response response = await client.put('/couriers/${courier.id}', data: courier.toJson(),);
|
||||
final Courier updatedCourier = Courier.fromJson(response.data as Map<String, dynamic>);
|
||||
final Response response = await client.put(
|
||||
'/couriers/${courier.id}',
|
||||
data: courier.toJson(),
|
||||
);
|
||||
final Courier updatedCourier =
|
||||
Courier.fromJson(response.data as Map<String, dynamic>);
|
||||
return ApiResponse<Courier>(
|
||||
statusCode: response.statusCode ?? 0,
|
||||
data: updatedCourier,
|
||||
|
@ -162,7 +178,8 @@ class ServerApi {
|
|||
Future<ApiResponse<Courier>> getCourier(final int id) async {
|
||||
final Dio client = await getClient();
|
||||
final Response response = await client.get('/couriers/$id');
|
||||
final Courier courier = Courier.fromJson(response.data as Map<String, dynamic>);
|
||||
final Courier courier =
|
||||
Courier.fromJson(response.data as Map<String, dynamic>);
|
||||
return ApiResponse<Courier>(
|
||||
statusCode: response.statusCode ?? 0,
|
||||
data: courier,
|
||||
|
@ -196,8 +213,10 @@ class ServerApi {
|
|||
// Create an order
|
||||
Future<ApiResponse<Order>> createOrder(final Order order) async {
|
||||
final Dio client = await getClient();
|
||||
final Response response = await client.post('/orders', data: order.toJsonAsNew());
|
||||
final Order createdOrder = Order.fromJson(response.data as Map<String, dynamic>);
|
||||
final Response response =
|
||||
await client.post('/orders/', data: order.toJsonAsNew());
|
||||
final Order createdOrder =
|
||||
Order.fromJson(response.data as Map<String, dynamic>);
|
||||
return ApiResponse<Order>(
|
||||
statusCode: response.statusCode ?? 0,
|
||||
data: createdOrder,
|
||||
|
@ -207,8 +226,10 @@ class ServerApi {
|
|||
// Update an order
|
||||
Future<ApiResponse<Order>> updateOrder(final Order order) async {
|
||||
final Dio client = await getClient();
|
||||
final Response response = await client.put('/orders/${order.id}', data: order.toJson());
|
||||
final Order updatedOrder = Order.fromJson(response.data as Map<String, dynamic>);
|
||||
final Response response =
|
||||
await client.put('/orders/${order.id}', data: order.toJson());
|
||||
final Order updatedOrder =
|
||||
Order.fromJson(response.data as Map<String, dynamic>);
|
||||
return ApiResponse<Order>(
|
||||
statusCode: response.statusCode ?? 0,
|
||||
data: updatedOrder,
|
||||
|
|
Loading…
Reference in a new issue