user_models.dart
7.36 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
// ─── 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(手动反序列化)──────────────────────────────────
class UserAccessToken {
const UserAccessToken({this.accessToken, this.expireTime});
final String? accessToken;
final int? expireTime;
factory UserAccessToken.fromJson(Map<String, dynamic> json) {
return UserAccessToken(
accessToken: json['access_token'] as String?,
expireTime: json['expire_time'] as int?,
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (accessToken != null) val['access_token'] = accessToken;
if (expireTime != null) val['expire_time'] = expireTime;
return val;
}
}
class LoginResponse {
const LoginResponse({this.isNewUser, this.accessTokenInfo, this.id});
final bool? isNewUser;
final UserAccessToken? accessTokenInfo;
final int? id;
String get accessToken => accessTokenInfo?.accessToken ?? '';
factory LoginResponse.fromJson(Map<String, dynamic> json) {
return LoginResponse(
isNewUser: json['is_new_user'] as bool?,
accessTokenInfo: json['token_info'] == null
? null
: UserAccessToken.fromJson(json['token_info'] as Map<String, dynamic>),
id: json['id'] as int?,
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (isNewUser != null) val['is_new_user'] = isNewUser;
if (accessTokenInfo != null) val['token_info'] = accessTokenInfo!.toJson();
if (id != null) val['id'] = id;
return val;
}
}
class RegisterResponse {
const RegisterResponse({this.accessTokenInfo});
final UserAccessToken? accessTokenInfo;
String get accessToken => accessTokenInfo?.accessToken ?? '';
factory RegisterResponse.fromJson(Map<String, dynamic> json) {
return RegisterResponse(
accessTokenInfo: json['token_info'] == null
? null
: UserAccessToken.fromJson(json['token_info'] as Map<String, dynamic>),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (accessTokenInfo != null) val['token_info'] = accessTokenInfo!.toJson();
return val;
}
}
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;
final String? pairCode;
final int? pairId;
final String? telephone;
final String? nickname;
final String? avatar;
final int? persona;
final int? status;
final int? lastLoginTime;
final int? createTime;
final int? isBot;
factory UserInfoResponse.fromJson(Map<String, dynamic> json) {
return UserInfoResponse(
id: json['id'] as int?,
pairCode: json['pair_code'] as String?,
pairId: json['pair_id'] as int?,
telephone: json['telephone'] as String?,
nickname: json['nickname'] as String?,
avatar: json['avatar'] as String?,
persona: json['persona'] as int?,
status: json['status'] as int?,
lastLoginTime: json['last_login_time'] as int?,
createTime: json['create_time'] as int?,
isBot: json['is_bot'] as int?,
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (id != null) val['id'] = id;
if (pairCode != null) val['pair_code'] = pairCode;
if (pairId != null) val['pair_id'] = pairId;
if (telephone != null) val['telephone'] = telephone;
if (nickname != null) val['nickname'] = nickname;
if (avatar != null) val['avatar'] = avatar;
if (persona != null) val['persona'] = persona;
if (status != null) val['status'] = status;
if (lastLoginTime != null) val['last_login_time'] = lastLoginTime;
if (createTime != null) val['create_time'] = createTime;
if (isBot != null) val['is_bot'] = isBot;
return val;
}
}
class BoundUserInfoResponse {
const BoundUserInfoResponse({this.userInfo, this.partnerUserInfo});
final UserInfoResponse? userInfo;
final UserInfoResponse? partnerUserInfo;
factory BoundUserInfoResponse.fromJson(Map<String, dynamic> json) {
return BoundUserInfoResponse(
userInfo: json['user_info'] == null
? null
: UserInfoResponse.fromJson(json['user_info'] as Map<String, dynamic>),
partnerUserInfo: json['pair_user_info'] == null
? null
: UserInfoResponse.fromJson(
json['pair_user_info'] as Map<String, dynamic>),
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (userInfo != null) val['user_info'] = userInfo!.toJson();
if (partnerUserInfo != null) {
val['pair_user_info'] = partnerUserInfo!.toJson();
}
return val;
}
}
class RongcloudTokenResponse {
const RongcloudTokenResponse({this.token});
final String? token;
factory RongcloudTokenResponse.fromJson(Map<String, dynamic> json) {
return RongcloudTokenResponse(
token: json['token'] as String?,
);
}
Map<String, dynamic> toJson() {
final val = <String, dynamic>{};
if (token != null) val['token'] = token;
return val;
}
}