change user payload

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2023-06-22 00:43:17 +08:00
parent 8dd218235d
commit 54cc45dd66
3 changed files with 25 additions and 23 deletions

View File

@@ -14,31 +14,37 @@ class HttpType {
static const kAuthResTypeEmailCheck = "email_check";
}
enum UserStatus { kDisabled, kNormal, kUnverified }
// to-do: The UserPayload does not contain all the fields of the user.
// Is all the fields of the user needed?
class UserPayload {
String id = '';
String name = '';
String email = '';
String note = '';
int? status;
UserStatus status;
bool isAdmin = false;
UserPayload.fromJson(Map<String, dynamic> json)
: id = json['id'] ?? '',
name = json['name'] ?? '',
: name = json['name'] ?? '',
email = json['email'] ?? '',
note = json['note'] ?? '',
status = json['status'],
status = json['status'] == 0
? UserStatus.kDisabled
: json['status'] == -1
? UserStatus.kUnverified
: UserStatus.kNormal,
isAdmin = json['is_admin'] == true;
Map<String, dynamic> toJson() {
final Map<String, dynamic> map = {
'name': name,
'status': status == UserStatus.kDisabled
? 0
: status == UserStatus.kUnverified
? -1
: 1,
};
if (status != null) {
map['status'] = status!;
}
return map;
}
}
@@ -117,6 +123,7 @@ class LoginResponse {
LoginResponse.fromJson(Map<String, dynamic> json) {
access_token = json['access_token'];
type = json['type'];
print('REMOVE ME ================== $json');
user = json['user'] != null ? UserPayload.fromJson(json['user']) : null;
}
}