From 7a4a8c8f68fdc7281951da8df04333d1a7466615 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Tue, 27 Dec 2022 11:12:00 +0400 Subject: [PATCH] fix: Change url for posts --- lib/logic/server_api.dart | 63 ++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/lib/logic/server_api.dart b/lib/logic/server_api.dart index c0b24a2..0ef6a94 100644 --- a/lib/logic/server_api.dart +++ b/lib/logic/server_api.dart @@ -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> 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); + final Response response = await client.post( + '/items/', + data: item.toJson(), + ); + final Item createdItem = + Item.fromJson(response.data as Map); return ApiResponse( statusCode: response.statusCode ?? 0, data: createdItem, @@ -89,12 +92,16 @@ class ServerApi { // Update an item Future> 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); + 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); return ApiResponse( statusCode: response.statusCode ?? 0, data: updatedItem, @@ -105,7 +112,8 @@ class ServerApi { Future> 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); + final Item deletedItem = + Item.fromJson(response.data as Map); return ApiResponse( statusCode: response.statusCode ?? 0, data: deletedItem, @@ -139,8 +147,12 @@ class ServerApi { // Add a courier Future> 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); + final Response response = await client.post( + '/couriers/', + data: courier.toJson(), + ); + final Courier createdCourier = + Courier.fromJson(response.data as Map); return ApiResponse( statusCode: response.statusCode ?? 0, data: createdCourier, @@ -150,8 +162,12 @@ class ServerApi { // Update a courier Future> 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); + final Response response = await client.put( + '/couriers/${courier.id}', + data: courier.toJson(), + ); + final Courier updatedCourier = + Courier.fromJson(response.data as Map); return ApiResponse( statusCode: response.statusCode ?? 0, data: updatedCourier, @@ -162,7 +178,8 @@ class ServerApi { Future> 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); + final Courier courier = + Courier.fromJson(response.data as Map); return ApiResponse( statusCode: response.statusCode ?? 0, data: courier, @@ -196,8 +213,10 @@ class ServerApi { // Create an order Future> 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); + final Response response = + await client.post('/orders/', data: order.toJsonAsNew()); + final Order createdOrder = + Order.fromJson(response.data as Map); return ApiResponse( statusCode: response.statusCode ?? 0, data: createdOrder, @@ -207,8 +226,10 @@ class ServerApi { // Update an order Future> 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); + final Response response = + await client.put('/orders/${order.id}', data: order.toJson()); + final Order updatedOrder = + Order.fromJson(response.data as Map); return ApiResponse( statusCode: response.statusCode ?? 0, data: updatedOrder,