Initial commit
This commit is contained in:
28
lib/data/mappers/analysis_mapper.dart
Normal file
28
lib/data/mappers/analysis_mapper.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:trainhub_flutter/data/database/app_database.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/analysis_session.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/annotation.dart';
|
||||
|
||||
class AnalysisMapper {
|
||||
AnalysisMapper._();
|
||||
|
||||
static AnalysisSessionEntity sessionToEntity(AnalysisSession row) {
|
||||
return AnalysisSessionEntity(
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
date: row.date,
|
||||
videoPath: row.videoPath,
|
||||
);
|
||||
}
|
||||
|
||||
static AnnotationEntity annotationToEntity(Annotation row) {
|
||||
return AnnotationEntity(
|
||||
id: row.id,
|
||||
sessionId: row.sessionId,
|
||||
startTime: row.startTime,
|
||||
endTime: row.endTime,
|
||||
name: row.name,
|
||||
description: row.description,
|
||||
color: row.color,
|
||||
);
|
||||
}
|
||||
}
|
||||
26
lib/data/mappers/chat_mapper.dart
Normal file
26
lib/data/mappers/chat_mapper.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:trainhub_flutter/data/database/app_database.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/chat_session.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/chat_message.dart';
|
||||
|
||||
class ChatMapper {
|
||||
ChatMapper._();
|
||||
|
||||
static ChatSessionEntity sessionToEntity(ChatSession row) {
|
||||
return ChatSessionEntity(
|
||||
id: row.id,
|
||||
title: row.title,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
);
|
||||
}
|
||||
|
||||
static ChatMessageEntity messageToEntity(ChatMessage row) {
|
||||
return ChatMessageEntity(
|
||||
id: row.id,
|
||||
sessionId: row.sessionId,
|
||||
role: row.role,
|
||||
content: row.content,
|
||||
createdAt: row.createdAt,
|
||||
);
|
||||
}
|
||||
}
|
||||
39
lib/data/mappers/exercise_mapper.dart
Normal file
39
lib/data/mappers/exercise_mapper.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:trainhub_flutter/data/database/app_database.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/exercise.dart';
|
||||
|
||||
class ExerciseMapper {
|
||||
ExerciseMapper._();
|
||||
|
||||
static ExerciseEntity toEntity(Exercise row) {
|
||||
return ExerciseEntity(
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
instructions: row.instructions,
|
||||
enrichment: row.enrichment,
|
||||
tags: row.tags,
|
||||
videoUrl: row.videoUrl,
|
||||
);
|
||||
}
|
||||
|
||||
static ExercisesCompanion toCompanion(ExerciseEntity entity) {
|
||||
return ExercisesCompanion(
|
||||
id: Value(entity.id),
|
||||
name: Value(entity.name),
|
||||
instructions: Value(entity.instructions),
|
||||
enrichment: Value(entity.enrichment),
|
||||
tags: Value(entity.tags),
|
||||
videoUrl: Value(entity.videoUrl),
|
||||
);
|
||||
}
|
||||
|
||||
static ExercisesCompanion toUpdateCompanion(ExerciseEntity entity) {
|
||||
return ExercisesCompanion(
|
||||
name: Value(entity.name),
|
||||
instructions: Value(entity.instructions),
|
||||
enrichment: Value(entity.enrichment),
|
||||
tags: Value(entity.tags),
|
||||
videoUrl: Value(entity.videoUrl),
|
||||
);
|
||||
}
|
||||
}
|
||||
68
lib/data/mappers/program_mapper.dart
Normal file
68
lib/data/mappers/program_mapper.dart
Normal file
@@ -0,0 +1,68 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:trainhub_flutter/data/database/app_database.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/program.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/program_week.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/program_workout.dart';
|
||||
|
||||
class ProgramMapper {
|
||||
ProgramMapper._();
|
||||
|
||||
static ProgramEntity toEntity(Program row) {
|
||||
return ProgramEntity(
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
createdAt: row.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
static ProgramWeekEntity weekToEntity(ProgramWeek row) {
|
||||
return ProgramWeekEntity(
|
||||
id: row.id,
|
||||
programId: row.programId,
|
||||
position: row.position,
|
||||
notes: row.notes,
|
||||
);
|
||||
}
|
||||
|
||||
static ProgramWorkoutEntity workoutToEntity(ProgramWorkout row) {
|
||||
return ProgramWorkoutEntity(
|
||||
id: row.id,
|
||||
weekId: row.weekId,
|
||||
programId: row.programId,
|
||||
day: row.day,
|
||||
type: row.type,
|
||||
refId: row.refId,
|
||||
name: row.name,
|
||||
description: row.description,
|
||||
completed: row.completed,
|
||||
);
|
||||
}
|
||||
|
||||
static ProgramWorkoutsCompanion workoutToCompanion(
|
||||
ProgramWorkoutEntity entity) {
|
||||
return ProgramWorkoutsCompanion(
|
||||
id: Value(entity.id),
|
||||
weekId: Value(entity.weekId),
|
||||
programId: Value(entity.programId),
|
||||
day: Value(entity.day),
|
||||
type: Value(entity.type),
|
||||
refId: Value(entity.refId),
|
||||
name: Value(entity.name),
|
||||
description: Value(entity.description),
|
||||
completed: Value(entity.completed),
|
||||
);
|
||||
}
|
||||
|
||||
static ProgramWorkoutsCompanion workoutToUpdateCompanion(
|
||||
ProgramWorkoutEntity entity) {
|
||||
return ProgramWorkoutsCompanion(
|
||||
day: Value(entity.day),
|
||||
type: Value(entity.type),
|
||||
refId: Value(entity.refId),
|
||||
name: Value(entity.name),
|
||||
description: Value(entity.description),
|
||||
completed: Value(entity.completed),
|
||||
weekId: Value(entity.weekId),
|
||||
);
|
||||
}
|
||||
}
|
||||
87
lib/data/mappers/training_plan_mapper.dart
Normal file
87
lib/data/mappers/training_plan_mapper.dart
Normal file
@@ -0,0 +1,87 @@
|
||||
import 'dart:convert';
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:trainhub_flutter/data/database/app_database.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/training_plan.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/training_section.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/training_exercise.dart';
|
||||
|
||||
class TrainingPlanMapper {
|
||||
TrainingPlanMapper._();
|
||||
|
||||
static TrainingPlanEntity toEntity(TrainingPlan row) {
|
||||
final List<dynamic> sectionsJson =
|
||||
row.sections != null && row.sections!.isNotEmpty
|
||||
? jsonDecode(row.sections!) as List
|
||||
: [];
|
||||
return TrainingPlanEntity(
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
sections: sectionsJson
|
||||
.map((s) => _mapSection(s as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
static TrainingSectionEntity _mapSection(Map<String, dynamic> json) {
|
||||
final exercisesJson = json['exercises'] as List<dynamic>? ?? [];
|
||||
return TrainingSectionEntity(
|
||||
id: json['id'] as String? ?? '',
|
||||
name: json['name'] as String? ?? '',
|
||||
exercises: exercisesJson
|
||||
.map((e) => _mapExercise(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
static TrainingExerciseEntity _mapExercise(Map<String, dynamic> json) {
|
||||
return TrainingExerciseEntity(
|
||||
instanceId: json['instanceId'] as String? ?? '',
|
||||
exerciseId: json['exerciseId'] as String? ?? '',
|
||||
name: json['name'] as String? ?? '',
|
||||
sets: json['sets'] as int? ?? 3,
|
||||
value: json['value'] as int? ?? 10,
|
||||
isTime: json['isTime'] as bool? ?? false,
|
||||
rest: json['rest'] as int? ?? 60,
|
||||
);
|
||||
}
|
||||
|
||||
static String sectionsToJson(List<TrainingSectionEntity> sections) {
|
||||
return jsonEncode(sections.map((s) => _sectionToMap(s)).toList());
|
||||
}
|
||||
|
||||
static Map<String, dynamic> _sectionToMap(TrainingSectionEntity section) {
|
||||
return {
|
||||
'id': section.id,
|
||||
'name': section.name,
|
||||
'exercises': section.exercises.map((e) => _exerciseToMap(e)).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
static Map<String, dynamic> _exerciseToMap(TrainingExerciseEntity exercise) {
|
||||
return {
|
||||
'instanceId': exercise.instanceId,
|
||||
'exerciseId': exercise.exerciseId,
|
||||
'name': exercise.name,
|
||||
'sets': exercise.sets,
|
||||
'value': exercise.value,
|
||||
'isTime': exercise.isTime,
|
||||
'rest': exercise.rest,
|
||||
};
|
||||
}
|
||||
|
||||
static TrainingPlansCompanion toInsertCompanion(
|
||||
String id, String name) {
|
||||
return TrainingPlansCompanion.insert(
|
||||
id: id,
|
||||
name: name,
|
||||
sections: const Value('[]'),
|
||||
);
|
||||
}
|
||||
|
||||
static TrainingPlansCompanion toUpdateCompanion(TrainingPlanEntity entity) {
|
||||
return TrainingPlansCompanion(
|
||||
name: Value(entity.name),
|
||||
sections: Value(sectionsToJson(entity.sections)),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user