server/lib/apis/cart.dart
2025-05-27 10:38:24 +03:00

31 lines
742 B
Dart

import 'package:dio/dio.dart';
import 'package:server/apis/auth.dart';
import 'package:server/client.dart';
class Cart {
String lastError = '';
addToCart() async {
try {
final id = await auth.setToken();
if (id != null) {
final response = await api.post(
'/collections/cart/records',
data: {'user_id': id, 'product_id': 'string', 'count': 10},
);
if (response.data != null) {
return 'Well done';
}
}
} on DioException catch (e) {
if (e.type == DioExceptionType.connectionError) {
return "Internet Connection Error";
}
return e.response!.data['message'];
} catch (e) {
print(e);
return Error();
}
}
}