#sprint-1

This commit is contained in:
User3 2025-05-27 10:38:24 +03:00
parent 080d7d137e
commit a131c3d241
3 changed files with 44 additions and 9 deletions

View File

@ -51,6 +51,19 @@ class Auth {
}
}
setToken() async {
String token = '';
final loginResponse = await auth.login(
'example123123333333@mail.ru',
'string213123',
);
if (loginResponse != null) {
token = loginResponse['token'];
api.options.headers['Authorization'] = "Bearer $token";
return loginResponse['records']['id'];
}
}
register(
String email,
String password,

30
lib/apis/cart.dart Normal file
View File

@ -0,0 +1,30 @@
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();
}
}
}

View File

@ -7,16 +7,8 @@ import 'package:server/client.dart';
class Shop {
String lastError = '';
getCatalog() async {
String token = '';
await auth.setToken();
try {
final loginResponse = await auth.login(
'example123123333333@mail.ru',
'string213123',
);
if (loginResponse != null) {
token = loginResponse['token'];
api.options.headers['Authorization'] = "Bearer ${token}";
}
final response = await api.get('collections/products/records');
if (response.data != null) {
return response.data;