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 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,toJson() 返回空 map。 /// 如需 query 参数(如分页),添加字段即可, /// toJson() 会自动将字段序列化为 URL query string。 @ApiRequest( path: ApiPaths.userProfile, method: HttpMethod.get, responseType: ProfileData, ) @JsonSerializable() class GetProfileRequest extends ApiRequestable with _$GetProfileRequestApi { GetProfileRequest(); factory GetProfileRequest.fromJson(Map json) => _$GetProfileRequestFromJson(json); @override Map toJson() => _$GetProfileRequestToJson(this); }