From e33a02c57dbface3710ca4bf6a054ed5db40a405 Mon Sep 17 00:00:00 2001 From: Jules Artaud Date: Fri, 8 Mar 2024 14:11:44 +0100 Subject: [PATCH] fix: added class_param to dayschedule bloc to get data - added file conf for run --- frontend/app_student/.run/main_dev.run.xml | 6 +++++ frontend/app_student/.run/main_prod.run.xml | 6 +++++ frontend/app_student/lib/api/api_service.dart | 22 ++++++++++--------- .../app_student/lib/config/dev_config.dart | 2 +- .../day_schedules/bloc/day_schedule_bloc.dart | 5 ++++- frontend/app_student/lib/main_prod.dart | 1 + 6 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 frontend/app_student/.run/main_dev.run.xml create mode 100644 frontend/app_student/.run/main_prod.run.xml diff --git a/frontend/app_student/.run/main_dev.run.xml b/frontend/app_student/.run/main_dev.run.xml new file mode 100644 index 0000000..b98f49e --- /dev/null +++ b/frontend/app_student/.run/main_dev.run.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/frontend/app_student/.run/main_prod.run.xml b/frontend/app_student/.run/main_prod.run.xml new file mode 100644 index 0000000..7a31433 --- /dev/null +++ b/frontend/app_student/.run/main_prod.run.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/frontend/app_student/lib/api/api_service.dart b/frontend/app_student/lib/api/api_service.dart index d1b3179..531d406 100644 --- a/frontend/app_student/lib/api/api_service.dart +++ b/frontend/app_student/lib/api/api_service.dart @@ -8,15 +8,17 @@ class ApiService { Future> getData( String endpoint, T Function(Map) fromJson) async { - final response = await http.get(Uri.parse('$apiUrl$endpoint')); - print('$apiUrl$endpoint'); - print('response.statusCode: ${response.statusCode}'); - if (response.statusCode == 200) { - List jsonResponse = json.decode(response.body); - return jsonResponse.map((item) => fromJson(item)).toList(); - } else { - print('response.body: ${response.body}'); - throw Exception('Failed to load data'); + try { + final response = await http.get(Uri.parse('$apiUrl$endpoint')); + + if (response.statusCode == 200) { + List jsonResponse = json.decode(response.body); + return jsonResponse.map((item) => fromJson(item)).toList(); + } else { + throw Exception('Failed to load data'); + } + } catch (e) { + throw Exception('Failed to load data: $e'); } } -} \ No newline at end of file +} diff --git a/frontend/app_student/lib/config/dev_config.dart b/frontend/app_student/lib/config/dev_config.dart index f608044..af2b236 100644 --- a/frontend/app_student/lib/config/dev_config.dart +++ b/frontend/app_student/lib/config/dev_config.dart @@ -2,5 +2,5 @@ import 'config.dart'; class DevConfig extends Config { @override - String get apiUrl => 'http://10.0.2.2:8000'; + String get apiUrl => 'https://api-dev.lukasvalois.com'; } 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 index 6fdec0b..40eb95d 100644 --- a/frontend/app_student/lib/day_schedules/bloc/day_schedule_bloc.dart +++ b/frontend/app_student/lib/day_schedules/bloc/day_schedule_bloc.dart @@ -9,7 +9,10 @@ class DayScheduleBloc { Stream> get dayScheduleStream => _dayScheduleController.stream; - DayScheduleBloc({required this.dayScheduleRepository}); + 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); diff --git a/frontend/app_student/lib/main_prod.dart b/frontend/app_student/lib/main_prod.dart index 6c4c9b6..c0adc91 100644 --- a/frontend/app_student/lib/main_prod.dart +++ b/frontend/app_student/lib/main_prod.dart @@ -28,6 +28,7 @@ class MyApp extends StatelessWidget { dayScheduleRepository: DayScheduleRepository( apiService: apiService, className: 'B3%20Groupe%203%20DLW-FA')); + return MaterialApp( title: 'Class List', theme: ThemeData(