Base user workflow (create/update)
This commit is contained in:
parent
eb5d3e2b70
commit
45be2c80ff
8 changed files with 528 additions and 17 deletions
|
|
@ -6,6 +6,7 @@ import 'package:http/browser_client.dart';
|
|||
import 'package:http/http.dart';
|
||||
import 'package:tuuli_app/api/model/table_field_model.dart';
|
||||
import 'package:tuuli_app/api/model/tables_list_model.dart';
|
||||
import 'package:tuuli_app/api/model/user_model.dart';
|
||||
|
||||
class ErrorOrData<T> {
|
||||
final T? data;
|
||||
|
|
@ -292,6 +293,69 @@ class ApiClient {
|
|||
return ErrorOrData(ignored, error);
|
||||
}
|
||||
|
||||
FutureErrorOrData<bool> createUser(
|
||||
TableModel table, String username, String password) async {
|
||||
bool? ignored;
|
||||
Exception? error;
|
||||
|
||||
final response = await post(
|
||||
'/api/createUser',
|
||||
body: {
|
||||
"username": username,
|
||||
"password": password,
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final body = json.decode(await response.stream.bytesToString());
|
||||
if (body['error'] != null) {
|
||||
error = Exception(body['error']);
|
||||
} else {
|
||||
ignored = true;
|
||||
}
|
||||
} else if (response.statusCode == 422) {
|
||||
error = Exception('Invalid request parameters');
|
||||
} else {
|
||||
error = Exception('HTTP ${response.statusCode}');
|
||||
}
|
||||
|
||||
return ErrorOrData(ignored, error);
|
||||
}
|
||||
|
||||
FutureErrorOrData<bool> updateUser(
|
||||
TableModel table, int userId, String password, String accessToken) async {
|
||||
bool? ignored;
|
||||
Exception? error;
|
||||
|
||||
final response = await post(
|
||||
'/api/updateUser',
|
||||
body: {
|
||||
"user_id": userId,
|
||||
"password": password,
|
||||
"access_token": accessToken,
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final body = json.decode(await response.stream.bytesToString());
|
||||
if (body['error'] != null) {
|
||||
error = Exception(body['error']);
|
||||
} else {
|
||||
ignored = true;
|
||||
}
|
||||
} else if (response.statusCode == 422) {
|
||||
error = Exception('Invalid request parameters');
|
||||
} else {
|
||||
error = Exception('HTTP ${response.statusCode}');
|
||||
}
|
||||
|
||||
return ErrorOrData(ignored, error);
|
||||
}
|
||||
|
||||
// REGION: HTTP Methods implementation
|
||||
|
||||
Future<StreamedResponse> get(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue