mnemo_cards/mnemo_cards_backend/lib/user/user_data_model.dart

46 lines
1.8 KiB
Dart
Raw Normal View History

2025-11-16 11:25:27 +00:00
import 'package:mnemo_cards_common_backend/mnemo_cards_common_backend.dart';
import 'package:mnemo_cards_common/mnemo_cards_common.dart';
extension UserDataModelExtension on UserDataModel {
2025-12-14 20:45:27 +00:00
/// Конвертация в DTO с использованием данных из модели
2025-12-20 18:26:15 +00:00
///
2025-12-14 20:45:27 +00:00
/// Примечание: packProgress, studyDates, categoryMinutes теперь рассчитываются на лету
/// и должны передаваться как параметры
UserDataDto toDto({
List<PackProgressDto>? calculatedPackProgress,
List<DateTime>? calculatedStudyDates,
Map<String, int>? calculatedCategoryMinutes,
AllWordsStatisticsDto? calculatedWordsStatistics,
}) {
2025-11-16 11:25:27 +00:00
return UserDataDto(
2025-12-20 18:26:15 +00:00
allWordsStatistics:
calculatedWordsStatistics ??
AllWordsStatisticsDto(
words: words.map((model) => model.toDto()).toList(),
),
2025-11-16 11:25:27 +00:00
allTestsStatistics: AllTestsStatisticsDto(
2026-01-09 17:21:18 +00:00
tests: {}, // testsStatistics removed - always empty
2025-11-16 11:25:27 +00:00
lastSessionToken: this.lastTestSessionToken,
),
// NEW STATISTICS FIELDS
lastTimeOnline: lastTimeOnline,
totalStudyTimeMinutes: totalStudyTimeMinutes,
currentStreak: currentStreak,
longestStreak: longestStreak,
2025-12-14 20:45:27 +00:00
packProgress: calculatedPackProgress != null
2025-12-20 18:26:15 +00:00
? {
for (final progress in calculatedPackProgress)
progress.packId: progress,
}
: {
for (final progress in packProgress)
progress.packId: progress.toDto(),
},
2025-12-14 20:45:27 +00:00
studyDates: calculatedStudyDates ?? List<DateTime>.from(studyDates),
2025-12-20 18:26:15 +00:00
categoryMinutes:
calculatedCategoryMinutes ?? Map<String, int>.from(categoryMinutes),
2025-11-16 11:25:27 +00:00
achievements: achievements.map((model) => model.toDto()).toList(),
);
}
}