Initial commit
This commit is contained in:
90
lib/data/repositories/analysis_repository_impl.dart
Normal file
90
lib/data/repositories/analysis_repository_impl.dart
Normal file
@@ -0,0 +1,90 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:trainhub_flutter/core/utils/id_generator.dart';
|
||||
import 'package:trainhub_flutter/data/database/app_database.dart';
|
||||
import 'package:trainhub_flutter/data/database/daos/analysis_dao.dart';
|
||||
import 'package:trainhub_flutter/data/mappers/analysis_mapper.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/analysis_session.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/annotation.dart';
|
||||
import 'package:trainhub_flutter/domain/repositories/analysis_repository.dart';
|
||||
|
||||
class AnalysisRepositoryImpl implements AnalysisRepository {
|
||||
final AnalysisDao _dao;
|
||||
|
||||
AnalysisRepositoryImpl(this._dao);
|
||||
|
||||
@override
|
||||
Future<List<AnalysisSessionEntity>> getAllSessions() async {
|
||||
final rows = await _dao.getAllSessions();
|
||||
return rows.map(AnalysisMapper.sessionToEntity).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<AnalysisSessionEntity?> getSession(String id) async {
|
||||
final row = await _dao.getSession(id);
|
||||
return row == null ? null : AnalysisMapper.sessionToEntity(row);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<AnalysisSessionEntity> createSession(
|
||||
String name, String videoPath) async {
|
||||
final String id = IdGenerator.generate();
|
||||
await _dao.insertSession(
|
||||
AnalysisSessionsCompanion.insert(
|
||||
id: id,
|
||||
name: name,
|
||||
videoPath: Value(videoPath),
|
||||
date: DateTime.now().toIso8601String(),
|
||||
),
|
||||
);
|
||||
final row = await _dao.getSession(id);
|
||||
return AnalysisMapper.sessionToEntity(row!);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteSession(String id) async {
|
||||
await _dao.deleteSession(id);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<AnnotationEntity>> getAnnotations(String sessionId) async {
|
||||
final rows = await _dao.getAnnotations(sessionId);
|
||||
return rows.map(AnalysisMapper.annotationToEntity).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<AnnotationEntity> addAnnotation({
|
||||
required String sessionId,
|
||||
required String name,
|
||||
required String description,
|
||||
required double startTime,
|
||||
required double endTime,
|
||||
required String color,
|
||||
}) async {
|
||||
final String id = IdGenerator.generate();
|
||||
await _dao.insertAnnotation(
|
||||
AnnotationsCompanion.insert(
|
||||
id: id,
|
||||
sessionId: sessionId,
|
||||
name: Value(name),
|
||||
description: Value(description),
|
||||
startTime: startTime,
|
||||
endTime: endTime,
|
||||
color: Value(color),
|
||||
),
|
||||
);
|
||||
return AnnotationEntity(
|
||||
id: id,
|
||||
sessionId: sessionId,
|
||||
startTime: startTime,
|
||||
endTime: endTime,
|
||||
name: name,
|
||||
description: description,
|
||||
color: color,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteAnnotation(String id) async {
|
||||
await _dao.deleteAnnotation(id);
|
||||
}
|
||||
}
|
||||
84
lib/data/repositories/chat_repository_impl.dart
Normal file
84
lib/data/repositories/chat_repository_impl.dart
Normal file
@@ -0,0 +1,84 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:trainhub_flutter/core/utils/id_generator.dart';
|
||||
import 'package:trainhub_flutter/data/database/app_database.dart';
|
||||
import 'package:trainhub_flutter/data/database/daos/chat_dao.dart';
|
||||
import 'package:trainhub_flutter/data/mappers/chat_mapper.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/chat_session.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/chat_message.dart';
|
||||
import 'package:trainhub_flutter/domain/repositories/chat_repository.dart';
|
||||
|
||||
class ChatRepositoryImpl implements ChatRepository {
|
||||
final ChatDao _dao;
|
||||
|
||||
ChatRepositoryImpl(this._dao);
|
||||
|
||||
@override
|
||||
Future<List<ChatSessionEntity>> getAllSessions() async {
|
||||
final rows = await _dao.getAllSessions();
|
||||
return rows.map(ChatMapper.sessionToEntity).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ChatSessionEntity?> getSession(String id) async {
|
||||
final row = await _dao.getSession(id);
|
||||
return row == null ? null : ChatMapper.sessionToEntity(row);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ChatSessionEntity> createSession() async {
|
||||
final String id = IdGenerator.generate();
|
||||
final String now = DateTime.now().toIso8601String();
|
||||
await _dao.insertSession(
|
||||
ChatSessionsCompanion.insert(
|
||||
id: id,
|
||||
title: const Value('New Chat'),
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
),
|
||||
);
|
||||
final row = await _dao.getSession(id);
|
||||
return ChatMapper.sessionToEntity(row!);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteSession(String id) async {
|
||||
await _dao.deleteSession(id);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<ChatMessageEntity>> getMessages(String sessionId) async {
|
||||
final rows = await _dao.getMessages(sessionId);
|
||||
return rows.map(ChatMapper.messageToEntity).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ChatMessageEntity> addMessage({
|
||||
required String sessionId,
|
||||
required String role,
|
||||
required String content,
|
||||
}) async {
|
||||
final String id = IdGenerator.generate();
|
||||
final String now = DateTime.now().toIso8601String();
|
||||
await _dao.insertMessage(
|
||||
ChatMessagesCompanion.insert(
|
||||
id: id,
|
||||
sessionId: sessionId,
|
||||
role: role,
|
||||
content: content,
|
||||
createdAt: now,
|
||||
),
|
||||
);
|
||||
return ChatMessageEntity(
|
||||
id: id,
|
||||
sessionId: sessionId,
|
||||
role: role,
|
||||
content: content,
|
||||
createdAt: now,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateSessionTitle(String sessionId, String title) async {
|
||||
await _dao.updateSessionTitle(sessionId, title);
|
||||
}
|
||||
}
|
||||
53
lib/data/repositories/exercise_repository_impl.dart
Normal file
53
lib/data/repositories/exercise_repository_impl.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:trainhub_flutter/core/utils/id_generator.dart';
|
||||
import 'package:trainhub_flutter/data/database/daos/exercise_dao.dart';
|
||||
import 'package:trainhub_flutter/data/mappers/exercise_mapper.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/exercise.dart';
|
||||
import 'package:trainhub_flutter/domain/repositories/exercise_repository.dart';
|
||||
import 'package:trainhub_flutter/data/database/app_database.dart';
|
||||
|
||||
class ExerciseRepositoryImpl implements ExerciseRepository {
|
||||
final ExerciseDao _dao;
|
||||
|
||||
ExerciseRepositoryImpl(this._dao);
|
||||
|
||||
@override
|
||||
Future<List<ExerciseEntity>> getAll() async {
|
||||
final rows = await _dao.getAllExercises();
|
||||
return rows.map(ExerciseMapper.toEntity).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ExerciseEntity> create({
|
||||
required String name,
|
||||
String? instructions,
|
||||
String? tags,
|
||||
String? videoUrl,
|
||||
}) async {
|
||||
final String id = IdGenerator.generate();
|
||||
await _dao.insertExercise(
|
||||
ExercisesCompanion.insert(
|
||||
id: id,
|
||||
name: name,
|
||||
instructions: Value(instructions),
|
||||
tags: Value(tags),
|
||||
videoUrl: Value(videoUrl),
|
||||
),
|
||||
);
|
||||
final row = await _dao.getExerciseById(id);
|
||||
return ExerciseMapper.toEntity(row);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> update(ExerciseEntity exercise) async {
|
||||
await _dao.updateExercise(
|
||||
exercise.id,
|
||||
ExerciseMapper.toUpdateCompanion(exercise),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> delete(String id) async {
|
||||
await _dao.deleteExercise(id);
|
||||
}
|
||||
}
|
||||
151
lib/data/repositories/program_repository_impl.dart
Normal file
151
lib/data/repositories/program_repository_impl.dart
Normal file
@@ -0,0 +1,151 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:trainhub_flutter/core/utils/id_generator.dart';
|
||||
import 'package:trainhub_flutter/data/database/app_database.dart';
|
||||
import 'package:trainhub_flutter/data/database/daos/program_dao.dart';
|
||||
import 'package:trainhub_flutter/data/mappers/program_mapper.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';
|
||||
import 'package:trainhub_flutter/domain/repositories/program_repository.dart';
|
||||
|
||||
class ProgramRepositoryImpl implements ProgramRepository {
|
||||
final ProgramDao _dao;
|
||||
|
||||
ProgramRepositoryImpl(this._dao);
|
||||
|
||||
@override
|
||||
Future<List<ProgramEntity>> getAllPrograms() async {
|
||||
final rows = await _dao.getAllPrograms();
|
||||
return rows.map(ProgramMapper.toEntity).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ProgramEntity?> getProgram(String id) async {
|
||||
final row = await _dao.getProgram(id);
|
||||
return row == null ? null : ProgramMapper.toEntity(row);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<ProgramWeekEntity>> getWeeks(String programId) async {
|
||||
final rows = await _dao.getWeeks(programId);
|
||||
return rows.map(ProgramMapper.weekToEntity).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<ProgramWorkoutEntity>> getWorkouts(String programId) async {
|
||||
final rows = await _dao.getWorkouts(programId);
|
||||
return rows.map(ProgramMapper.workoutToEntity).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ProgramEntity> createProgram(String name) async {
|
||||
final String id = IdGenerator.generate();
|
||||
await _dao.insertProgram(
|
||||
ProgramsCompanion.insert(
|
||||
id: id,
|
||||
name: name,
|
||||
createdAt: DateTime.now().toIso8601String(),
|
||||
),
|
||||
);
|
||||
final row = await _dao.getProgram(id);
|
||||
return ProgramMapper.toEntity(row!);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteProgram(String id) async {
|
||||
await _dao.deleteProgram(id);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> duplicateProgram(String sourceId) async {
|
||||
final sourceProgram = await _dao.getProgram(sourceId);
|
||||
if (sourceProgram == null) return;
|
||||
final String newId = IdGenerator.generate();
|
||||
await _dao.insertProgram(
|
||||
ProgramsCompanion.insert(
|
||||
id: newId,
|
||||
name: '${sourceProgram.name} (Copy)',
|
||||
createdAt: DateTime.now().toIso8601String(),
|
||||
),
|
||||
);
|
||||
final weeks = await _dao.getWeeks(sourceId);
|
||||
final workouts = await _dao.getWorkouts(sourceId);
|
||||
for (final week in weeks) {
|
||||
final String newWeekId = IdGenerator.generate();
|
||||
await _dao.insertWeek(
|
||||
ProgramWeeksCompanion.insert(
|
||||
id: newWeekId,
|
||||
programId: newId,
|
||||
position: week.position,
|
||||
notes: Value(week.notes),
|
||||
),
|
||||
);
|
||||
final weekWorkouts = workouts.where((w) => w.weekId == week.id);
|
||||
for (final workout in weekWorkouts) {
|
||||
await _dao.insertWorkout(
|
||||
ProgramWorkoutsCompanion.insert(
|
||||
id: IdGenerator.generate(),
|
||||
weekId: newWeekId,
|
||||
programId: newId,
|
||||
day: workout.day,
|
||||
type: workout.type,
|
||||
refId: Value(workout.refId),
|
||||
name: Value(workout.name),
|
||||
description: Value(workout.description),
|
||||
completed: const Value(false),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ProgramWeekEntity> addWeek(String programId, int position) async {
|
||||
final String id = IdGenerator.generate();
|
||||
await _dao.insertWeek(
|
||||
ProgramWeeksCompanion.insert(
|
||||
id: id,
|
||||
programId: programId,
|
||||
position: position,
|
||||
),
|
||||
);
|
||||
final weeks = await _dao.getWeeks(programId);
|
||||
final week = weeks.firstWhere((w) => w.id == id);
|
||||
return ProgramMapper.weekToEntity(week);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteWeek(String id) async {
|
||||
await _dao.deleteWeek(id);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateWeekNote(String weekId, String note) async {
|
||||
await _dao.updateWeekNote(weekId, note);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ProgramWorkoutEntity> addWorkout(
|
||||
ProgramWorkoutEntity workout) async {
|
||||
await _dao.insertWorkout(ProgramMapper.workoutToCompanion(workout));
|
||||
return workout;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateWorkout(ProgramWorkoutEntity workout) async {
|
||||
await _dao.updateWorkout(
|
||||
workout.id,
|
||||
ProgramMapper.workoutToUpdateCompanion(workout),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteWorkout(String id) async {
|
||||
await _dao.deleteWorkout(id);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> toggleWorkoutComplete(String id, bool currentStatus) async {
|
||||
await _dao.toggleWorkoutComplete(id, currentStatus);
|
||||
}
|
||||
}
|
||||
40
lib/data/repositories/training_plan_repository_impl.dart
Normal file
40
lib/data/repositories/training_plan_repository_impl.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
import 'package:trainhub_flutter/core/utils/id_generator.dart';
|
||||
import 'package:trainhub_flutter/data/database/daos/training_plan_dao.dart';
|
||||
import 'package:trainhub_flutter/data/mappers/training_plan_mapper.dart';
|
||||
import 'package:trainhub_flutter/domain/entities/training_plan.dart';
|
||||
import 'package:trainhub_flutter/domain/repositories/training_plan_repository.dart';
|
||||
|
||||
class TrainingPlanRepositoryImpl implements TrainingPlanRepository {
|
||||
final TrainingPlanDao _dao;
|
||||
|
||||
TrainingPlanRepositoryImpl(this._dao);
|
||||
|
||||
@override
|
||||
Future<List<TrainingPlanEntity>> getAll() async {
|
||||
final rows = await _dao.getAllPlans();
|
||||
return rows.map(TrainingPlanMapper.toEntity).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<TrainingPlanEntity> getById(String id) async {
|
||||
final row = await _dao.getPlanById(id);
|
||||
return TrainingPlanMapper.toEntity(row);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<TrainingPlanEntity> create(String name) async {
|
||||
final String id = IdGenerator.generate();
|
||||
await _dao.insertPlan(TrainingPlanMapper.toInsertCompanion(id, name));
|
||||
return getById(id);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> update(TrainingPlanEntity plan) async {
|
||||
await _dao.updatePlan(plan.id, TrainingPlanMapper.toUpdateCompanion(plan));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> delete(String id) async {
|
||||
await _dao.deletePlan(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user