# Conflicts: # apps/im_app/lib/features/chat/presentation/chat_db_test_view_model.dart # apps/im_app/lib/features/login/presentation/login_view_model.dart 修复逻辑漏洞,性能优化
120 lines
3.7 KiB
Dart
120 lines
3.7 KiB
Dart
import 'package:json_annotation/json_annotation.dart';
|
||
import 'package:networks_sdk/networks_sdk.dart';
|
||
|
||
import '../../../core/foundation/api_paths.dart';
|
||
import '../../../domain/entities/user.dart';
|
||
|
||
part 'get_profile_request.g.dart';
|
||
|
||
/// # /user/profile — 获取用户资料(GET 请求示例)
|
||
///
|
||
/// 演示:GET 请求 + 无 body 参数的模式。
|
||
/// GET 请求的 toJson() 结果会自动作为 URL query parameters 发送。
|
||
///
|
||
/// ## 数据流位置
|
||
///
|
||
/// ```
|
||
/// UserRepositoryImpl.getProfile()
|
||
/// → _client.executeRequest( ★ GetProfileRequest ★ ) ← 你在这里
|
||
/// → 服务端 GET /user/profile
|
||
/// → 响应 JSON → ★ ProfileData ★ ← 也在这里
|
||
/// → ProfileData.toEntity() → User
|
||
/// ```
|
||
|
||
// ─────────────────────────────────────────────
|
||
// Response DTO
|
||
// ─────────────────────────────────────────────
|
||
|
||
/// 用户资料响应 DTO(只需反序列化,禁止生成无用的 toJson)
|
||
@JsonSerializable(createToJson: false)
|
||
class ProfileData {
|
||
final int uid;
|
||
final String uuid;
|
||
@JsonKey(name: 'last_online')
|
||
final int lastOnline;
|
||
@JsonKey(name: 'profile_pic')
|
||
final String profilePic;
|
||
@JsonKey(name: 'profile_pic_gaussian')
|
||
final String profilePicGaussian;
|
||
final String nickname;
|
||
final String contact;
|
||
@JsonKey(name: 'country_code')
|
||
final String countryCode;
|
||
final String email;
|
||
@JsonKey(name: 'recovery_email')
|
||
final String recoveryEmail;
|
||
final String username;
|
||
final String bio;
|
||
final int relationship;
|
||
@JsonKey(name: 'user_alias')
|
||
final String? userAlias;
|
||
@JsonKey(name: 'channel_id')
|
||
final int channelId;
|
||
@JsonKey(name: 'channel_group_id')
|
||
final int channelGroupId;
|
||
final String hint;
|
||
|
||
const ProfileData({
|
||
required this.uid,
|
||
required this.uuid,
|
||
required this.lastOnline,
|
||
required this.profilePic,
|
||
required this.profilePicGaussian,
|
||
required this.nickname,
|
||
required this.contact,
|
||
required this.countryCode,
|
||
required this.email,
|
||
required this.recoveryEmail,
|
||
required this.username,
|
||
required this.bio,
|
||
required this.relationship,
|
||
this.userAlias,
|
||
required this.channelId,
|
||
required this.channelGroupId,
|
||
required this.hint,
|
||
});
|
||
|
||
factory ProfileData.fromJson(Map<String, dynamic> json) =>
|
||
_$ProfileDataFromJson(json);
|
||
|
||
/// DTO → Domain Entity
|
||
User toEntity() => User(
|
||
uid: uid,
|
||
uuid: uuid,
|
||
lastOnline: lastOnline,
|
||
profilePic: profilePic,
|
||
profilePicGaussian: profilePicGaussian,
|
||
nickname: nickname,
|
||
contact: contact,
|
||
countryCode: countryCode,
|
||
email: email,
|
||
recoveryEmail: recoveryEmail,
|
||
username: username,
|
||
bio: bio,
|
||
relationship: relationship,
|
||
userAlias: userAlias,
|
||
channelId: channelId,
|
||
channelGroupId: channelGroupId,
|
||
hint: hint,
|
||
);
|
||
}
|
||
|
||
// ─────────────────────────────────────────────
|
||
// Request
|
||
// ─────────────────────────────────────────────
|
||
|
||
/// 获取用户资料请求(GET,无参数)
|
||
///
|
||
/// GET 请求无 body,mixin 自动生成 toJson() → 空 map。
|
||
/// 如需 query 参数(如分页),添加字段即可,
|
||
/// toJson() 会自动将字段序列化为 URL query string。
|
||
@ApiRequest(
|
||
path: ApiPaths.userProfile,
|
||
method: HttpMethod.get,
|
||
responseType: ProfileData,
|
||
)
|
||
class GetProfileRequest extends ApiRequestable<ProfileData>
|
||
with _$GetProfileRequestApi {
|
||
GetProfileRequest();
|
||
}
|