fix: Change url for posts

This commit is contained in:
NaiJi 2022-12-27 11:12:00 +04:00
parent bc19399064
commit 7a4a8c8f68

View file

@ -49,8 +49,7 @@ class ServerApi {
return dio; return dio;
} }
BaseOptions get options => BaseOptions get options => BaseOptions(
BaseOptions(
baseUrl: 'http://10.100.0.6:8888/api/v1', baseUrl: 'http://10.100.0.6:8888/api/v1',
connectTimeout: 10000, connectTimeout: 10000,
receiveTimeout: 10000, receiveTimeout: 10000,
@ -78,8 +77,12 @@ class ServerApi {
// Create an item // Create an item
Future<ApiResponse<Item>> createItem(final Item item) async { Future<ApiResponse<Item>> createItem(final Item item) async {
final Dio client = await getClient(); final Dio client = await getClient();
final Response response = await client.post('/items', data: item.toJson(),); final Response response = await client.post(
final Item createdItem = Item.fromJson(response.data as Map<String, dynamic>); '/items/',
data: item.toJson(),
);
final Item createdItem =
Item.fromJson(response.data as Map<String, dynamic>);
return ApiResponse<Item>( return ApiResponse<Item>(
statusCode: response.statusCode ?? 0, statusCode: response.statusCode ?? 0,
data: createdItem, data: createdItem,
@ -89,12 +92,16 @@ class ServerApi {
// Update an item // Update an item
Future<ApiResponse<Item>> updateItem(final Item item) async { Future<ApiResponse<Item>> updateItem(final Item item) async {
final Dio client = await getClient(); final Dio client = await getClient();
final Response response = await client.put('/items/${item.id}', data: { final Response response = await client.put(
'/items/${item.id}',
data: {
'title': item.title, 'title': item.title,
'description': item.description, 'description': item.description,
'price': item.price, 'price': item.price,
},); },
final Item updatedItem = Item.fromJson(response.data as Map<String, dynamic>); );
final Item updatedItem =
Item.fromJson(response.data as Map<String, dynamic>);
return ApiResponse<Item>( return ApiResponse<Item>(
statusCode: response.statusCode ?? 0, statusCode: response.statusCode ?? 0,
data: updatedItem, data: updatedItem,
@ -105,7 +112,8 @@ class ServerApi {
Future<ApiResponse<Item>> deleteItem(final Item item) async { Future<ApiResponse<Item>> deleteItem(final Item item) async {
final Dio client = await getClient(); final Dio client = await getClient();
final Response response = await client.delete('/items/${item.id}'); 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>( return ApiResponse<Item>(
statusCode: response.statusCode ?? 0, statusCode: response.statusCode ?? 0,
data: deletedItem, data: deletedItem,
@ -139,8 +147,12 @@ class ServerApi {
// Add a courier // Add a courier
Future<ApiResponse<Courier>> addCourier(final Courier courier) async { Future<ApiResponse<Courier>> addCourier(final Courier courier) async {
final Dio client = await getClient(); final Dio client = await getClient();
final Response response = await client.post('/couriers', data: courier.toJson(),); final Response response = await client.post(
final Courier createdCourier = Courier.fromJson(response.data as Map<String, dynamic>); '/couriers/',
data: courier.toJson(),
);
final Courier createdCourier =
Courier.fromJson(response.data as Map<String, dynamic>);
return ApiResponse<Courier>( return ApiResponse<Courier>(
statusCode: response.statusCode ?? 0, statusCode: response.statusCode ?? 0,
data: createdCourier, data: createdCourier,
@ -150,8 +162,12 @@ class ServerApi {
// Update a courier // Update a courier
Future<ApiResponse<Courier>> updateCourier(final Courier courier) async { Future<ApiResponse<Courier>> updateCourier(final Courier courier) async {
final Dio client = await getClient(); final Dio client = await getClient();
final Response response = await client.put('/couriers/${courier.id}', data: courier.toJson(),); final Response response = await client.put(
final Courier updatedCourier = Courier.fromJson(response.data as Map<String, dynamic>); '/couriers/${courier.id}',
data: courier.toJson(),
);
final Courier updatedCourier =
Courier.fromJson(response.data as Map<String, dynamic>);
return ApiResponse<Courier>( return ApiResponse<Courier>(
statusCode: response.statusCode ?? 0, statusCode: response.statusCode ?? 0,
data: updatedCourier, data: updatedCourier,
@ -162,7 +178,8 @@ class ServerApi {
Future<ApiResponse<Courier>> getCourier(final int id) async { Future<ApiResponse<Courier>> getCourier(final int id) async {
final Dio client = await getClient(); final Dio client = await getClient();
final Response response = await client.get('/couriers/$id'); 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>( return ApiResponse<Courier>(
statusCode: response.statusCode ?? 0, statusCode: response.statusCode ?? 0,
data: courier, data: courier,
@ -196,8 +213,10 @@ class ServerApi {
// Create an order // Create an order
Future<ApiResponse<Order>> createOrder(final Order order) async { Future<ApiResponse<Order>> createOrder(final Order order) async {
final Dio client = await getClient(); final Dio client = await getClient();
final Response response = await client.post('/orders', data: order.toJsonAsNew()); final Response response =
final Order createdOrder = Order.fromJson(response.data as Map<String, dynamic>); await client.post('/orders/', data: order.toJsonAsNew());
final Order createdOrder =
Order.fromJson(response.data as Map<String, dynamic>);
return ApiResponse<Order>( return ApiResponse<Order>(
statusCode: response.statusCode ?? 0, statusCode: response.statusCode ?? 0,
data: createdOrder, data: createdOrder,
@ -207,8 +226,10 @@ class ServerApi {
// Update an order // Update an order
Future<ApiResponse<Order>> updateOrder(final Order order) async { Future<ApiResponse<Order>> updateOrder(final Order order) async {
final Dio client = await getClient(); final Dio client = await getClient();
final Response response = await client.put('/orders/${order.id}', data: order.toJson()); final Response response =
final Order updatedOrder = Order.fromJson(response.data as Map<String, dynamic>); await client.put('/orders/${order.id}', data: order.toJson());
final Order updatedOrder =
Order.fromJson(response.data as Map<String, dynamic>);
return ApiResponse<Order>( return ApiResponse<Order>(
statusCode: response.statusCode ?? 0, statusCode: response.statusCode ?? 0,
data: updatedOrder, data: updatedOrder,