#sprint-1

This commit is contained in:
User3 2025-05-27 10:08:54 +03:00
parent 583ac3643b
commit 577b746b8c
2 changed files with 90 additions and 5 deletions

View File

@ -20,13 +20,73 @@ class Auth {
}
}
register(String email, String password) async {
updateUser(
String userId,
String firstName,
String lastname,
String secondName,
String datebirthday,
String gender,
) async {
try {
final response = await api.patch(
'/collections/users/record/$userId',
data: {
'firstname': firstName,
'lastname': lastname,
'secondname': secondName,
'datebirthday': datebirthday,
'gender': gender,
},
);
if (response.data != null) {
return response.data;
}
} on DioException catch (e) {
if (e.type == DioExceptionType.connectionError) {
lastError = 'Internet Connection Error';
} else {
lastError = e.response!.data['message'];
}
}
}
register(
String email,
String password,
String confirmPassword,
String firstName,
String lastname,
String secondName,
String datebirthday,
String gender,
) async {
if (password != confirmPassword) {
lastError = 'Confirm password != password';
} else {
try {
final response = await api.post(
'/collections/users/records',
data: {emailKey: email, passwordKey: password},
data: {
emailKey: email,
passwordKey: password,
confirmPasswordKey: password,
},
);
return response.data;
if (response.data != null) {
final responseData = response.data['id'];
final result = await updateUser(
responseData,
firstName,
lastname,
secondName,
datebirthday,
gender,
);
if (response.data) {
return result;
}
}
} on DioException catch (e) {
if (e.type == DioExceptionType.connectionError) {
lastError = 'Internet Connection Error';
@ -36,5 +96,6 @@ class Auth {
}
}
}
}
final auth = Auth();

View File

@ -12,6 +12,30 @@ void main() {
expect(response['record']['email'], 'example123123@test.ru');
}
} catch (e) {
// ignore: avoid_print
print(e);
}
});
test('Спринт 2. Создание пользователя', () async {
try {
final response = await auth.register(
'example123123333333@mail.ru',
'string213123',
'string213123',
'testtest',
'testtest',
'testtest',
'testtest',
'testtest',
);
if (response != null) {
expect(response['record']['firstname'], 'testtest');
} else {
expect('1', '2');
}
} catch (e) {
// ignore: avoid_print
print(e);
}
});