Files
video/app/lib/models/user_profile.dart
2026-10-16 13:51:00 +08:00

64 lines
1.7 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'video_item.dart';
/// 用户公开主页(《03-接口文档》4.7)
class UserPublicProfile {
UserPublicProfile({
required this.userId,
this.nickname = '',
this.avatarUrl = '',
this.bio = '',
this.videoCount = 0,
this.totalLikes = 0,
});
final int userId;
final String nickname;
final String avatarUrl;
final String bio;
/// 已发布作品数
final int videoCount;
/// 累计获赞
final int totalLikes;
factory UserPublicProfile.fromJson(Map<String, dynamic> json) =>
UserPublicProfile(
userId: (json['user_id'] as num?)?.toInt() ?? 0,
nickname: (json['nickname'] as String?) ?? '',
avatarUrl: (json['avatar_url'] as String?) ?? '',
bio: (json['bio'] as String?) ?? '',
videoCount: (json['video_count'] as num?)?.toInt() ?? 0,
totalLikes: (json['total_likes'] as num?)?.toInt() ?? 0,
);
}
/// 观看历史项(《03-接口文档》6.7:video + watched_at + cost_type)
class HistoryItem {
HistoryItem({
required this.video,
this.watchedAt = '',
this.costType = 0,
});
final VideoItem video;
final String watchedAt;
/// 计费类型:0 免费额度 / 1 积分 / 2 会员 / 3 重复观看或本人作品(不计费)
final int costType;
String get costLabel => switch (costType) {
1 => '积分',
2 => '会员',
_ => '免费',
};
factory HistoryItem.fromJson(Map<String, dynamic> json) => HistoryItem(
video: VideoItem.fromJson(
(json['video'] as Map<String, dynamic>?) ?? const {},
),
watchedAt: (json['watched_at'] as String?) ?? '',
costType: (json['cost_type'] as num?)?.toInt() ?? 0,
);
}