2025-11-16 11:25:27 +00:00
|
|
|
|
import 'package:mnemo_cards_common_backend/mnemo_cards_common_backend.dart';
|
|
|
|
|
|
import 'package:mnemo_cards_backend/user/user_data_model.dart';
|
|
|
|
|
|
import 'package:mnemo_cards_common/mnemo_cards_common.dart';
|
|
|
|
|
|
|
|
|
|
|
|
extension UserModelExtension on UserModel {
|
2025-12-14 20:45:27 +00:00
|
|
|
|
/// Конвертация в DTO
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Примечание: для расчета packProgress, studyDates, categoryMinutes на лету
|
|
|
|
|
|
/// используйте toDtoWithCalculatedData()
|
2025-11-16 11:25:27 +00:00
|
|
|
|
Future<UserDto> toDto() async {
|
2025-12-13 20:55:50 +00:00
|
|
|
|
final activeSubscription = subscriptionModel != null && subscriptionModel!.isActive;
|
2025-11-16 11:25:27 +00:00
|
|
|
|
return UserDto(
|
|
|
|
|
|
id: id,
|
|
|
|
|
|
name: name,
|
|
|
|
|
|
email: email,
|
2025-12-18 20:40:48 +00:00
|
|
|
|
telegram: telegram,
|
2025-11-16 11:25:27 +00:00
|
|
|
|
admin: admin,
|
|
|
|
|
|
packs: packs.map((e) => e.id?.toString()).whereNotNull().toList(),
|
|
|
|
|
|
subscription: activeSubscription,
|
2025-12-13 20:55:50 +00:00
|
|
|
|
subscriptionFeatures: subscriptionModel?.features.toSet() ?? {},
|
|
|
|
|
|
userDataDto: userData?.toDto(),
|
2025-11-16 11:25:27 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2025-12-14 20:45:27 +00:00
|
|
|
|
|
|
|
|
|
|
/// Конвертация в DTO с рассчитанными данными на лету
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Используется когда нужно рассчитать packProgress, studyDates, categoryMinutes
|
|
|
|
|
|
/// из WordStatistics и StudySessions вместо использования удаленных полей UserDatas
|
|
|
|
|
|
Future<UserDto> toDtoWithCalculatedData({
|
|
|
|
|
|
required List<PackProgressDto> packProgress,
|
|
|
|
|
|
required List<DateTime> studyDates,
|
|
|
|
|
|
required Map<String, int> categoryMinutes,
|
|
|
|
|
|
AllWordsStatisticsDto? wordsStatistics,
|
|
|
|
|
|
}) async {
|
|
|
|
|
|
final activeSubscription = subscriptionModel != null && subscriptionModel!.isActive;
|
|
|
|
|
|
return UserDto(
|
|
|
|
|
|
id: id,
|
|
|
|
|
|
name: name,
|
|
|
|
|
|
email: email,
|
2025-12-18 20:40:48 +00:00
|
|
|
|
telegram: telegram,
|
2025-12-14 20:45:27 +00:00
|
|
|
|
admin: admin,
|
|
|
|
|
|
packs: packs.map((e) => e.id?.toString()).whereNotNull().toList(),
|
|
|
|
|
|
subscription: activeSubscription,
|
|
|
|
|
|
subscriptionFeatures: subscriptionModel?.features.toSet() ?? {},
|
|
|
|
|
|
userDataDto: userData?.toDto(
|
|
|
|
|
|
calculatedPackProgress: packProgress,
|
|
|
|
|
|
calculatedStudyDates: studyDates,
|
|
|
|
|
|
calculatedCategoryMinutes: categoryMinutes,
|
|
|
|
|
|
calculatedWordsStatistics: wordsStatistics,
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2025-11-16 11:25:27 +00:00
|
|
|
|
}
|