#sprint-1
This commit is contained in:
parent
080d7d137e
commit
a131c3d241
@ -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(
|
register(
|
||||||
String email,
|
String email,
|
||||||
String password,
|
String password,
|
||||||
|
30
lib/apis/cart.dart
Normal file
30
lib/apis/cart.dart
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,16 +7,8 @@ import 'package:server/client.dart';
|
|||||||
class Shop {
|
class Shop {
|
||||||
String lastError = '';
|
String lastError = '';
|
||||||
getCatalog() async {
|
getCatalog() async {
|
||||||
String token = '';
|
await auth.setToken();
|
||||||
try {
|
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');
|
final response = await api.get('collections/products/records');
|
||||||
if (response.data != null) {
|
if (response.data != null) {
|
||||||
return response.data;
|
return response.data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user