user_models.dart
5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import 'package:json_annotation/json_annotation.dart';
part 'user_models.g.dart';
// ─── Requests(手写 toJson,无 fromJson)────────────────────────────────────
class LoginRequest {
const LoginRequest({
this.loginType = 'verification_code',
required this.telephone,
required this.verificationCode,
});
final String loginType;
final String telephone;
final String verificationCode;
Map<String, dynamic> toJson() => {
'login_type': loginType,
'telephone': telephone,
'verification_code': verificationCode,
};
}
class RegisterRequest {
const RegisterRequest({
required this.telephone,
required this.verificationCode,
});
final String telephone;
final String verificationCode;
Map<String, dynamic> toJson() => {
'telephone': telephone,
'verification_code': verificationCode,
};
}
class VerifyCodeRequest {
const VerifyCodeRequest({required this.telephone, required this.scene});
final String telephone;
final int scene;
factory VerifyCodeRequest.login(String telephone) =>
VerifyCodeRequest(telephone: telephone, scene: 1);
factory VerifyCodeRequest.changeTelephone(String telephone) =>
VerifyCodeRequest(telephone: telephone, scene: 2);
Map<String, dynamic> toJson() => {
'telephone': telephone,
'scene': scene,
};
}
class BindPartnerRequest {
const BindPartnerRequest({required this.bindCode});
final String bindCode;
Map<String, dynamic> toJson() => {'pair_code': bindCode};
}
class PushTokenRequest {
const PushTokenRequest({
required this.pushToken,
required this.deviceInfo,
required this.pushPlatform,
});
final String pushToken;
final String deviceInfo;
final int pushPlatform;
Map<String, dynamic> toJson() => {
'cid': pushToken,
'device_info': deviceInfo,
'push_platform': pushPlatform,
};
}
class UserInfoUpdateRequest {
const UserInfoUpdateRequest({this.avatar, this.nickname, this.persona});
final String? avatar;
final String? nickname;
final int? persona;
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
if (avatar != null) json['avatar'] = avatar;
if (nickname != null) json['nickname'] = nickname;
if (persona != null) json['persona'] = persona;
return json;
}
}
// ─── Responses(json_annotation 代码生成)──────────────────────────────────
@JsonSerializable()
class UserAccessToken {
const UserAccessToken({this.accessToken, this.expireTime});
@JsonKey(name: 'access_token')
final String? accessToken;
@JsonKey(name: 'expire_time')
final int? expireTime;
factory UserAccessToken.fromJson(Map<String, dynamic> json) =>
_$UserAccessTokenFromJson(json);
Map<String, dynamic> toJson() => _$UserAccessTokenToJson(this);
}
@JsonSerializable()
class LoginResponse {
const LoginResponse({this.isNewUser, this.accessTokenInfo, this.id});
@JsonKey(name: 'is_new_user')
final bool? isNewUser;
@JsonKey(name: 'token_info')
final UserAccessToken? accessTokenInfo;
final int? id;
String get accessToken => accessTokenInfo?.accessToken ?? '';
factory LoginResponse.fromJson(Map<String, dynamic> json) =>
_$LoginResponseFromJson(json);
Map<String, dynamic> toJson() => _$LoginResponseToJson(this);
}
@JsonSerializable()
class RegisterResponse {
const RegisterResponse({this.accessTokenInfo});
@JsonKey(name: 'token_info')
final UserAccessToken? accessTokenInfo;
String get accessToken => accessTokenInfo?.accessToken ?? '';
factory RegisterResponse.fromJson(Map<String, dynamic> json) =>
_$RegisterResponseFromJson(json);
Map<String, dynamic> toJson() => _$RegisterResponseToJson(this);
}
@JsonSerializable()
class UserInfoResponse {
const UserInfoResponse({
this.id,
this.pairCode,
this.pairId,
this.telephone,
this.nickname,
this.avatar,
this.persona,
this.status,
this.lastLoginTime,
this.createTime,
this.isBot,
});
final int? id;
@JsonKey(name: 'pair_code')
final String? pairCode;
@JsonKey(name: 'pair_id')
final int? pairId;
final String? telephone;
final String? nickname;
final String? avatar;
final int? persona;
final int? status;
@JsonKey(name: 'last_login_time')
final int? lastLoginTime;
@JsonKey(name: 'create_time')
final int? createTime;
@JsonKey(name: 'is_bot')
final int? isBot;
factory UserInfoResponse.fromJson(Map<String, dynamic> json) =>
_$UserInfoResponseFromJson(json);
Map<String, dynamic> toJson() => _$UserInfoResponseToJson(this);
}
@JsonSerializable()
class BoundUserInfoResponse {
const BoundUserInfoResponse({this.userInfo, this.partnerUserInfo});
@JsonKey(name: 'user_info')
final UserInfoResponse? userInfo;
@JsonKey(name: 'pair_user_info')
final UserInfoResponse? partnerUserInfo;
factory BoundUserInfoResponse.fromJson(Map<String, dynamic> json) =>
_$BoundUserInfoResponseFromJson(json);
Map<String, dynamic> toJson() => _$BoundUserInfoResponseToJson(this);
}
@JsonSerializable()
class RongcloudTokenResponse {
const RongcloudTokenResponse({this.token});
final String? token;
factory RongcloudTokenResponse.fromJson(Map<String, dynamic> json) =>
_$RongcloudTokenResponseFromJson(json);
Map<String, dynamic> toJson() => _$RongcloudTokenResponseToJson(this);
}