diff --git a/frontend/app_student/lib/api/day_schedule/models/day_schedule_model.dart b/frontend/app_student/lib/api/day_schedule/models/day_schedule_model.dart index 149c410..5bd09d6 100644 --- a/frontend/app_student/lib/api/day_schedule/models/day_schedule_model.dart +++ b/frontend/app_student/lib/api/day_schedule/models/day_schedule_model.dart @@ -11,4 +11,10 @@ class DayScheduleModel { int get jour => entity.jour; List get events => entity.events; + + factory DayScheduleModel.fromEntity(DayScheduleEntity entity) { + return DayScheduleModel( + entity: entity, + ); + } } diff --git a/frontend/app_student/lib/api/day_schedule/repositories/day_schedule.dart b/frontend/app_student/lib/api/day_schedule/repositories/day_schedule.dart deleted file mode 100644 index 1d75c76..0000000 --- a/frontend/app_student/lib/api/day_schedule/repositories/day_schedule.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:app_student/api/api_service.dart'; -import '../entities/day_schedule_entity.dart'; - -class DayScheduleRepository { - final String className; - final ApiService apiService; - - DayScheduleRepository({required this.className, required this.apiService}); - - Future> getDaySchedule($className) { - return apiService.getData('/api/timetable?class_param=$className', - (item) => DayScheduleEntity.fromJson(item)); - } -} diff --git a/frontend/app_student/lib/api/week_schedule/models/week_schedule_model.dart b/frontend/app_student/lib/api/week_schedule/models/week_schedule_model.dart index 279723d..42825ad 100644 --- a/frontend/app_student/lib/api/week_schedule/models/week_schedule_model.dart +++ b/frontend/app_student/lib/api/week_schedule/models/week_schedule_model.dart @@ -1,14 +1,22 @@ -import 'package:app_student/api/day_schedule/entities/day_schedule_entity.dart'; - +import 'package:app_student/api/day_schedule/models/day_schedule_model.dart'; import '../entities/week_schedule_entity.dart'; class WeekScheduleModel { - final WeekScheduleEntity weekSchedule; + final String code; + final List daySchedules; WeekScheduleModel({ - required this.weekSchedule, + required this.code, + required this.daySchedules, }); - String get code => weekSchedule.code; - List get daySchedules => weekSchedule.daySchedules; + factory WeekScheduleModel.fromEntity(WeekScheduleEntity entity) { + return WeekScheduleModel( + code: entity.code, + daySchedules: entity.daySchedules + .map((dayScheduleEntity) => + DayScheduleModel.fromEntity(dayScheduleEntity)) + .toList(), + ); + } } diff --git a/frontend/app_student/lib/api/week_schedule/repositories/week_schedule_repositories.dart b/frontend/app_student/lib/api/week_schedule/repositories/week_schedule_repository.dart similarity index 91% rename from frontend/app_student/lib/api/week_schedule/repositories/week_schedule_repositories.dart rename to frontend/app_student/lib/api/week_schedule/repositories/week_schedule_repository.dart index 39e3b53..8eaf13e 100644 --- a/frontend/app_student/lib/api/week_schedule/repositories/week_schedule_repositories.dart +++ b/frontend/app_student/lib/api/week_schedule/repositories/week_schedule_repository.dart @@ -10,7 +10,7 @@ class WeekScheduleRepository { Future> getWeeksSchedule(className) { return apiService.getData('/api/timetable?class_param=$className', (item) { final entity = WeekScheduleEntity.fromJson(item); - return WeekScheduleModel(weekSchedule: entity); + return WeekScheduleModel.fromEntity(entity); }); } } diff --git a/frontend/app_student/lib/main_dev.dart b/frontend/app_student/lib/main_dev.dart index bf0e355..f1cc930 100644 --- a/frontend/app_student/lib/main_dev.dart +++ b/frontend/app_student/lib/main_dev.dart @@ -1,4 +1,4 @@ -import 'package:app_student/api/week_schedule/repositories/week_schedule_repositories.dart'; +import 'package:app_student/api/week_schedule/repositories/week_schedule_repository.dart'; import 'package:app_student/config/dev_config.dart'; import 'package:app_student/week_schedule/views/week_schedule.dart'; diff --git a/frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart b/frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart index ff8d5ff..fa507ff 100644 --- a/frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart +++ b/frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart @@ -1,4 +1,4 @@ -import 'package:app_student/api/week_schedule/repositories/week_schedule_repositories.dart'; +import 'package:app_student/api/week_schedule/repositories/week_schedule_repository.dart'; import 'package:bloc/bloc.dart'; import 'package:meta/meta.dart'; diff --git a/frontend/app_student/lib/week_schedule/views/week_schedule.dart b/frontend/app_student/lib/week_schedule/views/week_schedule.dart index 3041815..46df427 100644 --- a/frontend/app_student/lib/week_schedule/views/week_schedule.dart +++ b/frontend/app_student/lib/week_schedule/views/week_schedule.dart @@ -1,46 +1,9 @@ -import 'package:app_student/api/day_schedule/entities/day_schedule_entity.dart'; -import 'package:app_student/api/week_schedule/models/week_schedule_model.dart'; -import 'package:app_student/api/week_schedule/repositories/week_schedule_repositories.dart'; +import 'package:app_student/api/week_schedule/repositories/week_schedule_repository.dart'; import 'package:app_student/week_schedule/cubit/week_schedule_cubit.dart'; +import 'package:app_student/week_schedule/views/widgets/week_schedule_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -class DayScheduleWidget extends StatelessWidget { - final DayScheduleEntity daySchedule; - - const DayScheduleWidget({super.key, required this.daySchedule}); - - @override - Widget build(BuildContext context) { - return ExpansionTile( - title: Text('Date: ${daySchedule.date}'), - children: daySchedule.events.map((event) { - return ListTile( - title: Text('Event: ${event.activite}'), - subtitle: Text( - 'Start at: ${event.horaires.startAt}, End Time: ${event.horaires.endAt}'), - ); - }).toList(), - ); - } -} - -class WeekScheduleWidget extends StatelessWidget { - final WeekScheduleModel weekSchedule; - - const WeekScheduleWidget({super.key, required this.weekSchedule}); - - @override - Widget build(BuildContext context) { - return ExpansionTile( - title: Text('Code: ${weekSchedule.code}'), - children: weekSchedule.daySchedules.map((daySchedule) { - return DayScheduleWidget(daySchedule: daySchedule); - }).toList(), - ); - } -} - class WeekSchedulePage extends StatelessWidget { const WeekSchedulePage({super.key}); diff --git a/frontend/app_student/lib/week_schedule/views/widgets/day_schedule_widget.dart b/frontend/app_student/lib/week_schedule/views/widgets/day_schedule_widget.dart new file mode 100644 index 0000000..ae3662d --- /dev/null +++ b/frontend/app_student/lib/week_schedule/views/widgets/day_schedule_widget.dart @@ -0,0 +1,22 @@ +import 'package:app_student/api/day_schedule/models/day_schedule_model.dart'; +import 'package:flutter/material.dart'; + +class DayScheduleWidget extends StatelessWidget { + final DayScheduleModel daySchedule; + + const DayScheduleWidget({super.key, required this.daySchedule}); + + @override + Widget build(BuildContext context) { + return ExpansionTile( + title: Text('Date: ${daySchedule.date}'), + children: daySchedule.events.map((event) { + return ListTile( + title: Text('Event: ${event.activite}'), + subtitle: Text( + 'Start at: ${event.horaires.startAt}, End Time: ${event.horaires.endAt}'), + ); + }).toList(), + ); + } +} diff --git a/frontend/app_student/lib/week_schedule/views/widgets/week_schedule_widget.dart b/frontend/app_student/lib/week_schedule/views/widgets/week_schedule_widget.dart new file mode 100644 index 0000000..52d834e --- /dev/null +++ b/frontend/app_student/lib/week_schedule/views/widgets/week_schedule_widget.dart @@ -0,0 +1,19 @@ +import 'package:app_student/api/week_schedule/models/week_schedule_model.dart'; +import 'package:app_student/week_schedule/views/widgets/day_schedule_widget.dart'; +import 'package:flutter/material.dart'; + +class WeekScheduleWidget extends StatelessWidget { + final WeekScheduleModel weekSchedule; + + const WeekScheduleWidget({super.key, required this.weekSchedule}); + + @override + Widget build(BuildContext context) { + return ExpansionTile( + title: Text('Code: ${weekSchedule.code}'), + children: weekSchedule.daySchedules.map((daySchedule) { + return DayScheduleWidget(daySchedule: daySchedule); + }).toList(), + ); + } +}