From 577b746b8cd4aafa7855c8aff381d6b04d857d38 Mon Sep 17 00:00:00 2001 From: User3 Date: Tue, 27 May 2025 10:08:54 +0300 Subject: [PATCH] #sprint-1 --- lib/apis/auth.dart | 71 ++++++++++++++++++++++++++++++++++++++++--- test/server_test.dart | 24 +++++++++++++++ 2 files changed, 90 insertions(+), 5 deletions(-) diff --git a/lib/apis/auth.dart b/lib/apis/auth.dart index 309ded0..a2b23e7 100644 --- a/lib/apis/auth.dart +++ b/lib/apis/auth.dart @@ -20,13 +20,28 @@ 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.post( - '/collections/users/records', - data: {emailKey: email, passwordKey: password}, + final response = await api.patch( + '/collections/users/record/$userId', + data: { + 'firstname': firstName, + 'lastname': lastname, + 'secondname': secondName, + 'datebirthday': datebirthday, + 'gender': gender, + }, ); - return response.data; + if (response.data != null) { + return response.data; + } } on DioException catch (e) { if (e.type == DioExceptionType.connectionError) { lastError = 'Internet Connection Error'; @@ -35,6 +50,52 @@ class Auth { } } } + + 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, + confirmPasswordKey: password, + }, + ); + 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'; + } else { + lastError = e.response!.data['message']; + } + } + } + } } final auth = Auth(); diff --git a/test/server_test.dart b/test/server_test.dart index 639965d..f01538b 100644 --- a/test/server_test.dart +++ b/test/server_test.dart @@ -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); } });