From 9470e1249f2909b6d4da2bb4bde48e998424698f Mon Sep 17 00:00:00 2001 From: Jules Artaud Date: Mon, 11 Mar 2024 14:05:39 +0100 Subject: [PATCH 01/12] =?UTF-8?q?=E2=99=BB=EF=B8=8F:=20refactor=20all=20mo?= =?UTF-8?q?dels?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entities/class_group_entity.dart | 13 +++++++ .../models/class_group_model.dart | 10 ++++++ .../repositories/class_group_repository.dart | 13 +++++++ .../lib/api/classes/entities/class.dart | 13 ------- .../repositories/class_repository.dart | 12 ------- .../lib/api/courses/entities/course.dart | 31 ---------------- .../day_schedule/entities/day_schedule.dart | 25 ------------- .../entities/day_schedule_entity.dart | 25 +++++++++++++ .../models/day_schedule_model.dart | 12 +++++++ .../repositories/day_schedule.dart | 10 +++--- .../entities/event_hours_entity.dart | 16 +++++++++ .../event_hours/models/event_hours_model.dart | 10 ++++++ .../lib/api/events/entities/event_entity.dart | 35 +++++++++++++++++++ .../lib/api/events/models/event_model.dart | 15 ++++++++ .../lib/api/users/entities/user_entity.dart | 14 ++++++++ .../lib/api/users/models/user_model.dart | 11 ++++++ .../lib/classes/bloc/class_bloc.dart | 10 +++--- .../app_student/lib/classes/views/class.dart | 8 ++--- .../lib/day_courses/bloc/day_course_bloc.dart | 24 +++++++++++++ .../views/day_schedule.dart | 7 ++-- .../day_schedules/bloc/day_schedule_bloc.dart | 25 ------------- 21 files changed, 215 insertions(+), 124 deletions(-) create mode 100644 frontend/app_student/lib/api/class_groups/entities/class_group_entity.dart create mode 100644 frontend/app_student/lib/api/class_groups/models/class_group_model.dart create mode 100644 frontend/app_student/lib/api/class_groups/repositories/class_group_repository.dart delete mode 100644 frontend/app_student/lib/api/classes/entities/class.dart delete mode 100644 frontend/app_student/lib/api/classes/repositories/class_repository.dart delete mode 100644 frontend/app_student/lib/api/courses/entities/course.dart delete mode 100644 frontend/app_student/lib/api/day_schedule/entities/day_schedule.dart create mode 100644 frontend/app_student/lib/api/day_schedule/entities/day_schedule_entity.dart create mode 100644 frontend/app_student/lib/api/day_schedule/models/day_schedule_model.dart create mode 100644 frontend/app_student/lib/api/event_hours/entities/event_hours_entity.dart create mode 100644 frontend/app_student/lib/api/event_hours/models/event_hours_model.dart create mode 100644 frontend/app_student/lib/api/events/entities/event_entity.dart create mode 100644 frontend/app_student/lib/api/events/models/event_model.dart create mode 100644 frontend/app_student/lib/api/users/entities/user_entity.dart create mode 100644 frontend/app_student/lib/api/users/models/user_model.dart create mode 100644 frontend/app_student/lib/day_courses/bloc/day_course_bloc.dart rename frontend/app_student/lib/{day_schedules => day_courses}/views/day_schedule.dart (88%) delete mode 100644 frontend/app_student/lib/day_schedules/bloc/day_schedule_bloc.dart diff --git a/frontend/app_student/lib/api/class_groups/entities/class_group_entity.dart b/frontend/app_student/lib/api/class_groups/entities/class_group_entity.dart new file mode 100644 index 0000000..27de29c --- /dev/null +++ b/frontend/app_student/lib/api/class_groups/entities/class_group_entity.dart @@ -0,0 +1,13 @@ +class ClassGroupEntity { + final String file; + final String name; + + ClassGroupEntity({required this.file, required this.name}); + + factory ClassGroupEntity.fromJson(Map json) { + return ClassGroupEntity( + file: json['file'], + name: json['name'], + ); + } +} diff --git a/frontend/app_student/lib/api/class_groups/models/class_group_model.dart b/frontend/app_student/lib/api/class_groups/models/class_group_model.dart new file mode 100644 index 0000000..e9f55da --- /dev/null +++ b/frontend/app_student/lib/api/class_groups/models/class_group_model.dart @@ -0,0 +1,10 @@ +import '../entities/class_group_entity.dart'; + +class ClassGroupModel { + final ClassGroupEntity classGroup; + + ClassGroupModel({required this.classGroup}); + + String get name => classGroup.name; + String get file => classGroup.file; +} diff --git a/frontend/app_student/lib/api/class_groups/repositories/class_group_repository.dart b/frontend/app_student/lib/api/class_groups/repositories/class_group_repository.dart new file mode 100644 index 0000000..fb30d4e --- /dev/null +++ b/frontend/app_student/lib/api/class_groups/repositories/class_group_repository.dart @@ -0,0 +1,13 @@ +import 'package:app_student/api/class_groups/entities/class_group_entity.dart'; +import 'package:app_student/api/api_service.dart'; + +class ClassGroupRepository { + final ApiService apiService; + + ClassGroupRepository({required this.apiService}); + + Future> getClasses() { + return apiService.getData( + '/api/classes', (item) => ClassGroupEntity.fromJson(item)); + } +} diff --git a/frontend/app_student/lib/api/classes/entities/class.dart b/frontend/app_student/lib/api/classes/entities/class.dart deleted file mode 100644 index 4f3e2b1..0000000 --- a/frontend/app_student/lib/api/classes/entities/class.dart +++ /dev/null @@ -1,13 +0,0 @@ -class Class { - final String file; - final String name; - - Class({required this.file, required this.name}); - - factory Class.fromJson(Map json) { - return Class( - file: json['file'], - name: json['name'], - ); - } -} diff --git a/frontend/app_student/lib/api/classes/repositories/class_repository.dart b/frontend/app_student/lib/api/classes/repositories/class_repository.dart deleted file mode 100644 index d37d6cf..0000000 --- a/frontend/app_student/lib/api/classes/repositories/class_repository.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:app_student/api/classes/entities/class.dart'; -import 'package:app_student/api/api_service.dart'; - -class ClassRepository { - final ApiService apiService; - - ClassRepository({required this.apiService}); - - Future> getClasses() { - return apiService.getData('/api/classes', (item) => Class.fromJson(item)); - } -} diff --git a/frontend/app_student/lib/api/courses/entities/course.dart b/frontend/app_student/lib/api/courses/entities/course.dart deleted file mode 100644 index 93655dc..0000000 --- a/frontend/app_student/lib/api/courses/entities/course.dart +++ /dev/null @@ -1,31 +0,0 @@ -class Course { - final String creneau; - final String activite; - final String id; - final String couleur; - final Map horaire; - final String salle; - - Course({ - required this.creneau, - required this.activite, - required this.id, - required this.couleur, - required this.horaire, - required this.salle, - }); - - factory Course.fromJson(Map json) { - return Course( - creneau: json['creneau'] ?? 'null', - activite: json['activite'] ?? 'null', - id: json['id'] ?? 'null', - couleur: json['couleur'] ?? 'null', - horaire: { - 'start': json['horaire']['start'] ?? 'null', - 'end': json['horaire']['end'] ?? 'null', - }, - salle: json['salle'] ?? 'null', - ); - } -} diff --git a/frontend/app_student/lib/api/day_schedule/entities/day_schedule.dart b/frontend/app_student/lib/api/day_schedule/entities/day_schedule.dart deleted file mode 100644 index 77c70a2..0000000 --- a/frontend/app_student/lib/api/day_schedule/entities/day_schedule.dart +++ /dev/null @@ -1,25 +0,0 @@ -import '../../courses/entities/course.dart'; - -class DaySchedule { - final String date; - final String jour; - final List cours; - - DaySchedule({ - required this.date, - required this.jour, - required this.cours, - }); - - factory DaySchedule.fromJson(Map json) { - var coursFromJson = json['cours'] as List; - List coursList = - coursFromJson.map((i) => Course.fromJson(i)).toList(); - - return DaySchedule( - date: json['date'], - jour: json['jour'], - cours: coursList, - ); - } -} diff --git a/frontend/app_student/lib/api/day_schedule/entities/day_schedule_entity.dart b/frontend/app_student/lib/api/day_schedule/entities/day_schedule_entity.dart new file mode 100644 index 0000000..81c3574 --- /dev/null +++ b/frontend/app_student/lib/api/day_schedule/entities/day_schedule_entity.dart @@ -0,0 +1,25 @@ +import '../../events/entities/event_entity.dart'; + +class DaySchedule { + final DateTime date; + final int jour; + final List events; + + DaySchedule({ + required this.date, + required this.jour, + required this.events, + }); + + factory DaySchedule.fromJson(Map json) { + var eventsFromJson = json['cours'] as List; + List eventsList = + eventsFromJson.map((i) => EventEntity.fromJson(i)).toList(); + + return DaySchedule( + date: json['date'], + jour: json['jour'], + events: eventsList, + ); + } +} 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 new file mode 100644 index 0000000..0b41a78 --- /dev/null +++ b/frontend/app_student/lib/api/day_schedule/models/day_schedule_model.dart @@ -0,0 +1,12 @@ +import '../../events/entities/event_entity.dart'; +import '../entities/day_schedule_entity.dart'; + +class DayScheduleModel { + final DaySchedule entity; + + DayScheduleModel({required this.entity}); + + DateTime get date => entity.date; + int get jour => entity.jour; + List get events => entity.events; +} 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 index c0fa80a..1606169 100644 --- a/frontend/app_student/lib/api/day_schedule/repositories/day_schedule.dart +++ b/frontend/app_student/lib/api/day_schedule/repositories/day_schedule.dart @@ -1,5 +1,5 @@ import 'package:app_student/api/api_service.dart'; -import '../entities/day_schedule.dart'; +import '../entities/day_schedule_entity.dart'; class DayScheduleRepository { final String className; @@ -7,8 +7,8 @@ class DayScheduleRepository { DayScheduleRepository({required this.className, required this.apiService}); - Future> getDaySchedules($className) { - return apiService.getData('/api/timetable?class_param=$className', - (item) => DaySchedule.fromJson(item)); - } +Future> getDayCourses($className) { + return apiService.getData('/api/timetable?class_param=$className', + (item) => DaySchedule.fromJson(item)); +} } diff --git a/frontend/app_student/lib/api/event_hours/entities/event_hours_entity.dart b/frontend/app_student/lib/api/event_hours/entities/event_hours_entity.dart new file mode 100644 index 0000000..0d73a54 --- /dev/null +++ b/frontend/app_student/lib/api/event_hours/entities/event_hours_entity.dart @@ -0,0 +1,16 @@ +class EventHoursEntity { + final String startAt; + final String endAt; + + EventHoursEntity({ + required this.startAt, + required this.endAt, + }); + + factory EventHoursEntity.fromJson(Map json) { + return EventHoursEntity( + startAt: json['start'], + endAt: json['end'], + ); + } +} diff --git a/frontend/app_student/lib/api/event_hours/models/event_hours_model.dart b/frontend/app_student/lib/api/event_hours/models/event_hours_model.dart new file mode 100644 index 0000000..eb4336e --- /dev/null +++ b/frontend/app_student/lib/api/event_hours/models/event_hours_model.dart @@ -0,0 +1,10 @@ +import '../entities/event_hours_entity.dart'; + +class EventHoursModel { + final EventHoursEntity entity; + + EventHoursModel({required this.entity}); + + String get startAt => entity.startAt; + String get endAt => entity.endAt; +} diff --git a/frontend/app_student/lib/api/events/entities/event_entity.dart b/frontend/app_student/lib/api/events/entities/event_entity.dart new file mode 100644 index 0000000..06a164a --- /dev/null +++ b/frontend/app_student/lib/api/events/entities/event_entity.dart @@ -0,0 +1,35 @@ +import 'dart:ffi'; + +import '../../event_hours/entities/event_hours_entity.dart'; + +class EventEntity { + final int id; + final int creneau; + final String activite; + final String couleur; + final EventHoursEntity horaires; + final String salle; + final Bool visio; + + EventEntity({ + required this.id, + required this.creneau, + required this.activite, + required this.couleur, + required this.horaires, + required this.salle, + required this.visio, + }); + + factory EventEntity.fromJson(Map json) { + return EventEntity( + creneau: json['creneau'] ?? 'null', + activite: json['activite'] ?? 'null', + id: json['id'] ?? 'null', + couleur: json['couleur'] ?? 'null', + horaires: EventHoursEntity.fromJson(json['horaire']), + salle: json['salle'] ?? 'null', + visio: json['visio'] ?? 'null', + ); + } +} diff --git a/frontend/app_student/lib/api/events/models/event_model.dart b/frontend/app_student/lib/api/events/models/event_model.dart new file mode 100644 index 0000000..b0fa2e9 --- /dev/null +++ b/frontend/app_student/lib/api/events/models/event_model.dart @@ -0,0 +1,15 @@ +import '../../event_hours/models/event_hours_model.dart'; +import '../entities/event_entity.dart'; + +class EventModel { + final EventEntity entity; + + EventModel({required this.entity}); + + int get id => entity.id; + int get creneau => entity.creneau; + String get activite => entity.activite; + String get couleur => entity.couleur; + EventHoursModel get horaires => EventHoursModel(entity: entity.horaires); + String get salle => entity.salle; +} diff --git a/frontend/app_student/lib/api/users/entities/user_entity.dart b/frontend/app_student/lib/api/users/entities/user_entity.dart new file mode 100644 index 0000000..5acce5b --- /dev/null +++ b/frontend/app_student/lib/api/users/entities/user_entity.dart @@ -0,0 +1,14 @@ +import 'package:app_student/api/class_groups/entities/class_group_entity.dart'; + +class UserEntity { + final String ine; + final String firstName; + final DateTime birthDate; + final ClassGroupEntity? classGroup; + + UserEntity( + {required this.ine, + required this.firstName, + required this.birthDate, + this.classGroup}); +} diff --git a/frontend/app_student/lib/api/users/models/user_model.dart b/frontend/app_student/lib/api/users/models/user_model.dart new file mode 100644 index 0000000..e8a8836 --- /dev/null +++ b/frontend/app_student/lib/api/users/models/user_model.dart @@ -0,0 +1,11 @@ +import '../entities/user_entity.dart'; + +class UserModel { + final UserEntity entity; + + UserModel({required this.entity}); + + String get file => entity.ine; + String get name => entity.firstName; + DateTime get birthDate => entity.birthDate; +} diff --git a/frontend/app_student/lib/classes/bloc/class_bloc.dart b/frontend/app_student/lib/classes/bloc/class_bloc.dart index 8fdcab1..f233370 100644 --- a/frontend/app_student/lib/classes/bloc/class_bloc.dart +++ b/frontend/app_student/lib/classes/bloc/class_bloc.dart @@ -1,15 +1,13 @@ import 'dart:async'; -import 'package:app_student/api/classes/entities/class.dart'; -import 'package:app_student/api/classes/repositories/class_repository.dart'; - - +import 'package:app_student/api/class_groups/entities/class_group_entity.dart'; +import 'package:app_student/api/class_groups/repositories/class_group_repository.dart'; class ClassBloc { final ClassRepository classRepository; - final _classController = StreamController>(); + final _classController = StreamController>(); - Stream> get classStream => _classController.stream; + Stream> get classStream => _classController.stream; ClassBloc({required this.classRepository}) { fetchClasses(); diff --git a/frontend/app_student/lib/classes/views/class.dart b/frontend/app_student/lib/classes/views/class.dart index 465b331..237d52f 100644 --- a/frontend/app_student/lib/classes/views/class.dart +++ b/frontend/app_student/lib/classes/views/class.dart @@ -1,8 +1,7 @@ -import 'package:app_student/api/classes/entities/class.dart'; +import 'package:app_student/api/class_groups/entities/class_group_entity.dart'; import 'package:flutter/material.dart'; import 'package:app_student/classes/bloc/class_bloc.dart'; - class ClassListPage extends StatefulWidget { final ClassBloc classBloc; @@ -27,9 +26,10 @@ class ClassListPageState extends State { appBar: AppBar( title: const Text('Class List'), ), - body: StreamBuilder>( + body: StreamBuilder>( stream: _classBloc.classStream, - builder: (BuildContext context, AsyncSnapshot> snapshot) { + builder: (BuildContext context, + AsyncSnapshot> snapshot) { if (snapshot.hasError) { return Center(child: Text('Error: ${snapshot.error}')); } diff --git a/frontend/app_student/lib/day_courses/bloc/day_course_bloc.dart b/frontend/app_student/lib/day_courses/bloc/day_course_bloc.dart new file mode 100644 index 0000000..5dad851 --- /dev/null +++ b/frontend/app_student/lib/day_courses/bloc/day_course_bloc.dart @@ -0,0 +1,24 @@ +import 'dart:async'; +import 'package:app_student/api/day_schedule/entities/day_schedule_entity.dart'; +import 'package:app_student/api/day_schedule/repositories/day_schedule.dart'; + +class DayCourseBloc { + final DayCourseRepository dayCourseRepository; + final _dayCourseController = StreamController>(); + + Stream> get dayCourseStream => _dayCourseController.stream; + + DayCourseBloc({required this.dayCourseRepository}) { + fetchDayCourses('B3 GROUPE 3 DLW-FA'); + // TODO : get the class name from the shared preferences + } + + fetchDayCourses(String className) async { + final daySchedules = await dayCourseRepository.getDayCourses(className); + _dayCourseController.sink.add(daySchedules); + } + + dispose() { + _dayCourseController.close(); + } +} diff --git a/frontend/app_student/lib/day_schedules/views/day_schedule.dart b/frontend/app_student/lib/day_courses/views/day_schedule.dart similarity index 88% rename from frontend/app_student/lib/day_schedules/views/day_schedule.dart rename to frontend/app_student/lib/day_courses/views/day_schedule.dart index a522a09..1d65a83 100644 --- a/frontend/app_student/lib/day_schedules/views/day_schedule.dart +++ b/frontend/app_student/lib/day_courses/views/day_schedule.dart @@ -1,6 +1,7 @@ -import 'package:app_student/day_schedules/bloc/day_schedule_bloc.dart'; import 'package:flutter/material.dart'; -import 'package:app_student/api/day_schedule/entities/day_schedule.dart'; +import 'package:app_student/api/day_schedule/entities/day_schedule_entity.dart'; + +import '../bloc/day_course_bloc.dart'; class DayScheduleView extends StatelessWidget { final DayScheduleBloc dayScheduleBloc; @@ -19,7 +20,7 @@ class DayScheduleView extends StatelessWidget { final daySchedule = snapshot.data![index]; return Card( child: ListTile( - title: Text(daySchedule.date), + title: Text(daySchedule.date.toString()), subtitle: Text('Jour: ${daySchedule.jour}'), ), ); diff --git a/frontend/app_student/lib/day_schedules/bloc/day_schedule_bloc.dart b/frontend/app_student/lib/day_schedules/bloc/day_schedule_bloc.dart deleted file mode 100644 index 40eb95d..0000000 --- a/frontend/app_student/lib/day_schedules/bloc/day_schedule_bloc.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'dart:async'; -import 'package:app_student/api/day_schedule/entities/day_schedule.dart'; -import 'package:app_student/api/day_schedule/repositories/day_schedule.dart'; - -class DayScheduleBloc { - final DayScheduleRepository dayScheduleRepository; - final _dayScheduleController = StreamController>(); - - Stream> get dayScheduleStream => - _dayScheduleController.stream; - - DayScheduleBloc({required this.dayScheduleRepository}) { - fetchDaySchedules('B3 GROUPE 3 DLW-FA'); - // TODO : get the class name from the shared preferences - } - - fetchDaySchedules(String className) async { - final daySchedules = await dayScheduleRepository.getDaySchedules(className); - _dayScheduleController.sink.add(daySchedules); - } - - dispose() { - _dayScheduleController.close(); - } -} From 3eb532bd9a45b6fa672a8feb506f1206da4f34d0 Mon Sep 17 00:00:00 2001 From: Jules Artaud Date: Mon, 11 Mar 2024 18:20:36 +0100 Subject: [PATCH 02/12] =?UTF-8?q?=E2=9C=A8:=20added=20cubits=20to=20fetch?= =?UTF-8?q?=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/.env | 6 +- frontend/app_student/lib/api/api_service.dart | 7 ++- .../entities/day_schedule_entity.dart | 8 +-- .../models/day_schedule_model.dart | 4 +- .../repositories/day_schedule.dart | 4 +- .../class_groups/cubit/class_group_cubit.dart | 22 +++++++ .../class_groups/cubit/class_group_state.dart | 20 +++++++ .../class_groups/views/class_group_view.dart | 45 ++++++++++++++ .../lib/classes/bloc/class_bloc.dart | 24 -------- .../app_student/lib/classes/views/class.dart | 60 ------------------- .../lib/day_courses/bloc/day_course_bloc.dart | 24 -------- .../lib/day_courses/views/day_schedule.dart | 37 ------------ .../cubit/day_schedule_cubit.dart | 25 ++++++++ .../cubit/day_schedule_state.dart | 20 +++++++ .../lib/day_schedule/views/day_schedule.dart | 51 ++++++++++++++++ .../app_student/lib/generated/assets.dart | 6 -- frontend/app_student/lib/main_dev.dart | 32 +++++++--- frontend/app_student/pubspec.lock | 16 +++++ frontend/app_student/pubspec.yaml | 2 + 19 files changed, 242 insertions(+), 171 deletions(-) create mode 100644 frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart create mode 100644 frontend/app_student/lib/class_groups/cubit/class_group_state.dart create mode 100644 frontend/app_student/lib/class_groups/views/class_group_view.dart delete mode 100644 frontend/app_student/lib/classes/bloc/class_bloc.dart delete mode 100644 frontend/app_student/lib/classes/views/class.dart delete mode 100644 frontend/app_student/lib/day_courses/bloc/day_course_bloc.dart delete mode 100644 frontend/app_student/lib/day_courses/views/day_schedule.dart create mode 100644 frontend/app_student/lib/day_schedule/cubit/day_schedule_cubit.dart create mode 100644 frontend/app_student/lib/day_schedule/cubit/day_schedule_state.dart create mode 100644 frontend/app_student/lib/day_schedule/views/day_schedule.dart delete mode 100644 frontend/app_student/lib/generated/assets.dart diff --git a/backend/.env b/backend/.env index 29628db..26ddcf0 100644 --- a/backend/.env +++ b/backend/.env @@ -15,8 +15,8 @@ # https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration ###> symfony/framework-bundle ### -APP_ENV= -APP_SECRET= +APP_ENV=dev +APP_SECRET=dqdqdqdjihsuadguagduay ###< symfony/framework-bundle ### -APP_3IL_SCHEDULE_URL= \ No newline at end of file +APP_3IL_SCHEDULE_URL=https://eleves.groupe3il.fr/edt_eleves/ diff --git a/frontend/app_student/lib/api/api_service.dart b/frontend/app_student/lib/api/api_service.dart index 531d406..a7072f2 100644 --- a/frontend/app_student/lib/api/api_service.dart +++ b/frontend/app_student/lib/api/api_service.dart @@ -8,14 +8,17 @@ class ApiService { Future> getData( String endpoint, T Function(Map) fromJson) async { + String fullUrl = '$apiUrl$endpoint'; + fullUrl = Uri.encodeFull(fullUrl); + print(fullUrl); try { - final response = await http.get(Uri.parse('$apiUrl$endpoint')); + final response = await http.get(Uri.parse(fullUrl)); if (response.statusCode == 200) { List jsonResponse = json.decode(response.body); return jsonResponse.map((item) => fromJson(item)).toList(); } else { - throw Exception('Failed to load data'); + throw Exception('ERROR ${response.statusCode} Failed to load data'); } } catch (e) { throw Exception('Failed to load data: $e'); diff --git a/frontend/app_student/lib/api/day_schedule/entities/day_schedule_entity.dart b/frontend/app_student/lib/api/day_schedule/entities/day_schedule_entity.dart index 81c3574..033c3a5 100644 --- a/frontend/app_student/lib/api/day_schedule/entities/day_schedule_entity.dart +++ b/frontend/app_student/lib/api/day_schedule/entities/day_schedule_entity.dart @@ -1,22 +1,22 @@ import '../../events/entities/event_entity.dart'; -class DaySchedule { +class DayScheduleEntity { final DateTime date; final int jour; final List events; - DaySchedule({ + DayScheduleEntity({ required this.date, required this.jour, required this.events, }); - factory DaySchedule.fromJson(Map json) { + factory DayScheduleEntity.fromJson(Map json) { var eventsFromJson = json['cours'] as List; List eventsList = eventsFromJson.map((i) => EventEntity.fromJson(i)).toList(); - return DaySchedule( + return DayScheduleEntity( date: json['date'], jour: json['jour'], events: eventsList, 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 0b41a78..149c410 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 @@ -2,11 +2,13 @@ import '../../events/entities/event_entity.dart'; import '../entities/day_schedule_entity.dart'; class DayScheduleModel { - final DaySchedule entity; + final DayScheduleEntity entity; DayScheduleModel({required this.entity}); DateTime get date => entity.date; + int get jour => entity.jour; + List get events => entity.events; } 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 index 1606169..8860595 100644 --- a/frontend/app_student/lib/api/day_schedule/repositories/day_schedule.dart +++ b/frontend/app_student/lib/api/day_schedule/repositories/day_schedule.dart @@ -7,8 +7,8 @@ class DayScheduleRepository { DayScheduleRepository({required this.className, required this.apiService}); -Future> getDayCourses($className) { +Future> getDaySchedule($className) { return apiService.getData('/api/timetable?class_param=$className', - (item) => DaySchedule.fromJson(item)); + (item) => DayScheduleEntity.fromJson(item)); } } diff --git a/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart b/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart new file mode 100644 index 0000000..db63f94 --- /dev/null +++ b/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart @@ -0,0 +1,22 @@ +import 'package:app_student/api/class_groups/repositories/class_group_repository.dart'; +import 'package:app_student/api/class_groups/entities/class_group_entity.dart'; +import 'package:bloc/bloc.dart'; +import 'package:meta/meta.dart'; + +part 'class_group_state.dart'; + +class ClassGroupCubit extends Cubit { + final ClassGroupRepository classRepository; + + ClassGroupCubit({required this.classRepository}) : super(ClassGroupInitial()); + + Future fetchClasses() async { + try { + emit(ClassGroupLoading()); + final classes = await classRepository.getClasses(); + emit(ClassGroupLoaded(classes)); + } catch (e) { + emit(ClassGroupError(e.toString())); + } + } +} \ No newline at end of file diff --git a/frontend/app_student/lib/class_groups/cubit/class_group_state.dart b/frontend/app_student/lib/class_groups/cubit/class_group_state.dart new file mode 100644 index 0000000..5390c7e --- /dev/null +++ b/frontend/app_student/lib/class_groups/cubit/class_group_state.dart @@ -0,0 +1,20 @@ +part of 'class_group_cubit.dart'; + +@immutable +abstract class ClassGroupState {} + +class ClassGroupInitial extends ClassGroupState {} + +class ClassGroupLoading extends ClassGroupState {} + +class ClassGroupLoaded extends ClassGroupState { + final List classes; + + ClassGroupLoaded(this.classes); +} + +class ClassGroupError extends ClassGroupState { + final String message; + + ClassGroupError(this.message); +} diff --git a/frontend/app_student/lib/class_groups/views/class_group_view.dart b/frontend/app_student/lib/class_groups/views/class_group_view.dart new file mode 100644 index 0000000..91e9d7f --- /dev/null +++ b/frontend/app_student/lib/class_groups/views/class_group_view.dart @@ -0,0 +1,45 @@ +import 'package:app_student/api/class_groups/repositories/class_group_repository.dart'; +import 'package:app_student/class_groups/cubit/class_group_cubit.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +class ClassListPage extends StatelessWidget { + const ClassListPage({super.key}); + + @override + Widget build(BuildContext context) { + final classRepository = + RepositoryProvider.of(context); + final classCubit = ClassGroupCubit(classRepository: classRepository); + + return BlocProvider( + create: (context) => classCubit..fetchClasses(), + child: Scaffold( + appBar: AppBar( + title: const Text('Class List'), + ), + body: BlocBuilder( + builder: (context, state) { + if (state is ClassGroupLoading) { + return const Center(child: CircularProgressIndicator()); + } else if (state is ClassGroupLoaded) { + return ListView.builder( + itemCount: state.classes.length, + itemBuilder: (context, index) { + return ListTile( + title: Text(state.classes[index].name), + subtitle: Text(state.classes[index].file), + ); + }, + ); + } else if (state is ClassGroupError) { + return Center(child: Text(state.message)); + } else { + return const SizedBox.shrink(); + } + }, + ), + ), + ); + } +} diff --git a/frontend/app_student/lib/classes/bloc/class_bloc.dart b/frontend/app_student/lib/classes/bloc/class_bloc.dart deleted file mode 100644 index f233370..0000000 --- a/frontend/app_student/lib/classes/bloc/class_bloc.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'dart:async'; - -import 'package:app_student/api/class_groups/entities/class_group_entity.dart'; -import 'package:app_student/api/class_groups/repositories/class_group_repository.dart'; - -class ClassBloc { - final ClassRepository classRepository; - final _classController = StreamController>(); - - Stream> get classStream => _classController.stream; - - ClassBloc({required this.classRepository}) { - fetchClasses(); - } - - fetchClasses() async { - final classes = await classRepository.getClasses(); - _classController.sink.add(classes); - } - - dispose() { - _classController.close(); - } -} diff --git a/frontend/app_student/lib/classes/views/class.dart b/frontend/app_student/lib/classes/views/class.dart deleted file mode 100644 index 237d52f..0000000 --- a/frontend/app_student/lib/classes/views/class.dart +++ /dev/null @@ -1,60 +0,0 @@ -import 'package:app_student/api/class_groups/entities/class_group_entity.dart'; -import 'package:flutter/material.dart'; -import 'package:app_student/classes/bloc/class_bloc.dart'; - -class ClassListPage extends StatefulWidget { - final ClassBloc classBloc; - - const ClassListPage({required this.classBloc, super.key}); - - @override - ClassListPageState createState() => ClassListPageState(); -} - -class ClassListPageState extends State { - late ClassBloc _classBloc; - - @override - void initState() { - super.initState(); - _classBloc = widget.classBloc; - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('Class List'), - ), - body: StreamBuilder>( - stream: _classBloc.classStream, - builder: (BuildContext context, - AsyncSnapshot> snapshot) { - if (snapshot.hasError) { - return Center(child: Text('Error: ${snapshot.error}')); - } - - if (!snapshot.hasData) { - return const Center(child: CircularProgressIndicator()); - } - - return ListView.builder( - itemCount: snapshot.data!.length, - itemBuilder: (context, index) { - return ListTile( - title: Text(snapshot.data![index].name), - subtitle: Text(snapshot.data![index].file), - ); - }, - ); - }, - ), - ); - } - - @override - void dispose() { - _classBloc.dispose(); - super.dispose(); - } -} diff --git a/frontend/app_student/lib/day_courses/bloc/day_course_bloc.dart b/frontend/app_student/lib/day_courses/bloc/day_course_bloc.dart deleted file mode 100644 index 5dad851..0000000 --- a/frontend/app_student/lib/day_courses/bloc/day_course_bloc.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'dart:async'; -import 'package:app_student/api/day_schedule/entities/day_schedule_entity.dart'; -import 'package:app_student/api/day_schedule/repositories/day_schedule.dart'; - -class DayCourseBloc { - final DayCourseRepository dayCourseRepository; - final _dayCourseController = StreamController>(); - - Stream> get dayCourseStream => _dayCourseController.stream; - - DayCourseBloc({required this.dayCourseRepository}) { - fetchDayCourses('B3 GROUPE 3 DLW-FA'); - // TODO : get the class name from the shared preferences - } - - fetchDayCourses(String className) async { - final daySchedules = await dayCourseRepository.getDayCourses(className); - _dayCourseController.sink.add(daySchedules); - } - - dispose() { - _dayCourseController.close(); - } -} diff --git a/frontend/app_student/lib/day_courses/views/day_schedule.dart b/frontend/app_student/lib/day_courses/views/day_schedule.dart deleted file mode 100644 index 1d65a83..0000000 --- a/frontend/app_student/lib/day_courses/views/day_schedule.dart +++ /dev/null @@ -1,37 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:app_student/api/day_schedule/entities/day_schedule_entity.dart'; - -import '../bloc/day_course_bloc.dart'; - -class DayScheduleView extends StatelessWidget { - final DayScheduleBloc dayScheduleBloc; - - const DayScheduleView({super.key, required this.dayScheduleBloc}); - - @override - Widget build(BuildContext context) { - return StreamBuilder>( - stream: dayScheduleBloc.dayScheduleStream, - builder: (context, snapshot) { - if (snapshot.hasData) { - return ListView.builder( - itemCount: snapshot.data!.length, - itemBuilder: (context, index) { - final daySchedule = snapshot.data![index]; - return Card( - child: ListTile( - title: Text(daySchedule.date.toString()), - subtitle: Text('Jour: ${daySchedule.jour}'), - ), - ); - }, - ); - } else if (snapshot.hasError) { - return Text('Erreur: ${snapshot.error}'); - } - - return const Text('Erreur: Les données ne sont pas encore disponibles'); - }, - ); - } -} diff --git a/frontend/app_student/lib/day_schedule/cubit/day_schedule_cubit.dart b/frontend/app_student/lib/day_schedule/cubit/day_schedule_cubit.dart new file mode 100644 index 0000000..5cc1618 --- /dev/null +++ b/frontend/app_student/lib/day_schedule/cubit/day_schedule_cubit.dart @@ -0,0 +1,25 @@ +import 'package:app_student/api/day_schedule/repositories/day_schedule.dart'; +import 'package:bloc/bloc.dart'; +import 'package:meta/meta.dart'; + +part 'day_schedule_state.dart'; + +class DayScheduleCubit extends Cubit { + final DayScheduleRepository dayScheduleRepository; + + DayScheduleCubit({required this.dayScheduleRepository}) + : super(DayScheduleInitial()); + + Future fetchDaySchedule(String className) async { + try { + emit(DayScheduleLoading()); + final daySchedule = await dayScheduleRepository.getDaySchedule(className); + emit(DayScheduleLoaded(daySchedule)); + } catch (e) { + emit(DayScheduleError(e.toString())); + } + } +} + + + diff --git a/frontend/app_student/lib/day_schedule/cubit/day_schedule_state.dart b/frontend/app_student/lib/day_schedule/cubit/day_schedule_state.dart new file mode 100644 index 0000000..a2ed3c9 --- /dev/null +++ b/frontend/app_student/lib/day_schedule/cubit/day_schedule_state.dart @@ -0,0 +1,20 @@ +part of 'day_schedule_cubit.dart'; + +@immutable +abstract class DayScheduleState {} + +class DayScheduleInitial extends DayScheduleState {} + +class DayScheduleLoading extends DayScheduleState {} + +class DayScheduleLoaded extends DayScheduleState { + final List daySchedule; + + DayScheduleLoaded(this.daySchedule); +} + +class DayScheduleError extends DayScheduleState { + final String message; + + DayScheduleError(this.message); +} \ No newline at end of file diff --git a/frontend/app_student/lib/day_schedule/views/day_schedule.dart b/frontend/app_student/lib/day_schedule/views/day_schedule.dart new file mode 100644 index 0000000..a94bc97 --- /dev/null +++ b/frontend/app_student/lib/day_schedule/views/day_schedule.dart @@ -0,0 +1,51 @@ +import 'package:app_student/api/day_schedule/repositories/day_schedule.dart'; +import 'package:app_student/day_schedule/cubit/day_schedule_cubit.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +class DaySchedulePage extends StatelessWidget { + const DaySchedulePage({super.key}); + + @override + Widget build(BuildContext context) { + final dayScheduleRepository = + RepositoryProvider.of(context); + final dayScheduleCubit = DayScheduleCubit(dayScheduleRepository: dayScheduleRepository); + + return BlocProvider( + create: (context) => dayScheduleCubit..fetchDaySchedule('B3 Groupe 3 DLW-FA'), + child: Scaffold( + appBar: AppBar( + title: const Text('Day Schedule'), + ), + body: BlocBuilder( + builder: (context, state) { + if (state is DayScheduleLoading) { + return const Center(child: CircularProgressIndicator()); + } else if (state is DayScheduleLoaded) { + return ListView.builder( + itemCount: state.daySchedule.length, + itemBuilder: (context, index) { + final daySchedule = state.daySchedule[index]; + return ListTile( + title: Text('Date: ${daySchedule.date}, Jour: ${daySchedule.jour}'), + subtitle: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: daySchedule.events.map((event) { + return Text('Event: ${event.activite}, Start at: ${event.horaires.startAt}, End Time: ${event.horaires.endAt}'); + }).toList(), + ), + ); + }, + ); + } else if (state is DayScheduleError) { + return Center(child: Text(state.message)); + } else { + return const SizedBox.shrink(); + } + }, + ), + ), + ); + } +} diff --git a/frontend/app_student/lib/generated/assets.dart b/frontend/app_student/lib/generated/assets.dart deleted file mode 100644 index 80e18b1..0000000 --- a/frontend/app_student/lib/generated/assets.dart +++ /dev/null @@ -1,6 +0,0 @@ -///This file is automatically generated. DO NOT EDIT, all your changes would be lost. -class Assets { - Assets._(); - - static const String images3ilLogo = 'assets/images/3il-logo.jpg'; -} diff --git a/frontend/app_student/lib/main_dev.dart b/frontend/app_student/lib/main_dev.dart index e39fb78..b0a1f7e 100644 --- a/frontend/app_student/lib/main_dev.dart +++ b/frontend/app_student/lib/main_dev.dart @@ -1,9 +1,12 @@ import 'package:app_student/config/dev_config.dart'; -import 'package:app_student/login/views/login_page.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:provider/provider.dart'; +import 'api/api_service.dart'; +import 'api/day_schedule/repositories/day_schedule.dart'; import 'config/config.dart'; +import 'day_schedule/views/day_schedule.dart'; void main() { runApp( @@ -19,12 +22,25 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { - return MaterialApp( - title: 'Class List', - theme: ThemeData( - primarySwatch: Colors.blue, - focusColor: const Color(0xffE84E0F), - ), - home: const LoginPage()); + return Provider( + create: (_) => DevConfig(), + child: RepositoryProvider( + create: (context) => DayScheduleRepository( + apiService: ApiService(apiUrl: context.read().apiUrl), className: 'B3 Groupe 3 DLW-FA'), + child: const MaterialApp(home: DaySchedulePage()), + ), + ); } + + // @override + // Widget build(BuildContext context) { + // return Provider( + // create: (_) => DevConfig(), + // child: RepositoryProvider( + // create: (context) => ClassGroupRepository( + // apiService: ApiService(apiUrl: context.read().apiUrl)), + // child: const MaterialApp(home: ClassListPage()), + // ), + // ); + // } } diff --git a/frontend/app_student/pubspec.lock b/frontend/app_student/pubspec.lock index b5fb585..aa98c4d 100644 --- a/frontend/app_student/pubspec.lock +++ b/frontend/app_student/pubspec.lock @@ -9,6 +9,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.11.0" + bloc: + dependency: "direct main" + description: + name: bloc + sha256: f53a110e3b48dcd78136c10daa5d51512443cea5e1348c9d80a320095fa2db9e + url: "https://pub.dev" + source: hosted + version: "8.1.3" boolean_selector: dependency: transitive description: @@ -62,6 +70,14 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_bloc: + dependency: "direct main" + description: + name: flutter_bloc + sha256: "87325da1ac757fcc4813e6b34ed5dd61169973871fdf181d6c2109dd6935ece1" + url: "https://pub.dev" + source: hosted + version: "8.1.4" flutter_lints: dependency: "direct dev" description: diff --git a/frontend/app_student/pubspec.yaml b/frontend/app_student/pubspec.yaml index f606863..ff5d2c2 100644 --- a/frontend/app_student/pubspec.yaml +++ b/frontend/app_student/pubspec.yaml @@ -37,6 +37,8 @@ dependencies: cupertino_icons: ^1.0.6 http: ^1.2.1 provider: ^6.1.2 + bloc: ^8.1.3 + flutter_bloc: ^8.1.4 dev_dependencies: flutter_test: From e8e76ceb264412d63e1fda43c8308193a7646ca5 Mon Sep 17 00:00:00 2001 From: Jules Artaud Date: Mon, 11 Mar 2024 19:57:37 +0100 Subject: [PATCH 03/12] =?UTF-8?q?=F0=9F=9A=A7:=20trying=20to=20get=20new?= =?UTF-8?q?=20schedule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app_student/lib/api/api_service.dart | 29 ++++++++++ .../repositories/class_group_repository.dart | 9 ++- .../schedule/entities/schedule_entity.dart | 23 ++++++++ .../api/schedule/models/schedule_model.dart | 11 ++++ .../repositories/schedule_repository.dart | 17 ++++++ .../entities/week_schedule_entity.dart | 22 +++++++ .../models/week_schedule_model.dart | 11 ++++ .../week_schedule_repositories.dart | 21 +++++++ .../class_groups/cubit/class_group_cubit.dart | 1 + .../class_groups/cubit/class_group_state.dart | 2 +- .../cubit/day_schedule_cubit.dart | 25 -------- .../cubit/day_schedule_state.dart | 20 ------- .../lib/day_schedule/views/day_schedule.dart | 51 ----------------- frontend/app_student/lib/main_dev.dart | 40 +++++++------ .../lib/schedule/cubit/schedule_cubit.dart | 23 ++++++++ .../lib/schedule/cubit/schedule_state.dart | 19 +++++++ .../lib/schedule/views/schedule_view.dart | 57 +++++++++++++++++++ .../cubit/week_schedule_cubit.dart | 23 ++++++++ .../cubit/week_schedule_state.dart | 20 +++++++ .../week_schedule/views/week_schedule.dart | 56 ++++++++++++++++++ 20 files changed, 362 insertions(+), 118 deletions(-) create mode 100644 frontend/app_student/lib/api/schedule/entities/schedule_entity.dart create mode 100644 frontend/app_student/lib/api/schedule/models/schedule_model.dart create mode 100644 frontend/app_student/lib/api/schedule/repositories/schedule_repository.dart create mode 100644 frontend/app_student/lib/api/week_schedule/entities/week_schedule_entity.dart create mode 100644 frontend/app_student/lib/api/week_schedule/models/week_schedule_model.dart create mode 100644 frontend/app_student/lib/api/week_schedule/repositories/week_schedule_repositories.dart delete mode 100644 frontend/app_student/lib/day_schedule/cubit/day_schedule_cubit.dart delete mode 100644 frontend/app_student/lib/day_schedule/cubit/day_schedule_state.dart delete mode 100644 frontend/app_student/lib/day_schedule/views/day_schedule.dart create mode 100644 frontend/app_student/lib/schedule/cubit/schedule_cubit.dart create mode 100644 frontend/app_student/lib/schedule/cubit/schedule_state.dart create mode 100644 frontend/app_student/lib/schedule/views/schedule_view.dart create mode 100644 frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart create mode 100644 frontend/app_student/lib/week_schedule/cubit/week_schedule_state.dart create mode 100644 frontend/app_student/lib/week_schedule/views/week_schedule.dart diff --git a/frontend/app_student/lib/api/api_service.dart b/frontend/app_student/lib/api/api_service.dart index a7072f2..b63d6be 100644 --- a/frontend/app_student/lib/api/api_service.dart +++ b/frontend/app_student/lib/api/api_service.dart @@ -16,6 +16,7 @@ class ApiService { if (response.statusCode == 200) { List jsonResponse = json.decode(response.body); + print('JSON Response: $jsonResponse'); // Print the JSON response return jsonResponse.map((item) => fromJson(item)).toList(); } else { throw Exception('ERROR ${response.statusCode} Failed to load data'); @@ -24,4 +25,32 @@ class ApiService { throw Exception('Failed to load data: $e'); } } + +// Future> getData( +// String endpoint, T Function(Map) fromJson) async { +// String fullUrl = '$apiUrl$endpoint'; +// fullUrl = Uri.encodeFull(fullUrl); +// print(fullUrl); +// try { +// final response = await http.get(Uri.parse(fullUrl)); +// +// if (response.statusCode == 200) { +// var jsonResponse = json.decode(response.body); +// print('JSON Response: $jsonResponse'); // Print the JSON response +// +// // Check if jsonResponse is a Map. If so, convert it to a List +// if (jsonResponse is Map) { +// jsonResponse = [jsonResponse]; +// } +// +// return jsonResponse.map((item) => fromJson(item)).toList(); +// } else { +// print('ERROR ${response.statusCode} Failed to load data'); +// throw Exception('ERROR ${response.statusCode} Failed to load data'); +// } +// } catch (e) { +// print('Failed to load data: $e'); +// throw Exception('Failed to load data: $e'); +// } +// } } diff --git a/frontend/app_student/lib/api/class_groups/repositories/class_group_repository.dart b/frontend/app_student/lib/api/class_groups/repositories/class_group_repository.dart index fb30d4e..1250c9a 100644 --- a/frontend/app_student/lib/api/class_groups/repositories/class_group_repository.dart +++ b/frontend/app_student/lib/api/class_groups/repositories/class_group_repository.dart @@ -1,13 +1,16 @@ import 'package:app_student/api/class_groups/entities/class_group_entity.dart'; import 'package:app_student/api/api_service.dart'; +import 'package:app_student/api/class_groups/models/class_group_model.dart'; class ClassGroupRepository { final ApiService apiService; ClassGroupRepository({required this.apiService}); - Future> getClasses() { - return apiService.getData( - '/api/classes', (item) => ClassGroupEntity.fromJson(item)); + Future> getClasses() { + return apiService.getData('/api/classes', (item) { + final entity = ClassGroupEntity.fromJson(item); + return ClassGroupModel(classGroup: entity); + }); } } diff --git a/frontend/app_student/lib/api/schedule/entities/schedule_entity.dart b/frontend/app_student/lib/api/schedule/entities/schedule_entity.dart new file mode 100644 index 0000000..94f22a0 --- /dev/null +++ b/frontend/app_student/lib/api/schedule/entities/schedule_entity.dart @@ -0,0 +1,23 @@ +import 'package:app_student/api/week_schedule/entities/week_schedule_entity.dart'; + +class ScheduleEntity { + final int id; + final List weekSchedules; + + ScheduleEntity({ + required this.id, + required this.weekSchedules, + }); + + factory ScheduleEntity.fromJson(Map json) { + var weekSchedulesFromJson = json['Weeks'] as List; + List weekSchedulesList = weekSchedulesFromJson + .map((i) => WeekScheduleEntity.fromJson(i)) + .toList(); + + return ScheduleEntity( + id: json['id'], + weekSchedules: weekSchedulesList, + ); + } +} diff --git a/frontend/app_student/lib/api/schedule/models/schedule_model.dart b/frontend/app_student/lib/api/schedule/models/schedule_model.dart new file mode 100644 index 0000000..c1fe5b9 --- /dev/null +++ b/frontend/app_student/lib/api/schedule/models/schedule_model.dart @@ -0,0 +1,11 @@ +import 'package:app_student/api/schedule/entities/schedule_entity.dart'; +import 'package:app_student/api/week_schedule/entities/week_schedule_entity.dart'; + +class ScheduleModel { + final ScheduleEntity schedule; + + ScheduleModel({required this.schedule}); + + int get id => schedule.id; + List get weekSchedules => schedule.weekSchedules; +} diff --git a/frontend/app_student/lib/api/schedule/repositories/schedule_repository.dart b/frontend/app_student/lib/api/schedule/repositories/schedule_repository.dart new file mode 100644 index 0000000..172e764 --- /dev/null +++ b/frontend/app_student/lib/api/schedule/repositories/schedule_repository.dart @@ -0,0 +1,17 @@ +import 'package:app_student/api/api_service.dart'; +import 'package:app_student/api/schedule/entities/schedule_entity.dart'; +import 'package:app_student/api/schedule/models/schedule_model.dart'; + +class ScheduleRepository { + final ApiService apiService; + final String className; + + ScheduleRepository({required this.apiService, required this.className}); + + Future getSchedule(className) { + return apiService.getData('/api/timetable?class_param=$className', (item) { + final entity = ScheduleEntity.fromJson(item); + return ScheduleModel(schedule: entity); + }).then((list) => list.first); + } +} diff --git a/frontend/app_student/lib/api/week_schedule/entities/week_schedule_entity.dart b/frontend/app_student/lib/api/week_schedule/entities/week_schedule_entity.dart new file mode 100644 index 0000000..5e48453 --- /dev/null +++ b/frontend/app_student/lib/api/week_schedule/entities/week_schedule_entity.dart @@ -0,0 +1,22 @@ +import 'package:app_student/api/day_schedule/entities/day_schedule_entity.dart'; + +class WeekScheduleEntity { + final String code; + final List daySchedules; + + WeekScheduleEntity({ + required this.code, + required this.daySchedules, + }); + + factory WeekScheduleEntity.fromJson(Map json) { + var daySchedulesFromJson = json['DaySchedule'] as List; + List daySchedulesList = + daySchedulesFromJson.map((i) => DayScheduleEntity.fromJson(i)).toList(); + + return WeekScheduleEntity( + code: json['code'], + daySchedules: daySchedulesList, + ); + } +} 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 new file mode 100644 index 0000000..6da76d9 --- /dev/null +++ b/frontend/app_student/lib/api/week_schedule/models/week_schedule_model.dart @@ -0,0 +1,11 @@ +import 'package:app_student/api/day_schedule/entities/day_schedule_entity.dart'; + +class WeekScheduleModel { + final String code; + final List daySchedules; + + WeekScheduleModel({ + required this.code, + required this.daySchedules, + }); +} 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_repositories.dart new file mode 100644 index 0000000..5b27e69 --- /dev/null +++ b/frontend/app_student/lib/api/week_schedule/repositories/week_schedule_repositories.dart @@ -0,0 +1,21 @@ +import 'dart:convert'; + +import 'package:app_student/api/api_service.dart'; +import 'package:app_student/api/week_schedule/entities/week_schedule_entity.dart'; +import 'package:app_student/api/week_schedule/models/week_schedule_model.dart'; + +class WeekScheduleRepository { + final ApiService apiService; + + WeekScheduleRepository({required this.apiService, required String className}); + + Future> getWeeksSchedule(className) { + return apiService.getData('/api/timetable?class_param=$className', (item) { + final entity = WeekScheduleEntity.fromJson(item); + return WeekScheduleModel( + code: entity.code, + daySchedules: entity.daySchedules, + ); + }); + } +} diff --git a/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart b/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart index db63f94..636b7bf 100644 --- a/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart +++ b/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart @@ -1,3 +1,4 @@ +import 'package:app_student/api/class_groups/models/class_group_model.dart'; import 'package:app_student/api/class_groups/repositories/class_group_repository.dart'; import 'package:app_student/api/class_groups/entities/class_group_entity.dart'; import 'package:bloc/bloc.dart'; diff --git a/frontend/app_student/lib/class_groups/cubit/class_group_state.dart b/frontend/app_student/lib/class_groups/cubit/class_group_state.dart index 5390c7e..7ee2c23 100644 --- a/frontend/app_student/lib/class_groups/cubit/class_group_state.dart +++ b/frontend/app_student/lib/class_groups/cubit/class_group_state.dart @@ -8,7 +8,7 @@ class ClassGroupInitial extends ClassGroupState {} class ClassGroupLoading extends ClassGroupState {} class ClassGroupLoaded extends ClassGroupState { - final List classes; + final List classes; ClassGroupLoaded(this.classes); } diff --git a/frontend/app_student/lib/day_schedule/cubit/day_schedule_cubit.dart b/frontend/app_student/lib/day_schedule/cubit/day_schedule_cubit.dart deleted file mode 100644 index 5cc1618..0000000 --- a/frontend/app_student/lib/day_schedule/cubit/day_schedule_cubit.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:app_student/api/day_schedule/repositories/day_schedule.dart'; -import 'package:bloc/bloc.dart'; -import 'package:meta/meta.dart'; - -part 'day_schedule_state.dart'; - -class DayScheduleCubit extends Cubit { - final DayScheduleRepository dayScheduleRepository; - - DayScheduleCubit({required this.dayScheduleRepository}) - : super(DayScheduleInitial()); - - Future fetchDaySchedule(String className) async { - try { - emit(DayScheduleLoading()); - final daySchedule = await dayScheduleRepository.getDaySchedule(className); - emit(DayScheduleLoaded(daySchedule)); - } catch (e) { - emit(DayScheduleError(e.toString())); - } - } -} - - - diff --git a/frontend/app_student/lib/day_schedule/cubit/day_schedule_state.dart b/frontend/app_student/lib/day_schedule/cubit/day_schedule_state.dart deleted file mode 100644 index a2ed3c9..0000000 --- a/frontend/app_student/lib/day_schedule/cubit/day_schedule_state.dart +++ /dev/null @@ -1,20 +0,0 @@ -part of 'day_schedule_cubit.dart'; - -@immutable -abstract class DayScheduleState {} - -class DayScheduleInitial extends DayScheduleState {} - -class DayScheduleLoading extends DayScheduleState {} - -class DayScheduleLoaded extends DayScheduleState { - final List daySchedule; - - DayScheduleLoaded(this.daySchedule); -} - -class DayScheduleError extends DayScheduleState { - final String message; - - DayScheduleError(this.message); -} \ No newline at end of file diff --git a/frontend/app_student/lib/day_schedule/views/day_schedule.dart b/frontend/app_student/lib/day_schedule/views/day_schedule.dart deleted file mode 100644 index a94bc97..0000000 --- a/frontend/app_student/lib/day_schedule/views/day_schedule.dart +++ /dev/null @@ -1,51 +0,0 @@ -import 'package:app_student/api/day_schedule/repositories/day_schedule.dart'; -import 'package:app_student/day_schedule/cubit/day_schedule_cubit.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -class DaySchedulePage extends StatelessWidget { - const DaySchedulePage({super.key}); - - @override - Widget build(BuildContext context) { - final dayScheduleRepository = - RepositoryProvider.of(context); - final dayScheduleCubit = DayScheduleCubit(dayScheduleRepository: dayScheduleRepository); - - return BlocProvider( - create: (context) => dayScheduleCubit..fetchDaySchedule('B3 Groupe 3 DLW-FA'), - child: Scaffold( - appBar: AppBar( - title: const Text('Day Schedule'), - ), - body: BlocBuilder( - builder: (context, state) { - if (state is DayScheduleLoading) { - return const Center(child: CircularProgressIndicator()); - } else if (state is DayScheduleLoaded) { - return ListView.builder( - itemCount: state.daySchedule.length, - itemBuilder: (context, index) { - final daySchedule = state.daySchedule[index]; - return ListTile( - title: Text('Date: ${daySchedule.date}, Jour: ${daySchedule.jour}'), - subtitle: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: daySchedule.events.map((event) { - return Text('Event: ${event.activite}, Start at: ${event.horaires.startAt}, End Time: ${event.horaires.endAt}'); - }).toList(), - ), - ); - }, - ); - } else if (state is DayScheduleError) { - return Center(child: Text(state.message)); - } else { - return const SizedBox.shrink(); - } - }, - ), - ), - ); - } -} diff --git a/frontend/app_student/lib/main_dev.dart b/frontend/app_student/lib/main_dev.dart index b0a1f7e..81125f8 100644 --- a/frontend/app_student/lib/main_dev.dart +++ b/frontend/app_student/lib/main_dev.dart @@ -1,12 +1,15 @@ +import 'package:app_student/api/schedule/repositories/schedule_repository.dart'; import 'package:app_student/config/dev_config.dart'; + import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:provider/provider.dart'; import 'api/api_service.dart'; -import 'api/day_schedule/repositories/day_schedule.dart'; +import 'api/class_groups/repositories/class_group_repository.dart'; +import 'class_groups/views/class_group_view.dart'; import 'config/config.dart'; -import 'day_schedule/views/day_schedule.dart'; +import 'schedule/views/schedule_view.dart'; void main() { runApp( @@ -20,27 +23,28 @@ void main() { class MyApp extends StatelessWidget { const MyApp({super.key}); - @override - Widget build(BuildContext context) { - return Provider( - create: (_) => DevConfig(), - child: RepositoryProvider( - create: (context) => DayScheduleRepository( - apiService: ApiService(apiUrl: context.read().apiUrl), className: 'B3 Groupe 3 DLW-FA'), - child: const MaterialApp(home: DaySchedulePage()), - ), - ); - } - // @override // Widget build(BuildContext context) { // return Provider( // create: (_) => DevConfig(), - // child: RepositoryProvider( - // create: (context) => ClassGroupRepository( - // apiService: ApiService(apiUrl: context.read().apiUrl)), - // child: const MaterialApp(home: ClassListPage()), + // child: RepositoryProvider( + // create: (context) => ScheduleRepository( + // apiService: ApiService(apiUrl: context.read().apiUrl), + // className: 'B3 Groupe 3 DLW-FA'), + // child: const MaterialApp(home: SchedulePage()), // ), // ); // } + + @override + Widget build(BuildContext context) { + return Provider( + create: (_) => DevConfig(), + child: RepositoryProvider( + create: (context) => ClassGroupRepository( + apiService: ApiService(apiUrl: context.read().apiUrl)), + child: const MaterialApp(home: ClassListPage()), + ), + ); + } } diff --git a/frontend/app_student/lib/schedule/cubit/schedule_cubit.dart b/frontend/app_student/lib/schedule/cubit/schedule_cubit.dart new file mode 100644 index 0000000..5be3a66 --- /dev/null +++ b/frontend/app_student/lib/schedule/cubit/schedule_cubit.dart @@ -0,0 +1,23 @@ +import 'package:app_student/api/schedule/models/schedule_model.dart'; +import 'package:app_student/api/schedule/repositories/schedule_repository.dart'; +import 'package:bloc/bloc.dart'; +import 'package:meta/meta.dart'; + +part 'schedule_state.dart'; + +class ScheduleCubit extends Cubit { + final ScheduleRepository scheduleRepository; + + ScheduleCubit({required this.scheduleRepository}) : super(ScheduleInitial()); + + Future fetchSchedule(String className) async { + try { + print(scheduleRepository.getSchedule(className)); + emit(ScheduleLoading()); + final schedule = await scheduleRepository.getSchedule(className); + emit(ScheduleLoaded(schedule)); + } catch (e) { + emit(ScheduleError(e.toString())); + } + } +} diff --git a/frontend/app_student/lib/schedule/cubit/schedule_state.dart b/frontend/app_student/lib/schedule/cubit/schedule_state.dart new file mode 100644 index 0000000..fec9be2 --- /dev/null +++ b/frontend/app_student/lib/schedule/cubit/schedule_state.dart @@ -0,0 +1,19 @@ +part of 'schedule_cubit.dart'; + +@immutable +abstract class ScheduleState {} + +class ScheduleInitial extends ScheduleState {} + +class ScheduleLoading extends ScheduleState {} + +class ScheduleLoaded extends ScheduleState { + final ScheduleModel schedule; + + ScheduleLoaded(this.schedule); +} +class ScheduleError extends ScheduleState { + final String message; + + ScheduleError(this.message); +} diff --git a/frontend/app_student/lib/schedule/views/schedule_view.dart b/frontend/app_student/lib/schedule/views/schedule_view.dart new file mode 100644 index 0000000..3bdd20a --- /dev/null +++ b/frontend/app_student/lib/schedule/views/schedule_view.dart @@ -0,0 +1,57 @@ +import 'package:app_student/api/schedule/repositories/schedule_repository.dart'; +import 'package:app_student/schedule/cubit/schedule_cubit.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +class SchedulePage extends StatelessWidget { + const SchedulePage({super.key}); + + @override + Widget build(BuildContext context) { + final scheduleRepository = + RepositoryProvider.of(context); + final scheduleCubit = ScheduleCubit(scheduleRepository: scheduleRepository); + + return BlocProvider( + create: (context) => scheduleCubit..fetchSchedule('B3 Groupe 3 DLW-FA'), + child: Scaffold( + appBar: AppBar( + title: const Text('Schedule'), + ), + body: BlocBuilder( + builder: (context, state) { + if (state is ScheduleLoading) { + return const Center(child: CircularProgressIndicator()); + } else if (state is ScheduleLoaded) { + return ListView.builder( + itemCount: state.schedule.weekSchedules.length, + itemBuilder: (context, index) { + return ExpansionTile( + title: Text('Week ${state.schedule.weekSchedules[index].code}'), + children: state.schedule.weekSchedules[index].daySchedules.map((day) { + return ExpansionTile( + title: Text('Day ${day.jour}'), + children: day.events.map((event) { + return ListTile( + title: Text(event.activite), + subtitle: Text( + 'From ${event.horaires.startAt} to ${event.horaires.endAt}'), + trailing: Text(event.salle), + ); + }).toList(), + ); + }).toList(), + ); + }, + ); + } else if (state is ScheduleError) { + return Center(child: Text(state.message)); + } else { + return const SizedBox.shrink(); + } + }, + ), + ), + ); + } +} 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 new file mode 100644 index 0000000..ff8d5ff --- /dev/null +++ b/frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart @@ -0,0 +1,23 @@ +import 'package:app_student/api/week_schedule/repositories/week_schedule_repositories.dart'; +import 'package:bloc/bloc.dart'; +import 'package:meta/meta.dart'; + +part 'week_schedule_state.dart'; + +class WeekScheduleCubit extends Cubit { + final WeekScheduleRepository weekScheduleRepository; + + WeekScheduleCubit({required this.weekScheduleRepository}) + : super(WeekScheduleInitial()); + + Future fetchWeekSchedule(String className) async { + try { + emit(WeekScheduleLoading()); + final weekSchedule = + await weekScheduleRepository.getWeeksSchedule(className); + emit(WeekScheduleLoaded(weekSchedule)); + } catch (e) { + emit(WeekScheduleError(e.toString())); + } + } +} diff --git a/frontend/app_student/lib/week_schedule/cubit/week_schedule_state.dart b/frontend/app_student/lib/week_schedule/cubit/week_schedule_state.dart new file mode 100644 index 0000000..cea2f6f --- /dev/null +++ b/frontend/app_student/lib/week_schedule/cubit/week_schedule_state.dart @@ -0,0 +1,20 @@ +part of 'week_schedule_cubit.dart'; + +@immutable +abstract class WeekScheduleState {} + +class WeekScheduleInitial extends WeekScheduleState {} + +class WeekScheduleLoading extends WeekScheduleState {} + +class WeekScheduleLoaded extends WeekScheduleState { + final List weekSchedule; + + WeekScheduleLoaded(this.weekSchedule); +} + +class WeekScheduleError extends WeekScheduleState { + final String message; + + WeekScheduleError(this.message); +} diff --git a/frontend/app_student/lib/week_schedule/views/week_schedule.dart b/frontend/app_student/lib/week_schedule/views/week_schedule.dart new file mode 100644 index 0000000..ea3cdbc --- /dev/null +++ b/frontend/app_student/lib/week_schedule/views/week_schedule.dart @@ -0,0 +1,56 @@ + +import 'package:app_student/api/week_schedule/repositories/week_schedule_repositories.dart'; +import 'package:app_student/week_schedule/cubit/week_schedule_cubit.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +class WeekSchedulePage extends StatelessWidget { + const WeekSchedulePage({super.key}); + + @override + Widget build(BuildContext context) { + final weekScheduleRepository = + RepositoryProvider.of(context); + final weekScheduleCubit = + WeekScheduleCubit(weekScheduleRepository: weekScheduleRepository); + + return BlocProvider( + create: (context) => + weekScheduleCubit..fetchWeekSchedule('B3 Groupe 3 DLW-FA'), + child: Scaffold( + appBar: AppBar( + title: const Text('Week Schedule'), + ), + body: BlocBuilder( + builder: (context, state) { + if (state is WeekScheduleLoading) { + return const Center(child: CircularProgressIndicator()); + } else if (state is WeekScheduleLoaded) { + return ListView.builder( + itemCount: state.weekSchedule.length, + itemBuilder: (context, index) { + final WeekSchedule = state.weekSchedule[index]; + return ListTile( + title: Text( + 'Date: ${WeekSchedule.date}, Jour: ${WeekSchedule.jour}'), + subtitle: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: WeekSchedule.events.map((event) { + return Text( + 'Event: ${event.activite}, Start at: ${event.horaires.startAt}, End Time: ${event.horaires.endAt}'); + }).toList(), + ), + ); + }, + ); + } else if (state is WeekScheduleError) { + return Center(child: Text(state.message)); + } else { + return const SizedBox.shrink(); + } + }, + ), + ), + ); + } +} From 977fa0b693932365e1381c5bc1a53e5d30b79b30 Mon Sep 17 00:00:00 2001 From: Jules Artaud Date: Tue, 12 Mar 2024 10:26:25 +0100 Subject: [PATCH 04/12] =?UTF-8?q?=F0=9F=9A=A7:=20trying=20to=20get=20weeks?= =?UTF-8?q?chedule=20data=20and=20remove=20schedule=20data=20layer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app_student/lib/api/api_service.dart | 42 ++++---------- .../repositories/day_schedule.dart | 8 +-- .../schedule/entities/schedule_entity.dart | 23 -------- .../api/schedule/models/schedule_model.dart | 11 ---- .../repositories/schedule_repository.dart | 17 ------ .../entities/week_schedule_entity.dart | 9 ++- .../models/week_schedule_model.dart | 11 ++-- .../week_schedule_repositories.dart | 7 +-- .../class_groups/cubit/class_group_cubit.dart | 2 +- frontend/app_student/lib/main_dev.dart | 40 +++++++------ .../lib/schedule/cubit/schedule_cubit.dart | 23 -------- .../lib/schedule/cubit/schedule_state.dart | 19 ------- .../lib/schedule/views/schedule_view.dart | 57 ------------------- .../week_schedule/views/week_schedule.dart | 18 +++--- 14 files changed, 56 insertions(+), 231 deletions(-) delete mode 100644 frontend/app_student/lib/api/schedule/entities/schedule_entity.dart delete mode 100644 frontend/app_student/lib/api/schedule/models/schedule_model.dart delete mode 100644 frontend/app_student/lib/api/schedule/repositories/schedule_repository.dart delete mode 100644 frontend/app_student/lib/schedule/cubit/schedule_cubit.dart delete mode 100644 frontend/app_student/lib/schedule/cubit/schedule_state.dart delete mode 100644 frontend/app_student/lib/schedule/views/schedule_view.dart diff --git a/frontend/app_student/lib/api/api_service.dart b/frontend/app_student/lib/api/api_service.dart index b63d6be..c50c4cb 100644 --- a/frontend/app_student/lib/api/api_service.dart +++ b/frontend/app_student/lib/api/api_service.dart @@ -16,8 +16,18 @@ class ApiService { if (response.statusCode == 200) { List jsonResponse = json.decode(response.body); - print('JSON Response: $jsonResponse'); // Print the JSON response - return jsonResponse.map((item) => fromJson(item)).toList(); + print('JSON Response: $jsonResponse'); + + return jsonResponse.map((item) { + print('Item: $item'); // Print the item before conversion + try { + return fromJson(item); + } catch (e) { + print( + 'Failed to convert item: $e'); // Print the error if conversion fails + throw e; + } + }).toList(); } else { throw Exception('ERROR ${response.statusCode} Failed to load data'); } @@ -25,32 +35,4 @@ class ApiService { throw Exception('Failed to load data: $e'); } } - -// Future> getData( -// String endpoint, T Function(Map) fromJson) async { -// String fullUrl = '$apiUrl$endpoint'; -// fullUrl = Uri.encodeFull(fullUrl); -// print(fullUrl); -// try { -// final response = await http.get(Uri.parse(fullUrl)); -// -// if (response.statusCode == 200) { -// var jsonResponse = json.decode(response.body); -// print('JSON Response: $jsonResponse'); // Print the JSON response -// -// // Check if jsonResponse is a Map. If so, convert it to a List -// if (jsonResponse is Map) { -// jsonResponse = [jsonResponse]; -// } -// -// return jsonResponse.map((item) => fromJson(item)).toList(); -// } else { -// print('ERROR ${response.statusCode} Failed to load data'); -// throw Exception('ERROR ${response.statusCode} Failed to load data'); -// } -// } catch (e) { -// print('Failed to load data: $e'); -// throw Exception('Failed to load data: $e'); -// } -// } } 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 index 8860595..1d75c76 100644 --- a/frontend/app_student/lib/api/day_schedule/repositories/day_schedule.dart +++ b/frontend/app_student/lib/api/day_schedule/repositories/day_schedule.dart @@ -7,8 +7,8 @@ class DayScheduleRepository { DayScheduleRepository({required this.className, required this.apiService}); -Future> getDaySchedule($className) { - return apiService.getData('/api/timetable?class_param=$className', - (item) => DayScheduleEntity.fromJson(item)); -} + Future> getDaySchedule($className) { + return apiService.getData('/api/timetable?class_param=$className', + (item) => DayScheduleEntity.fromJson(item)); + } } diff --git a/frontend/app_student/lib/api/schedule/entities/schedule_entity.dart b/frontend/app_student/lib/api/schedule/entities/schedule_entity.dart deleted file mode 100644 index 94f22a0..0000000 --- a/frontend/app_student/lib/api/schedule/entities/schedule_entity.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:app_student/api/week_schedule/entities/week_schedule_entity.dart'; - -class ScheduleEntity { - final int id; - final List weekSchedules; - - ScheduleEntity({ - required this.id, - required this.weekSchedules, - }); - - factory ScheduleEntity.fromJson(Map json) { - var weekSchedulesFromJson = json['Weeks'] as List; - List weekSchedulesList = weekSchedulesFromJson - .map((i) => WeekScheduleEntity.fromJson(i)) - .toList(); - - return ScheduleEntity( - id: json['id'], - weekSchedules: weekSchedulesList, - ); - } -} diff --git a/frontend/app_student/lib/api/schedule/models/schedule_model.dart b/frontend/app_student/lib/api/schedule/models/schedule_model.dart deleted file mode 100644 index c1fe5b9..0000000 --- a/frontend/app_student/lib/api/schedule/models/schedule_model.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'package:app_student/api/schedule/entities/schedule_entity.dart'; -import 'package:app_student/api/week_schedule/entities/week_schedule_entity.dart'; - -class ScheduleModel { - final ScheduleEntity schedule; - - ScheduleModel({required this.schedule}); - - int get id => schedule.id; - List get weekSchedules => schedule.weekSchedules; -} diff --git a/frontend/app_student/lib/api/schedule/repositories/schedule_repository.dart b/frontend/app_student/lib/api/schedule/repositories/schedule_repository.dart deleted file mode 100644 index 172e764..0000000 --- a/frontend/app_student/lib/api/schedule/repositories/schedule_repository.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'package:app_student/api/api_service.dart'; -import 'package:app_student/api/schedule/entities/schedule_entity.dart'; -import 'package:app_student/api/schedule/models/schedule_model.dart'; - -class ScheduleRepository { - final ApiService apiService; - final String className; - - ScheduleRepository({required this.apiService, required this.className}); - - Future getSchedule(className) { - return apiService.getData('/api/timetable?class_param=$className', (item) { - final entity = ScheduleEntity.fromJson(item); - return ScheduleModel(schedule: entity); - }).then((list) => list.first); - } -} diff --git a/frontend/app_student/lib/api/week_schedule/entities/week_schedule_entity.dart b/frontend/app_student/lib/api/week_schedule/entities/week_schedule_entity.dart index 5e48453..a56c5d8 100644 --- a/frontend/app_student/lib/api/week_schedule/entities/week_schedule_entity.dart +++ b/frontend/app_student/lib/api/week_schedule/entities/week_schedule_entity.dart @@ -10,13 +10,12 @@ class WeekScheduleEntity { }); factory WeekScheduleEntity.fromJson(Map json) { - var daySchedulesFromJson = json['DaySchedule'] as List; - List daySchedulesList = - daySchedulesFromJson.map((i) => DayScheduleEntity.fromJson(i)).toList(); - return WeekScheduleEntity( code: json['code'], - daySchedules: daySchedulesList, + daySchedules: (json['DaySchedule'] as List) + .map((daySchedule) => + DayScheduleEntity.fromJson(daySchedule as Map)) + .toList(), ); } } 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 6da76d9..279723d 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,11 +1,14 @@ import 'package:app_student/api/day_schedule/entities/day_schedule_entity.dart'; +import '../entities/week_schedule_entity.dart'; + class WeekScheduleModel { - final String code; - final List daySchedules; + final WeekScheduleEntity weekSchedule; WeekScheduleModel({ - required this.code, - required this.daySchedules, + required this.weekSchedule, }); + + String get code => weekSchedule.code; + List get daySchedules => weekSchedule.daySchedules; } 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_repositories.dart index 5b27e69..39e3b53 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_repositories.dart @@ -1,5 +1,3 @@ -import 'dart:convert'; - import 'package:app_student/api/api_service.dart'; import 'package:app_student/api/week_schedule/entities/week_schedule_entity.dart'; import 'package:app_student/api/week_schedule/models/week_schedule_model.dart'; @@ -12,10 +10,7 @@ class WeekScheduleRepository { Future> getWeeksSchedule(className) { return apiService.getData('/api/timetable?class_param=$className', (item) { final entity = WeekScheduleEntity.fromJson(item); - return WeekScheduleModel( - code: entity.code, - daySchedules: entity.daySchedules, - ); + return WeekScheduleModel(weekSchedule: entity); }); } } diff --git a/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart b/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart index 636b7bf..c2803d6 100644 --- a/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart +++ b/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart @@ -20,4 +20,4 @@ class ClassGroupCubit extends Cubit { emit(ClassGroupError(e.toString())); } } -} \ No newline at end of file +} diff --git a/frontend/app_student/lib/main_dev.dart b/frontend/app_student/lib/main_dev.dart index 81125f8..bf0e355 100644 --- a/frontend/app_student/lib/main_dev.dart +++ b/frontend/app_student/lib/main_dev.dart @@ -1,15 +1,13 @@ -import 'package:app_student/api/schedule/repositories/schedule_repository.dart'; +import 'package:app_student/api/week_schedule/repositories/week_schedule_repositories.dart'; import 'package:app_student/config/dev_config.dart'; +import 'package:app_student/week_schedule/views/week_schedule.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:provider/provider.dart'; import 'api/api_service.dart'; -import 'api/class_groups/repositories/class_group_repository.dart'; -import 'class_groups/views/class_group_view.dart'; import 'config/config.dart'; -import 'schedule/views/schedule_view.dart'; void main() { runApp( @@ -23,28 +21,28 @@ void main() { class MyApp extends StatelessWidget { const MyApp({super.key}); - // @override - // Widget build(BuildContext context) { - // return Provider( - // create: (_) => DevConfig(), - // child: RepositoryProvider( - // create: (context) => ScheduleRepository( - // apiService: ApiService(apiUrl: context.read().apiUrl), - // className: 'B3 Groupe 3 DLW-FA'), - // child: const MaterialApp(home: SchedulePage()), - // ), - // ); - // } - @override Widget build(BuildContext context) { return Provider( create: (_) => DevConfig(), - child: RepositoryProvider( - create: (context) => ClassGroupRepository( - apiService: ApiService(apiUrl: context.read().apiUrl)), - child: const MaterialApp(home: ClassListPage()), + child: RepositoryProvider( + create: (context) => WeekScheduleRepository( + apiService: ApiService(apiUrl: context.read().apiUrl), + className: 'B3 Groupe 3 DLW-FA'), + child: const MaterialApp(home: WeekSchedulePage()), ), ); } + +// @override +// Widget build(BuildContext context) { +// return Provider( +// create: (_) => DevConfig(), +// child: RepositoryProvider( +// create: (context) => ClassGroupRepository( +// apiService: ApiService(apiUrl: context.read().apiUrl)), +// child: const MaterialApp(home: ClassListPage()), +// ), +// ); +// } } diff --git a/frontend/app_student/lib/schedule/cubit/schedule_cubit.dart b/frontend/app_student/lib/schedule/cubit/schedule_cubit.dart deleted file mode 100644 index 5be3a66..0000000 --- a/frontend/app_student/lib/schedule/cubit/schedule_cubit.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:app_student/api/schedule/models/schedule_model.dart'; -import 'package:app_student/api/schedule/repositories/schedule_repository.dart'; -import 'package:bloc/bloc.dart'; -import 'package:meta/meta.dart'; - -part 'schedule_state.dart'; - -class ScheduleCubit extends Cubit { - final ScheduleRepository scheduleRepository; - - ScheduleCubit({required this.scheduleRepository}) : super(ScheduleInitial()); - - Future fetchSchedule(String className) async { - try { - print(scheduleRepository.getSchedule(className)); - emit(ScheduleLoading()); - final schedule = await scheduleRepository.getSchedule(className); - emit(ScheduleLoaded(schedule)); - } catch (e) { - emit(ScheduleError(e.toString())); - } - } -} diff --git a/frontend/app_student/lib/schedule/cubit/schedule_state.dart b/frontend/app_student/lib/schedule/cubit/schedule_state.dart deleted file mode 100644 index fec9be2..0000000 --- a/frontend/app_student/lib/schedule/cubit/schedule_state.dart +++ /dev/null @@ -1,19 +0,0 @@ -part of 'schedule_cubit.dart'; - -@immutable -abstract class ScheduleState {} - -class ScheduleInitial extends ScheduleState {} - -class ScheduleLoading extends ScheduleState {} - -class ScheduleLoaded extends ScheduleState { - final ScheduleModel schedule; - - ScheduleLoaded(this.schedule); -} -class ScheduleError extends ScheduleState { - final String message; - - ScheduleError(this.message); -} diff --git a/frontend/app_student/lib/schedule/views/schedule_view.dart b/frontend/app_student/lib/schedule/views/schedule_view.dart deleted file mode 100644 index 3bdd20a..0000000 --- a/frontend/app_student/lib/schedule/views/schedule_view.dart +++ /dev/null @@ -1,57 +0,0 @@ -import 'package:app_student/api/schedule/repositories/schedule_repository.dart'; -import 'package:app_student/schedule/cubit/schedule_cubit.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -class SchedulePage extends StatelessWidget { - const SchedulePage({super.key}); - - @override - Widget build(BuildContext context) { - final scheduleRepository = - RepositoryProvider.of(context); - final scheduleCubit = ScheduleCubit(scheduleRepository: scheduleRepository); - - return BlocProvider( - create: (context) => scheduleCubit..fetchSchedule('B3 Groupe 3 DLW-FA'), - child: Scaffold( - appBar: AppBar( - title: const Text('Schedule'), - ), - body: BlocBuilder( - builder: (context, state) { - if (state is ScheduleLoading) { - return const Center(child: CircularProgressIndicator()); - } else if (state is ScheduleLoaded) { - return ListView.builder( - itemCount: state.schedule.weekSchedules.length, - itemBuilder: (context, index) { - return ExpansionTile( - title: Text('Week ${state.schedule.weekSchedules[index].code}'), - children: state.schedule.weekSchedules[index].daySchedules.map((day) { - return ExpansionTile( - title: Text('Day ${day.jour}'), - children: day.events.map((event) { - return ListTile( - title: Text(event.activite), - subtitle: Text( - 'From ${event.horaires.startAt} to ${event.horaires.endAt}'), - trailing: Text(event.salle), - ); - }).toList(), - ); - }).toList(), - ); - }, - ); - } else if (state is ScheduleError) { - return Center(child: Text(state.message)); - } else { - return const SizedBox.shrink(); - } - }, - ), - ), - ); - } -} 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 ea3cdbc..33ddbbc 100644 --- a/frontend/app_student/lib/week_schedule/views/week_schedule.dart +++ b/frontend/app_student/lib/week_schedule/views/week_schedule.dart @@ -1,4 +1,3 @@ - import 'package:app_student/api/week_schedule/repositories/week_schedule_repositories.dart'; import 'package:app_student/week_schedule/cubit/week_schedule_cubit.dart'; import 'package:flutter/material.dart'; @@ -31,15 +30,14 @@ class WeekSchedulePage extends StatelessWidget { itemBuilder: (context, index) { final WeekSchedule = state.weekSchedule[index]; return ListTile( - title: Text( - 'Date: ${WeekSchedule.date}, Jour: ${WeekSchedule.jour}'), - subtitle: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: WeekSchedule.events.map((event) { - return Text( - 'Event: ${event.activite}, Start at: ${event.horaires.startAt}, End Time: ${event.horaires.endAt}'); - }).toList(), - ), + title: Text('Code: ${WeekSchedule.code}'), + // subtitle: Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: WeekSchedule.events.map((event) { + // return Text( + // 'Event: ${event.activite}, Start at: ${event.horaires.startAt}, End Time: ${event.horaires.endAt}'); + // }).toList(), + // ), ); }, ); From 273baed1612253d712e7f0e6717ba4304c209270 Mon Sep 17 00:00:00 2001 From: Lukas <35173609+PHPLukaas@users.noreply.github.com> Date: Tue, 12 Mar 2024 10:57:08 +0100 Subject: [PATCH 05/12] =?UTF-8?q?=F0=9F=90=9B:=20fixed=20entity=20models?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app_student/lib/api/api_service.dart | 4 ++++ .../lib/api/day_schedule/entities/day_schedule_entity.dart | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/app_student/lib/api/api_service.dart b/frontend/app_student/lib/api/api_service.dart index c50c4cb..0eae58e 100644 --- a/frontend/app_student/lib/api/api_service.dart +++ b/frontend/app_student/lib/api/api_service.dart @@ -1,4 +1,5 @@ import 'dart:convert'; + import 'package:http/http.dart' as http; class ApiService { @@ -25,6 +26,9 @@ class ApiService { } catch (e) { print( 'Failed to convert item: $e'); // Print the error if conversion fails + print( + 'Failed item: $item'); // Print the item that failed to convert + throw e; } }).toList(); diff --git a/frontend/app_student/lib/api/day_schedule/entities/day_schedule_entity.dart b/frontend/app_student/lib/api/day_schedule/entities/day_schedule_entity.dart index 033c3a5..6da93e5 100644 --- a/frontend/app_student/lib/api/day_schedule/entities/day_schedule_entity.dart +++ b/frontend/app_student/lib/api/day_schedule/entities/day_schedule_entity.dart @@ -12,12 +12,14 @@ class DayScheduleEntity { }); factory DayScheduleEntity.fromJson(Map json) { - var eventsFromJson = json['cours'] as List; + var eventsFromJson = json['events'] as List; List eventsList = eventsFromJson.map((i) => EventEntity.fromJson(i)).toList(); + DateTime date = DateTime.parse(json['date']); + return DayScheduleEntity( - date: json['date'], + date: date, jour: json['jour'], events: eventsList, ); From 1997a9946e127c7656bb1a33029b0ee41b109093 Mon Sep 17 00:00:00 2001 From: Lukas <35173609+PHPLukaas@users.noreply.github.com> Date: Tue, 12 Mar 2024 11:00:31 +0100 Subject: [PATCH 06/12] =?UTF-8?q?=F0=9F=90=9B:=20fixed=20entity=20with=20a?= =?UTF-8?q?pi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/api/event_hours/entities/event_hours_entity.dart | 4 ++-- .../app_student/lib/api/events/entities/event_entity.dart | 6 ++---- frontend/app_student/pubspec.yaml | 2 -- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/frontend/app_student/lib/api/event_hours/entities/event_hours_entity.dart b/frontend/app_student/lib/api/event_hours/entities/event_hours_entity.dart index 0d73a54..8f0a23c 100644 --- a/frontend/app_student/lib/api/event_hours/entities/event_hours_entity.dart +++ b/frontend/app_student/lib/api/event_hours/entities/event_hours_entity.dart @@ -9,8 +9,8 @@ class EventHoursEntity { factory EventHoursEntity.fromJson(Map json) { return EventHoursEntity( - startAt: json['start'], - endAt: json['end'], + startAt: json['startAt'], + endAt: json['endAt'], ); } } diff --git a/frontend/app_student/lib/api/events/entities/event_entity.dart b/frontend/app_student/lib/api/events/entities/event_entity.dart index 06a164a..a5baeac 100644 --- a/frontend/app_student/lib/api/events/entities/event_entity.dart +++ b/frontend/app_student/lib/api/events/entities/event_entity.dart @@ -1,5 +1,3 @@ -import 'dart:ffi'; - import '../../event_hours/entities/event_hours_entity.dart'; class EventEntity { @@ -9,7 +7,7 @@ class EventEntity { final String couleur; final EventHoursEntity horaires; final String salle; - final Bool visio; + final bool visio; EventEntity({ required this.id, @@ -29,7 +27,7 @@ class EventEntity { couleur: json['couleur'] ?? 'null', horaires: EventHoursEntity.fromJson(json['horaire']), salle: json['salle'] ?? 'null', - visio: json['visio'] ?? 'null', + visio: json['visio'] ?? false, ); } } diff --git a/frontend/app_student/pubspec.yaml b/frontend/app_student/pubspec.yaml index ff5d2c2..f606863 100644 --- a/frontend/app_student/pubspec.yaml +++ b/frontend/app_student/pubspec.yaml @@ -37,8 +37,6 @@ dependencies: cupertino_icons: ^1.0.6 http: ^1.2.1 provider: ^6.1.2 - bloc: ^8.1.3 - flutter_bloc: ^8.1.4 dev_dependencies: flutter_test: From 4bf85eaf69f9e77ee941d6e8536c6647b39b552a Mon Sep 17 00:00:00 2001 From: Jules Artaud Date: Tue, 12 Mar 2024 11:26:57 +0100 Subject: [PATCH 07/12] =?UTF-8?q?=F0=9F=90=9B:=20fix=20week=20schedule=20v?= =?UTF-8?q?ie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../week_schedule/views/week_schedule.dart | 55 +++++++++++++++---- frontend/app_student/pubspec.yaml | 2 + 2 files changed, 45 insertions(+), 12 deletions(-) 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 33ddbbc..7836714 100644 --- a/frontend/app_student/lib/week_schedule/views/week_schedule.dart +++ b/frontend/app_student/lib/week_schedule/views/week_schedule.dart @@ -1,10 +1,50 @@ +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/week_schedule/cubit/week_schedule_cubit.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +class DayScheduleWidget extends StatelessWidget { + final DayScheduleEntity daySchedule; + + const DayScheduleWidget({Key? key, required this.daySchedule}) + : super(key: key); + + @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({Key? key, required this.weekSchedule}) + : super(key: key); + + @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}); + const WeekSchedulePage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -28,17 +68,8 @@ class WeekSchedulePage extends StatelessWidget { return ListView.builder( itemCount: state.weekSchedule.length, itemBuilder: (context, index) { - final WeekSchedule = state.weekSchedule[index]; - return ListTile( - title: Text('Code: ${WeekSchedule.code}'), - // subtitle: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: WeekSchedule.events.map((event) { - // return Text( - // 'Event: ${event.activite}, Start at: ${event.horaires.startAt}, End Time: ${event.horaires.endAt}'); - // }).toList(), - // ), - ); + final weekSchedule = state.weekSchedule[index]; + return WeekScheduleWidget(weekSchedule: weekSchedule); }, ); } else if (state is WeekScheduleError) { diff --git a/frontend/app_student/pubspec.yaml b/frontend/app_student/pubspec.yaml index f606863..ff5d2c2 100644 --- a/frontend/app_student/pubspec.yaml +++ b/frontend/app_student/pubspec.yaml @@ -37,6 +37,8 @@ dependencies: cupertino_icons: ^1.0.6 http: ^1.2.1 provider: ^6.1.2 + bloc: ^8.1.3 + flutter_bloc: ^8.1.4 dev_dependencies: flutter_test: From 3f142694a17c4d0ead4ccbe4ee262bb77dcd58cc Mon Sep 17 00:00:00 2001 From: Jules Artaud Date: Tue, 12 Mar 2024 17:06:18 +0100 Subject: [PATCH 08/12] =?UTF-8?q?=E2=99=BB=EF=B8=8F:=20remove=20useless=20?= =?UTF-8?q?import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app_student/lib/class_groups/cubit/class_group_cubit.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart b/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart index c2803d6..cd2c584 100644 --- a/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart +++ b/frontend/app_student/lib/class_groups/cubit/class_group_cubit.dart @@ -1,6 +1,5 @@ import 'package:app_student/api/class_groups/models/class_group_model.dart'; import 'package:app_student/api/class_groups/repositories/class_group_repository.dart'; -import 'package:app_student/api/class_groups/entities/class_group_entity.dart'; import 'package:bloc/bloc.dart'; import 'package:meta/meta.dart'; From e966725384dd8f285d29b30897bf130ad1d85ef0 Mon Sep 17 00:00:00 2001 From: Jules Date: Tue, 12 Mar 2024 17:09:18 +0100 Subject: [PATCH 09/12] fix: remove .env data --- backend/.env | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/.env b/backend/.env index 26ddcf0..868ff55 100644 --- a/backend/.env +++ b/backend/.env @@ -15,8 +15,8 @@ # https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration ###> symfony/framework-bundle ### -APP_ENV=dev -APP_SECRET=dqdqdqdjihsuadguagduay +APP_ENV= +APP_SECRET= ###< symfony/framework-bundle ### -APP_3IL_SCHEDULE_URL=https://eleves.groupe3il.fr/edt_eleves/ +APP_3IL_SCHEDULE_URL= From 241f4039ee8950f1ea778106dfa29bad15ca8f5f Mon Sep 17 00:00:00 2001 From: Jules Date: Tue, 12 Mar 2024 17:16:59 +0100 Subject: [PATCH 10/12] =?UTF-8?q?=E2=99=BB=EF=B8=8F:=20remove=20print=20li?= =?UTF-8?q?nter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app_student/lib/api/api_service.dart | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/frontend/app_student/lib/api/api_service.dart b/frontend/app_student/lib/api/api_service.dart index 0eae58e..a6cbf06 100644 --- a/frontend/app_student/lib/api/api_service.dart +++ b/frontend/app_student/lib/api/api_service.dart @@ -11,25 +11,16 @@ class ApiService { String endpoint, T Function(Map) fromJson) async { String fullUrl = '$apiUrl$endpoint'; fullUrl = Uri.encodeFull(fullUrl); - print(fullUrl); try { final response = await http.get(Uri.parse(fullUrl)); if (response.statusCode == 200) { List jsonResponse = json.decode(response.body); - print('JSON Response: $jsonResponse'); - return jsonResponse.map((item) { - print('Item: $item'); // Print the item before conversion try { return fromJson(item); } catch (e) { - print( - 'Failed to convert item: $e'); // Print the error if conversion fails - print( - 'Failed item: $item'); // Print the item that failed to convert - - throw e; + rethrow; } }).toList(); } else { From a82538980158f00c4f13744e7b5a6231f4e68440 Mon Sep 17 00:00:00 2001 From: Jules Date: Tue, 12 Mar 2024 17:21:26 +0100 Subject: [PATCH 11/12] =?UTF-8?q?=E2=9E=95=EF=B8=8F:=20added=20meta=20depe?= =?UTF-8?q?dency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app_student/pubspec.lock | 2 +- frontend/app_student/pubspec.yaml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/app_student/pubspec.lock b/frontend/app_student/pubspec.lock index aa98c4d..423934a 100644 --- a/frontend/app_student/pubspec.lock +++ b/frontend/app_student/pubspec.lock @@ -156,7 +156,7 @@ packages: source: hosted version: "0.8.0" meta: - dependency: transitive + dependency: "direct main" description: name: meta sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 diff --git a/frontend/app_student/pubspec.yaml b/frontend/app_student/pubspec.yaml index ff5d2c2..e136faa 100644 --- a/frontend/app_student/pubspec.yaml +++ b/frontend/app_student/pubspec.yaml @@ -39,6 +39,7 @@ dependencies: provider: ^6.1.2 bloc: ^8.1.3 flutter_bloc: ^8.1.4 + meta: ^1.11.0 dev_dependencies: flutter_test: From 1ae71c4f78ad3bb535f0883ee489252a33d5274d Mon Sep 17 00:00:00 2001 From: Jules Date: Tue, 12 Mar 2024 17:23:32 +0100 Subject: [PATCH 12/12] =?UTF-8?q?=F0=9F=9A=A8:=20fix=20warnings=20from=20l?= =?UTF-8?q?inter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/week_schedule/views/week_schedule.dart | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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 7836714..3041815 100644 --- a/frontend/app_student/lib/week_schedule/views/week_schedule.dart +++ b/frontend/app_student/lib/week_schedule/views/week_schedule.dart @@ -8,8 +8,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; class DayScheduleWidget extends StatelessWidget { final DayScheduleEntity daySchedule; - const DayScheduleWidget({Key? key, required this.daySchedule}) - : super(key: key); + const DayScheduleWidget({super.key, required this.daySchedule}); @override Widget build(BuildContext context) { @@ -29,8 +28,7 @@ class DayScheduleWidget extends StatelessWidget { class WeekScheduleWidget extends StatelessWidget { final WeekScheduleModel weekSchedule; - const WeekScheduleWidget({Key? key, required this.weekSchedule}) - : super(key: key); + const WeekScheduleWidget({super.key, required this.weekSchedule}); @override Widget build(BuildContext context) { @@ -44,7 +42,7 @@ class WeekScheduleWidget extends StatelessWidget { } class WeekSchedulePage extends StatelessWidget { - const WeekSchedulePage({Key? key}) : super(key: key); + const WeekSchedulePage({super.key}); @override Widget build(BuildContext context) {