From 63aa00c4436af6b7e99da8d68af59ae9ee60d0d4 Mon Sep 17 00:00:00 2001 From: HenriqueSFernandes Date: Sat, 16 Nov 2024 16:00:55 +0000 Subject: [PATCH 01/15] feat: added up_menus dependency --- packages/uni_app/pubspec.lock | 16 ++++++++++++++++ packages/uni_app/pubspec.yaml | 1 + 2 files changed, 17 insertions(+) diff --git a/packages/uni_app/pubspec.lock b/packages/uni_app/pubspec.lock index 04778b73c..1f8db98e1 100644 --- a/packages/uni_app/pubspec.lock +++ b/packages/uni_app/pubspec.lock @@ -1147,6 +1147,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.28.0" + scrollable_positioned_list: + dependency: transitive + description: + name: scrollable_positioned_list + sha256: "1b54d5f1329a1e263269abc9e2543d90806131aa14fe7c6062a8054d57249287" + url: "https://pub.dev" + source: hosted + version: "0.3.8" sentry: dependency: transitive description: @@ -1511,6 +1519,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.2.2" + up_menus: + dependency: "direct main" + description: + name: up_menus + sha256: b973555072c6056b757f2740cf7c10fc190ff7f7cd3df3f26c303faf261ce112 + url: "https://pub.dev" + source: hosted + version: "1.0.1" upgrader: dependency: "direct main" description: diff --git a/packages/uni_app/pubspec.yaml b/packages/uni_app/pubspec.yaml index 7c5d3d057..29f7c0f3a 100644 --- a/packages/uni_app/pubspec.yaml +++ b/packages/uni_app/pubspec.yaml @@ -69,6 +69,7 @@ dependencies: ua_client_hints: ^1.3.1 uni_ui: path: ../uni_ui + up_menus: ^1.0.1 upgrader: ^10.3.0 url_launcher: ^6.2.2 workmanager: ^0.5.2 From 9e8f5c093eca2a5b7c3195a0da27238a8e8c2c3d Mon Sep 17 00:00:00 2001 From: HenriqueSFernandes Date: Sat, 16 Nov 2024 20:13:16 +0000 Subject: [PATCH 02/15] feat: Updated day of the week parser to include datetime --- .../uni_app/lib/model/utils/day_of_week.dart | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/uni_app/lib/model/utils/day_of_week.dart b/packages/uni_app/lib/model/utils/day_of_week.dart index 77f78d9d3..579c4e991 100644 --- a/packages/uni_app/lib/model/utils/day_of_week.dart +++ b/packages/uni_app/lib/model/utils/day_of_week.dart @@ -8,6 +8,28 @@ enum DayOfWeek { sunday } +DayOfWeek parseDateTime(DateTime dateTime) { + final weekDay = dateTime.weekday; + switch (weekDay) { + case DateTime.monday: + return DayOfWeek.monday; + case DateTime.tuesday: + return DayOfWeek.tuesday; + case DateTime.wednesday: + return DayOfWeek.wednesday; + case DateTime.thursday: + return DayOfWeek.thursday; + case DateTime.friday: + return DayOfWeek.friday; + case DateTime.saturday: + return DayOfWeek.saturday; + case DateTime.sunday: + return DayOfWeek.sunday; + default: + throw Exception('Invalid day of week'); + } +} + DayOfWeek? parseDayOfWeek(String str) { final weekDay = str.replaceAll(' ', '').toLowerCase(); if (weekDay == 'segunda-feira') { From ece6d191d08046b2ea91e9817bba1f8689e162da Mon Sep 17 00:00:00 2001 From: HenriqueSFernandes Date: Sat, 16 Nov 2024 20:16:35 +0000 Subject: [PATCH 03/15] partially implemented new restaurants api Co-authored-by: AugustoVSoares --- .../fetchers/restaurant_fetcher.dart | 86 ++++++++++++++++++- .../providers/lazy/restaurant_provider.dart | 16 +++- 2 files changed, 96 insertions(+), 6 deletions(-) diff --git a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart index 979759046..6569f471b 100644 --- a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart +++ b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart @@ -1,7 +1,12 @@ +import 'dart:convert'; + import 'package:uni/controller/networking/network_router.dart'; import 'package:uni/controller/parsers/parser_restaurants.dart'; +import 'package:uni/model/entities/meal.dart'; import 'package:uni/model/entities/restaurant.dart'; +import 'package:uni/model/utils/day_of_week.dart'; import 'package:uni/session/flows/base/session.dart'; +import 'package:up_menus/up_menus.dart'; /// Class for fetching the menu class RestaurantFetcher { @@ -16,6 +21,22 @@ class RestaurantFetcher { // List the Restaurant sheet names in the Google Sheets Document final List restaurantSheets = ['Cantina']; + // TODO: remove later + void printRestaurants(List restaurants) { + for (final restaurant in restaurants) { + print(restaurant.id); + print(restaurant.name); + print(restaurant.reference); + final meals = restaurant.meals; + meals.forEach((day, mealList) { + print(day); + for (final meal in mealList) { + print(' - ${meal.name}'); + } + }); + } + } + // Generate the Gsheets endpoints list based on a list of sheets String buildGSheetsEndpoint(String sheet) { return Uri.encodeFull( @@ -44,6 +65,65 @@ class RestaurantFetcher { ); } + Future> getSASUPRestaurants() async { + // TODO: change to accomodate changes for the new UI. + final upMenus = UPMenusApi(); + final establishments = await upMenus.establishments.list(); + final restaurants = []; + + final icbas = await upMenus.establishments.get(4); + print(icbas.toJson()); + + print("74"); + // For every establishement... + for (final establishment in establishments) { + // Get the menu for the current week + if (establishment.dayMenu == false) continue; + final dayMenus = + (await upMenus.dayMenus.get(establishment.id, Period.lunch)) + .followedBy( + await upMenus.dayMenus.get(establishment.id, Period.dinner), + ) + .followedBy( + await upMenus.dayMenus.get(establishment.id, Period.snackBar), + ) + .followedBy( + await upMenus.dayMenus.get(establishment.id, Period.breakfast), + ); + print("89"); + print("${establishment.namePt} id: ${establishment.id}"); + final meals = []; + // For every day... + print("93"); + for (final dayMenu in dayMenus) { + print("94"); + // And for every dish... + for (final dish in dayMenu.dishes) { + // Extract the information about the meal. + print("96"); + meals.add( + Meal( + dish.dishType.namePt, + dish.dish.namePt, + parseDateTime(dayMenu.day), + dayMenu.day, + ), + ); + } + } + print("110"); + + restaurants.add( + Restaurant(establishment.id, establishment.namePt, '', meals: meals), + ); + print("115"); + printRestaurants(restaurants); + } + print("hereee"); + print(restaurants); + return restaurants; + } + final List sigarraMenuEndpoints = [ '${NetworkRouter.getBaseUrl('feup')}CANTINA.EMENTASHOW', ]; @@ -64,7 +144,9 @@ class RestaurantFetcher { } Future> getRestaurants(Session session) async { - final restaurants = await fetchSigarraRestaurants(session); + final restaurants = await getSASUPRestaurants(); + print(restaurants); + // final restaurants = await fetchSigarraRestaurants(session); // Check for restaurants without associated meals and attempt to parse them // from GSheets @@ -90,7 +172,7 @@ class RestaurantFetcher { ) ..insert(0, gSheetsRestaurant); } - + // printRestaurants(restaurants); return restaurants; } } diff --git a/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart b/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart index f6f9599f7..258633ae2 100644 --- a/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart +++ b/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart @@ -9,13 +9,20 @@ import 'package:uni/model/providers/state_providers.dart'; class RestaurantProvider extends StateProviderNotifier> { RestaurantProvider() : super(cacheDuration: const Duration(days: 1)); + // @override + // Future> loadFromStorage( + // StateProviders stateProviders, + // ) async { + // final restaurantDb = RestaurantDatabase(); + // final restaurants = await restaurantDb.getRestaurants(); + // return restaurants; + // } + @override Future> loadFromStorage( StateProviders stateProviders, ) async { - final restaurantDb = RestaurantDatabase(); - final restaurants = await restaurantDb.getRestaurants(); - return restaurants; + return loadFromRemote(stateProviders); } @override @@ -26,6 +33,7 @@ class RestaurantProvider extends StateProviderNotifier> { final db = RestaurantDatabase(); unawaited(db.saveIfPersistentSession(restaurants)); - return filterPastMeals(restaurants); + // return filterPastMeals(restaurants); + return restaurants; } } From bdc94974da6c12ad8efc2014510f98db9f174ad6 Mon Sep 17 00:00:00 2001 From: HenriqueSFernandes Date: Mon, 18 Nov 2024 17:59:10 +0000 Subject: [PATCH 04/15] refactor: removed GSheets fetching logic --- .../fetchers/restaurant_fetcher.dart | 135 +++++------------- 1 file changed, 38 insertions(+), 97 deletions(-) diff --git a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart index 6569f471b..552037ea8 100644 --- a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart +++ b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart @@ -1,5 +1,3 @@ -import 'dart:convert'; - import 'package:uni/controller/networking/network_router.dart'; import 'package:uni/controller/parsers/parser_restaurants.dart'; import 'package:uni/model/entities/meal.dart'; @@ -10,17 +8,6 @@ import 'package:up_menus/up_menus.dart'; /// Class for fetching the menu class RestaurantFetcher { - final String spreadSheetUrl = 'https://docs.google.com/spreadsheets/d/' - '1TJauM0HwIf2RauQU2GmhdZZ1ZicFLMHuBkxWwVOw3Q4'; - final String jsonEndpoint = '/gviz/tq?tqx=out:json'; - - // Format: Date(dd/mm/yyyy), Meal("Almoço", "Jantar), Dish("Sopa", "Carne", - // "Peixe", "Dieta", "Vegetariano", "Salada"), Description(String) - final String sheetsColumnRange = 'A:D'; - - // List the Restaurant sheet names in the Google Sheets Document - final List restaurantSheets = ['Cantina']; - // TODO: remove later void printRestaurants(List restaurants) { for (final restaurant in restaurants) { @@ -37,90 +24,69 @@ class RestaurantFetcher { } } - // Generate the Gsheets endpoints list based on a list of sheets - String buildGSheetsEndpoint(String sheet) { - return Uri.encodeFull( - '$spreadSheetUrl$jsonEndpoint&sheet=$sheet&range=$sheetsColumnRange', - ); - } - - String getRestaurantGSheetName(Restaurant restaurant) { - return restaurantSheets.firstWhere( - (sheetName) => - restaurant.name.toLowerCase().contains(sheetName.toLowerCase()), - orElse: () => '', - ); - } - - Future fetchGSheetsRestaurant( - String url, - String restaurantName, - Session session, { - bool isDinner = false, - }) async { - return getRestaurantFromGSheets( - await NetworkRouter.getWithCookies(url, {}, session), - restaurantName, - isDinner: isDinner, - ); - } - Future> getSASUPRestaurants() async { - // TODO: change to accomodate changes for the new UI. + // TODO: change the implementation to accomodate changes for the new UI. final upMenus = UPMenusApi(); final establishments = await upMenus.establishments.list(); final restaurants = []; - final icbas = await upMenus.establishments.get(4); - print(icbas.toJson()); - - print("74"); // For every establishement... for (final establishment in establishments) { // Get the menu for the current week - if (establishment.dayMenu == false) continue; - final dayMenus = - (await upMenus.dayMenus.get(establishment.id, Period.lunch)) - .followedBy( - await upMenus.dayMenus.get(establishment.id, Period.dinner), - ) - .followedBy( - await upMenus.dayMenus.get(establishment.id, Period.snackBar), - ) - .followedBy( - await upMenus.dayMenus.get(establishment.id, Period.breakfast), - ); - print("89"); - print("${establishment.namePt} id: ${establishment.id}"); + if (establishment.dayMenu == false) { + continue; + } + // HACK: hardcoded week number, because SASUP hasn't published the menus for the current week. + final dayMenus = (await upMenus.dayMenus + .get(establishment.id, Period.lunch, weekNumber: 40, year: 2024)) + .followedBy( + await upMenus.dayMenus.get( + establishment.id, + Period.dinner, + weekNumber: 40, + year: 2024, + ), + ) + .followedBy( + await upMenus.dayMenus.get( + establishment.id, + Period.snackBar, + weekNumber: 40, + year: 2024, + ), + ) + .followedBy( + await upMenus.dayMenus.get( + establishment.id, + Period.breakfast, + weekNumber: 40, + year: 2024, + ), + ); final meals = []; // For every day... - print("93"); for (final dayMenu in dayMenus) { - print("94"); // And for every dish... for (final dish in dayMenu.dishes) { // Extract the information about the meal. - print("96"); meals.add( Meal( dish.dishType.namePt, dish.dish.namePt, - parseDateTime(dayMenu.day), - dayMenu.day, + DayOfWeek.monday, + dayMenu.day.weekday == DateTime.monday + ? DateTime.now() + : dayMenu.day, ), ); } } - print("110"); restaurants.add( Restaurant(establishment.id, establishment.namePt, '', meals: meals), ); - print("115"); printRestaurants(restaurants); } - print("hereee"); - print(restaurants); return restaurants; } @@ -144,35 +110,10 @@ class RestaurantFetcher { } Future> getRestaurants(Session session) async { - final restaurants = await getSASUPRestaurants(); - print(restaurants); - // final restaurants = await fetchSigarraRestaurants(session); - - // Check for restaurants without associated meals and attempt to parse them - // from GSheets - final restaurantsWithoutMeals = - restaurants.where((restaurant) => restaurant.meals.isEmpty).toList(); + final restaurants = + await getSASUPRestaurants() + await fetchSigarraRestaurants(session); - for (final restaurant in restaurantsWithoutMeals) { - final sheetName = getRestaurantGSheetName(restaurant); - if (sheetName.isEmpty) { - continue; - } - - final gSheetsRestaurant = await fetchGSheetsRestaurant( - buildGSheetsEndpoint(sheetName), - restaurant.name, - session, - isDinner: restaurant.name.toLowerCase().contains('jantar'), - ); - - restaurants - ..removeWhere( - (restaurant) => restaurant.name == gSheetsRestaurant.name, - ) - ..insert(0, gSheetsRestaurant); - } - // printRestaurants(restaurants); + printRestaurants(restaurants); return restaurants; } } From 2f4d9dde52ea04dd528a4c99a90b97972ef3ca06 Mon Sep 17 00:00:00 2001 From: HenriqueSFernandes Date: Mon, 18 Nov 2024 18:20:32 +0000 Subject: [PATCH 05/15] refactor: removed debug prints --- .../fetchers/restaurant_fetcher.dart | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart index 552037ea8..96b103235 100644 --- a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart +++ b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart @@ -8,23 +8,23 @@ import 'package:up_menus/up_menus.dart'; /// Class for fetching the menu class RestaurantFetcher { - // TODO: remove later - void printRestaurants(List restaurants) { - for (final restaurant in restaurants) { - print(restaurant.id); - print(restaurant.name); - print(restaurant.reference); - final meals = restaurant.meals; - meals.forEach((day, mealList) { - print(day); - for (final meal in mealList) { - print(' - ${meal.name}'); - } - }); - } - } + // Auxliary function to print a list of restaurants. + // void printRestaurants(List restaurants) { + // for (final restaurant in restaurants) { + // print(restaurant.id); + // print(restaurant.name); + // print(restaurant.reference); + // final meals = restaurant.meals; + // meals.forEach((day, mealList) { + // print(day); + // for (final meal in mealList) { + // print(' - ${meal.name}'); + // } + // }); + // } + // } - Future> getSASUPRestaurants() async { + Future> fetchSASUPRestaurants() async { // TODO: change the implementation to accomodate changes for the new UI. final upMenus = UPMenusApi(); final establishments = await upMenus.establishments.list(); @@ -37,8 +37,12 @@ class RestaurantFetcher { continue; } // HACK: hardcoded week number, because SASUP hasn't published the menus for the current week. - final dayMenus = (await upMenus.dayMenus - .get(establishment.id, Period.lunch, weekNumber: 40, year: 2024)) + final dayMenus = (await upMenus.dayMenus.get( + establishment.id, + Period.lunch, + weekNumber: 40, + year: 2024, + )) .followedBy( await upMenus.dayMenus.get( establishment.id, @@ -73,10 +77,8 @@ class RestaurantFetcher { Meal( dish.dishType.namePt, dish.dish.namePt, - DayOfWeek.monday, - dayMenu.day.weekday == DateTime.monday - ? DateTime.now() - : dayMenu.day, + parseDateTime(dayMenu.day), + dayMenu.day, ), ); } @@ -85,7 +87,6 @@ class RestaurantFetcher { restaurants.add( Restaurant(establishment.id, establishment.namePt, '', meals: meals), ); - printRestaurants(restaurants); } return restaurants; } @@ -111,9 +112,8 @@ class RestaurantFetcher { Future> getRestaurants(Session session) async { final restaurants = - await getSASUPRestaurants() + await fetchSigarraRestaurants(session); + await fetchSASUPRestaurants() + await fetchSigarraRestaurants(session); - printRestaurants(restaurants); return restaurants; } } From 5b2568df41e1df265d79d6275de8837089e5c807 Mon Sep 17 00:00:00 2001 From: HenriqueSFernandes Date: Mon, 18 Nov 2024 18:41:00 +0000 Subject: [PATCH 06/15] refactor: disable past meals filtering temporarily --- .../database/app_restaurant_database.dart | 6 +++++- .../model/providers/lazy/restaurant_provider.dart | 15 +++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart b/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart index 70c15204f..045c19fed 100644 --- a/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart +++ b/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart @@ -70,7 +70,11 @@ class RestaurantDatabase extends AppDatabase> { } }); - return filterPastMeals(restaurants); + // TODO: reimplement the filter. + + // return filterPastMeals(restaurants); + + return restaurants; } Future> getRestaurantMeals( diff --git a/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart b/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart index 258633ae2..a4b70a388 100644 --- a/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart +++ b/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart @@ -9,20 +9,13 @@ import 'package:uni/model/providers/state_providers.dart'; class RestaurantProvider extends StateProviderNotifier> { RestaurantProvider() : super(cacheDuration: const Duration(days: 1)); - // @override - // Future> loadFromStorage( - // StateProviders stateProviders, - // ) async { - // final restaurantDb = RestaurantDatabase(); - // final restaurants = await restaurantDb.getRestaurants(); - // return restaurants; - // } - @override Future> loadFromStorage( StateProviders stateProviders, ) async { - return loadFromRemote(stateProviders); + final restaurantDb = RestaurantDatabase(); + final restaurants = await restaurantDb.getRestaurants(); + return restaurants; } @override @@ -33,6 +26,8 @@ class RestaurantProvider extends StateProviderNotifier> { final db = RestaurantDatabase(); unawaited(db.saveIfPersistentSession(restaurants)); + // TODO: enable past meals filtering after SASUP publishes the new menus (ALSO CHANGE IN THE STORAGE DATABASE!!!!). + // return filterPastMeals(restaurants); return restaurants; } From 72c189f1fe4120a8e5a78a295295f730bcd9a85c Mon Sep 17 00:00:00 2001 From: HenriqueSFernandes Date: Tue, 19 Nov 2024 14:25:32 +0000 Subject: [PATCH 07/15] =?UTF-8?q?fix:=20The=20new=20API=20uses=20"pescado"?= =?UTF-8?q?=20for=20fish=20and=20"hort=C3=ADcola"=20for=20salad,=20instead?= =?UTF-8?q?=20of=20"peixe"=20and=20"salada"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uni_app/lib/view/restaurant/widgets/restaurant_slot.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/uni_app/lib/view/restaurant/widgets/restaurant_slot.dart b/packages/uni_app/lib/view/restaurant/widgets/restaurant_slot.dart index f819ac36b..a4eee00ce 100644 --- a/packages/uni_app/lib/view/restaurant/widgets/restaurant_slot.dart +++ b/packages/uni_app/lib/view/restaurant/widgets/restaurant_slot.dart @@ -47,9 +47,11 @@ class RestaurantSlotType extends StatelessWidget { 'sopa': 'assets/meal-icons/soup.svg', 'carne': 'assets/meal-icons/chicken.svg', 'peixe': 'assets/meal-icons/fish.svg', + 'pescado': 'assets/meal-icons/fish.svg', 'dieta': 'assets/meal-icons/diet.svg', 'vegetariano': 'assets/meal-icons/vegetarian.svg', 'salada': 'assets/meal-icons/salad.svg', + 'hortícola': 'assets/meal-icons/salad.svg', }; @override From 9f1457ecc6565312ebba98eead4dee9c5593a427 Mon Sep 17 00:00:00 2001 From: HenriqueSFernandes Date: Sun, 1 Dec 2024 20:42:51 +0000 Subject: [PATCH 08/15] feat: removed restautant filtering function --- .../fetchers/restaurant_fetcher.dart | 34 +++++++++---------- .../database/app_restaurant_database.dart | 23 ------------- .../providers/lazy/restaurant_provider.dart | 5 ++- 3 files changed, 19 insertions(+), 43 deletions(-) diff --git a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart index 96b103235..0f8108045 100644 --- a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart +++ b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:uni/controller/networking/network_router.dart'; import 'package:uni/controller/parsers/parser_restaurants.dart'; import 'package:uni/model/entities/meal.dart'; @@ -9,20 +11,20 @@ import 'package:up_menus/up_menus.dart'; /// Class for fetching the menu class RestaurantFetcher { // Auxliary function to print a list of restaurants. - // void printRestaurants(List restaurants) { - // for (final restaurant in restaurants) { - // print(restaurant.id); - // print(restaurant.name); - // print(restaurant.reference); - // final meals = restaurant.meals; - // meals.forEach((day, mealList) { - // print(day); - // for (final meal in mealList) { - // print(' - ${meal.name}'); - // } - // }); - // } - // } + void printRestaurants(List restaurants) { + for (final restaurant in restaurants) { + print(restaurant.id); + print(restaurant.name); + print(restaurant.reference); + final meals = restaurant.meals; + meals.forEach((day, mealList) { + print(day); + for (final meal in mealList) { + print(' - ${meal.name}'); + } + }); + } + } Future> fetchSASUPRestaurants() async { // TODO: change the implementation to accomodate changes for the new UI. @@ -36,12 +38,9 @@ class RestaurantFetcher { if (establishment.dayMenu == false) { continue; } - // HACK: hardcoded week number, because SASUP hasn't published the menus for the current week. final dayMenus = (await upMenus.dayMenus.get( establishment.id, Period.lunch, - weekNumber: 40, - year: 2024, )) .followedBy( await upMenus.dayMenus.get( @@ -88,6 +87,7 @@ class RestaurantFetcher { Restaurant(establishment.id, establishment.namePt, '', meals: meals), ); } + printRestaurants(restaurants); return restaurants; } diff --git a/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart b/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart index 045c19fed..6661d78c6 100644 --- a/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart +++ b/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart @@ -70,10 +70,6 @@ class RestaurantDatabase extends AppDatabase> { } }); - // TODO: reimplement the filter. - - // return filterPastMeals(restaurants); - return restaurants; } @@ -133,22 +129,3 @@ class RestaurantDatabase extends AppDatabase> { }); } } - -List filterPastMeals(List restaurants) { - final restaurantsCopy = List.from(restaurants); - // Hide past and next weeks' meals - // (To replicate sigarra's behaviour for the GSheets meals) - final now = DateTime.now().toUtc(); - final today = DateTime.utc(now.year, now.month, now.day); - final nextSunday = today.add(Duration(days: DateTime.sunday - now.weekday)); - - for (final restaurant in restaurantsCopy) { - for (final meals in restaurant.meals.values) { - meals.removeWhere( - (meal) => meal.date.isBefore(today) || meal.date.isAfter(nextSunday), - ); - } - } - - return restaurantsCopy; -} diff --git a/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart b/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart index a4b70a388..0815ba8c2 100644 --- a/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart +++ b/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart @@ -13,6 +13,8 @@ class RestaurantProvider extends StateProviderNotifier> { Future> loadFromStorage( StateProviders stateProviders, ) async { + // TODO: remove this line after PR #1380 (fix: Added meals column to the RESTAURANTS table) is merged + return loadFromRemote(stateProviders); final restaurantDb = RestaurantDatabase(); final restaurants = await restaurantDb.getRestaurants(); return restaurants; @@ -26,9 +28,6 @@ class RestaurantProvider extends StateProviderNotifier> { final db = RestaurantDatabase(); unawaited(db.saveIfPersistentSession(restaurants)); - // TODO: enable past meals filtering after SASUP publishes the new menus (ALSO CHANGE IN THE STORAGE DATABASE!!!!). - - // return filterPastMeals(restaurants); return restaurants; } } From 3d021d8c0a1c6847de950276df36d4d54e527f0c Mon Sep 17 00:00:00 2001 From: HenriqueSFernandes Date: Sun, 1 Dec 2024 22:17:14 +0000 Subject: [PATCH 09/15] feat: Added suffix to distinguish lunch and dinner --- .../fetchers/restaurant_fetcher.dart | 96 +++++++++++-------- 1 file changed, 57 insertions(+), 39 deletions(-) diff --git a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart index 0f8108045..b1bdb04a1 100644 --- a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart +++ b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart @@ -26,68 +26,86 @@ class RestaurantFetcher { } } + Restaurant convertToRestaurant( + Establishment establishment, + Iterable dayMenus, + String period, + ) { + final meals = []; + for (final dayMenu in dayMenus) { + for (final dish in dayMenu.dishes) { + // Extract the information about the meal. + meals.add( + Meal( + dish.dishType.namePt, + dish.dish.namePt, + parseDateTime(dayMenu.day), + dayMenu.day, + ), + ); + } + } + return Restaurant( + establishment.id, + '${establishment.namePt} - $period', + '', + meals: meals, + ); + } + Future> fetchSASUPRestaurants() async { // TODO: change the implementation to accomodate changes for the new UI. final upMenus = UPMenusApi(); final establishments = await upMenus.establishments.list(); final restaurants = []; - // For every establishement... for (final establishment in establishments) { - // Get the menu for the current week if (establishment.dayMenu == false) { continue; } - final dayMenus = (await upMenus.dayMenus.get( - establishment.id, - Period.lunch, - )) - .followedBy( + + restaurants + ..add( + convertToRestaurant( + establishment, + await upMenus.dayMenus.get( + establishment.id, + Period.lunch, + ), + 'Almoço', + ), + ) + ..add( + convertToRestaurant( + establishment, await upMenus.dayMenus.get( establishment.id, Period.dinner, - weekNumber: 40, - year: 2024, ), - ) - .followedBy( + 'Jantar', + ), + ) + ..add( + convertToRestaurant( + establishment, await upMenus.dayMenus.get( establishment.id, Period.snackBar, - weekNumber: 40, - year: 2024, ), - ) - .followedBy( + 'Snackbar', + ), + ) + ..add( + convertToRestaurant( + establishment, await upMenus.dayMenus.get( establishment.id, Period.breakfast, - weekNumber: 40, - year: 2024, - ), - ); - final meals = []; - // For every day... - for (final dayMenu in dayMenus) { - // And for every dish... - for (final dish in dayMenu.dishes) { - // Extract the information about the meal. - meals.add( - Meal( - dish.dishType.namePt, - dish.dish.namePt, - parseDateTime(dayMenu.day), - dayMenu.day, ), - ); - } - } - - restaurants.add( - Restaurant(establishment.id, establishment.namePt, '', meals: meals), - ); + 'Pequeno Almoço', + ), + ); } - printRestaurants(restaurants); return restaurants; } From b08a26a214fbe2ed1dead92563dc49d665e15ab6 Mon Sep 17 00:00:00 2001 From: HenriqueSFernandes Date: Sun, 1 Dec 2024 22:25:25 +0000 Subject: [PATCH 10/15] refactor: removed dead code --- .../fetchers/restaurant_fetcher.dart | 18 ------------------ .../providers/lazy/restaurant_provider.dart | 6 +++--- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart index b1bdb04a1..c836c2389 100644 --- a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart +++ b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart @@ -1,5 +1,3 @@ -import 'dart:convert'; - import 'package:uni/controller/networking/network_router.dart'; import 'package:uni/controller/parsers/parser_restaurants.dart'; import 'package:uni/model/entities/meal.dart'; @@ -10,22 +8,6 @@ import 'package:up_menus/up_menus.dart'; /// Class for fetching the menu class RestaurantFetcher { - // Auxliary function to print a list of restaurants. - void printRestaurants(List restaurants) { - for (final restaurant in restaurants) { - print(restaurant.id); - print(restaurant.name); - print(restaurant.reference); - final meals = restaurant.meals; - meals.forEach((day, mealList) { - print(day); - for (final meal in mealList) { - print(' - ${meal.name}'); - } - }); - } - } - Restaurant convertToRestaurant( Establishment establishment, Iterable dayMenus, diff --git a/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart b/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart index 0815ba8c2..a422bfba6 100644 --- a/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart +++ b/packages/uni_app/lib/model/providers/lazy/restaurant_provider.dart @@ -15,9 +15,9 @@ class RestaurantProvider extends StateProviderNotifier> { ) async { // TODO: remove this line after PR #1380 (fix: Added meals column to the RESTAURANTS table) is merged return loadFromRemote(stateProviders); - final restaurantDb = RestaurantDatabase(); - final restaurants = await restaurantDb.getRestaurants(); - return restaurants; + // final restaurantDb = RestaurantDatabase(); + // final restaurants = await restaurantDb.getRestaurants(); + // return restaurants; } @override From 27fff36c9fb94a2c3371cc4350e9812519fc0b62 Mon Sep 17 00:00:00 2001 From: HenriqueSFernandes Date: Tue, 3 Dec 2024 17:50:43 +0000 Subject: [PATCH 11/15] feat: added restaurant period translation --- .../lib/generated/intl/messages_en.dart | 4 ++ .../lib/generated/intl/messages_pt_PT.dart | 4 ++ packages/uni_app/lib/generated/l10n.dart | 40 +++++++++++++++++++ packages/uni_app/lib/l10n/intl_en.arb | 10 ++++- packages/uni_app/lib/l10n/intl_pt_PT.arb | 10 ++++- 5 files changed, 66 insertions(+), 2 deletions(-) diff --git a/packages/uni_app/lib/generated/intl/messages_en.dart b/packages/uni_app/lib/generated/intl/messages_en.dart index 24826a3e3..29743e6aa 100644 --- a/packages/uni_app/lib/generated/intl/messages_en.dart +++ b/packages/uni_app/lib/generated/intl/messages_en.dart @@ -63,6 +63,7 @@ class MessageLookup extends MessageLookupByLibrary { "banner_info": MessageLookupByLibrary.simpleMessage( "We do now collect anonymous usage statistics in order to improve your experience. You can change it in settings."), "bibliography": MessageLookupByLibrary.simpleMessage("Bibliography"), + "breakfast": MessageLookupByLibrary.simpleMessage("Breakfast"), "bs_description": MessageLookupByLibrary.simpleMessage( "Did you find any bugs in the application?\nDo you have any suggestions for the app?\nTell us so we can improve!"), "bug_description": MessageLookupByLibrary.simpleMessage( @@ -110,6 +111,7 @@ class MessageLookup extends MessageLookupByLibrary { "description": MessageLookupByLibrary.simpleMessage("Description"), "desired_email": MessageLookupByLibrary.simpleMessage( "Email where you want to be contacted"), + "dinner": MessageLookupByLibrary.simpleMessage("Dinner"), "dona_bia": MessageLookupByLibrary.simpleMessage( "D. Beatriz\'s stationery store"), "dona_bia_building": MessageLookupByLibrary.simpleMessage( @@ -167,6 +169,7 @@ class MessageLookup extends MessageLookupByLibrary { "login_with_credentials": MessageLookupByLibrary.simpleMessage("Login with credentials"), "logout": MessageLookupByLibrary.simpleMessage("Log out"), + "lunch": MessageLookupByLibrary.simpleMessage("Lunch"), "menus": MessageLookupByLibrary.simpleMessage("Menus"), "min_value_reference": MessageLookupByLibrary.simpleMessage("Minimum value: 1,00 €"), @@ -272,6 +275,7 @@ class MessageLookup extends MessageLookupByLibrary { "sent_error": MessageLookupByLibrary.simpleMessage( "An error occurred in sending"), "settings": MessageLookupByLibrary.simpleMessage("Settings"), + "snackbar": MessageLookupByLibrary.simpleMessage("Snackbar"), "some_error": MessageLookupByLibrary.simpleMessage("Some error!"), "stcp_stops": MessageLookupByLibrary.simpleMessage("STCP - Upcoming Trips"), diff --git a/packages/uni_app/lib/generated/intl/messages_pt_PT.dart b/packages/uni_app/lib/generated/intl/messages_pt_PT.dart index 502e9f9ec..1aca84f19 100644 --- a/packages/uni_app/lib/generated/intl/messages_pt_PT.dart +++ b/packages/uni_app/lib/generated/intl/messages_pt_PT.dart @@ -63,6 +63,7 @@ class MessageLookup extends MessageLookupByLibrary { "banner_info": MessageLookupByLibrary.simpleMessage( "Agora recolhemos estatísticas de uso anónimas para melhorar a tua experiência. Podes alterá-lo nas definições."), "bibliography": MessageLookupByLibrary.simpleMessage("Bibliografia"), + "breakfast": MessageLookupByLibrary.simpleMessage("Pequeno Almoço"), "bs_description": MessageLookupByLibrary.simpleMessage( "Encontraste algum bug na aplicação?\nTens alguma sugestão para a app?\nConta-nos para que possamos melhorar!"), "bug_description": MessageLookupByLibrary.simpleMessage( @@ -109,6 +110,7 @@ class MessageLookup extends MessageLookupByLibrary { "description": MessageLookupByLibrary.simpleMessage("Descrição"), "desired_email": MessageLookupByLibrary.simpleMessage( "Email em que desejas ser contactado"), + "dinner": MessageLookupByLibrary.simpleMessage("Jantar"), "dona_bia": MessageLookupByLibrary.simpleMessage("Papelaria D. Beatriz"), "dona_bia_building": MessageLookupByLibrary.simpleMessage( @@ -166,6 +168,7 @@ class MessageLookup extends MessageLookupByLibrary { "login_with_credentials": MessageLookupByLibrary.simpleMessage( "Iniciar sessão com credenciais"), "logout": MessageLookupByLibrary.simpleMessage("Terminar sessão"), + "lunch": MessageLookupByLibrary.simpleMessage("Almoço"), "menus": MessageLookupByLibrary.simpleMessage("Ementas"), "min_value_reference": MessageLookupByLibrary.simpleMessage("Valor mínimo: 1,00 €"), @@ -273,6 +276,7 @@ class MessageLookup extends MessageLookupByLibrary { "sent_error": MessageLookupByLibrary.simpleMessage("Ocorreu um erro no envio"), "settings": MessageLookupByLibrary.simpleMessage("Definições"), + "snackbar": MessageLookupByLibrary.simpleMessage("Snackbar"), "some_error": MessageLookupByLibrary.simpleMessage("Algum erro!"), "stcp_stops": MessageLookupByLibrary.simpleMessage("STCP - Próximas Viagens"), diff --git a/packages/uni_app/lib/generated/l10n.dart b/packages/uni_app/lib/generated/l10n.dart index 4201d66c1..ee888da7f 100644 --- a/packages/uni_app/lib/generated/l10n.dart +++ b/packages/uni_app/lib/generated/l10n.dart @@ -260,6 +260,16 @@ class S { ); } + /// `Breakfast` + String get breakfast { + return Intl.message( + 'Breakfast', + name: 'breakfast', + desc: '', + args: [], + ); + } + /// `Did you find any bugs in the application?\nDo you have any suggestions for the app?\nTell us so we can improve!` String get bs_description { return Intl.message( @@ -530,6 +540,16 @@ class S { ); } + /// `Dinner` + String get dinner { + return Intl.message( + 'Dinner', + name: 'dinner', + desc: '', + args: [], + ); + } + /// `D. Beatriz's stationery store` String get dona_bia { return Intl.message( @@ -783,6 +803,16 @@ class S { ); } + /// `Lunch` + String get lunch { + return Intl.message( + 'Lunch', + name: 'lunch', + desc: '', + args: [], + ); + } + /// `Error downloading the file` String get download_error { return Intl.message( @@ -823,6 +853,16 @@ class S { ); } + /// `Snackbar` + String get snackbar { + return Intl.message( + 'Snackbar', + name: 'snackbar', + desc: '', + args: [], + ); + } + /// `Log out` String get logout { return Intl.message( diff --git a/packages/uni_app/lib/l10n/intl_en.arb b/packages/uni_app/lib/l10n/intl_en.arb index 5e3eb22a6..c0cb3ad19 100644 --- a/packages/uni_app/lib/l10n/intl_en.arb +++ b/packages/uni_app/lib/l10n/intl_en.arb @@ -42,6 +42,8 @@ "@balance": {}, "bibliography": "Bibliography", "@bibliography": {}, + "breakfast": "Breakfast", + "@breakfast": {}, "bs_description": "Did you find any bugs in the application?\nDo you have any suggestions for the app?\nTell us so we can improve!", "@bs_description": {}, "bug_description": "Bug found, how to reproduce it, etc.", @@ -96,6 +98,8 @@ "@description": {}, "desired_email": "Email where you want to be contacted", "@desired_email": {}, + "dinner": "Dinner", + "@dinner": {}, "dona_bia": "D. Beatriz's stationery store", "@dona_bia": {}, "dona_bia_building": "Floor -1 of building B (B-142)", @@ -154,6 +158,8 @@ }, "library_occupation": "Library Occupation", "@library_occupation": {}, + "lunch": "Lunch", + "@lunch": {}, "download_error": "Error downloading the file", "@download_error": {}, "loading_terms": "Loading Terms and Conditions...", @@ -162,6 +168,8 @@ "@login": {}, "settings": "Settings", "@settings": {}, + "snackbar": "Snackbar", + "@snackbar": {}, "logout": "Log out", "@logout": {}, "menus": "Menus", @@ -334,4 +342,4 @@ "@wrong_credentials_exception": {}, "internet_status_exception": "Check your internet connection", "@internet_status_exception": {} -} \ No newline at end of file +} diff --git a/packages/uni_app/lib/l10n/intl_pt_PT.arb b/packages/uni_app/lib/l10n/intl_pt_PT.arb index 4212fe69c..50eb23e8b 100644 --- a/packages/uni_app/lib/l10n/intl_pt_PT.arb +++ b/packages/uni_app/lib/l10n/intl_pt_PT.arb @@ -56,6 +56,8 @@ "@buses_text": {}, "bus_information": "Seleciona os autocarros dos quais queres informação:", "@bus_information": {}, + "breakfast": "Pequeno Almoço", + "@breakfast": {}, "cancel": "Cancelar", "@cancel": {}, "change": "Alterar", @@ -98,6 +100,8 @@ "@description": {}, "desired_email": "Email em que desejas ser contactado", "@desired_email": {}, + "dinner": "Jantar", + "@dinner": {}, "dona_bia": "Papelaria D. Beatriz", "@dona_bia": {}, "dona_bia_building": "Piso -1 do edifício B (B-142)", @@ -158,6 +162,8 @@ "@load_error": {}, "library_occupation": "Ocupação da Biblioteca", "@library_occupation": {}, + "lunch": "Almoço", + "@lunch": {}, "download_error": "Erro ao descarregar o ficheiro", "@download_error": {}, "successful_open": "Ficheiro aberto com sucesso", @@ -294,6 +300,8 @@ "@stcp_stops": {}, "student_number": "número de estudante", "@student_number": {}, + "snackbar": "Snackbar", + "@snackbar": {}, "success": "Enviado com sucesso", "@success": {}, "tele_assistance": "Atendimento telefónico", @@ -334,4 +342,4 @@ "@wrong_credentials_exception": {}, "internet_status_exception": "Verifique sua conexão com a internet", "@internet_status_exception": {} -} \ No newline at end of file +} From 07891264d8a377792112db562c7658dee09373db Mon Sep 17 00:00:00 2001 From: HenriqueSFernandes Date: Tue, 3 Dec 2024 17:55:26 +0000 Subject: [PATCH 12/15] feat: added period to restaurant model --- .../fetchers/restaurant_fetcher.dart | 11 ++--- .../database/app_restaurant_database.dart | 2 + .../parsers/parser_restaurants.dart | 45 +------------------ .../model/entities/restaurant.g.dart | 4 +- .../lib/model/entities/restaurant.dart | 5 ++- .../widgets/restaurant_page_card.dart | 13 +++++- 6 files changed, 28 insertions(+), 52 deletions(-) diff --git a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart index c836c2389..48c75979c 100644 --- a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart +++ b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart @@ -29,7 +29,8 @@ class RestaurantFetcher { } return Restaurant( establishment.id, - '${establishment.namePt} - $period', + establishment.namePt, + period, '', meals: meals, ); @@ -54,7 +55,7 @@ class RestaurantFetcher { establishment.id, Period.lunch, ), - 'Almoço', + 'lunch', ), ) ..add( @@ -64,7 +65,7 @@ class RestaurantFetcher { establishment.id, Period.dinner, ), - 'Jantar', + 'dinner', ), ) ..add( @@ -74,7 +75,7 @@ class RestaurantFetcher { establishment.id, Period.snackBar, ), - 'Snackbar', + 'snackbar', ), ) ..add( @@ -84,7 +85,7 @@ class RestaurantFetcher { establishment.id, Period.breakfast, ), - 'Pequeno Almoço', + 'breakfast', ), ); } diff --git a/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart b/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart index 6661d78c6..fc2ce8c3e 100644 --- a/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart +++ b/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart @@ -4,6 +4,7 @@ import 'package:uni/controller/local_storage/database/app_database.dart'; import 'package:uni/model/entities/meal.dart'; import 'package:uni/model/entities/restaurant.dart'; import 'package:uni/model/utils/day_of_week.dart'; +import 'package:up_menus/up_menus.dart'; class RestaurantDatabase extends AppDatabase> { RestaurantDatabase() @@ -46,6 +47,7 @@ class RestaurantDatabase extends AppDatabase> { return Restaurant( restaurantId, map['name'] as String, + map['period'] as String, map['ref'] as String, meals: meals, ); diff --git a/packages/uni_app/lib/controller/parsers/parser_restaurants.dart b/packages/uni_app/lib/controller/parsers/parser_restaurants.dart index a4c543f70..014a019bc 100644 --- a/packages/uni_app/lib/controller/parsers/parser_restaurants.dart +++ b/packages/uni_app/lib/controller/parsers/parser_restaurants.dart @@ -72,52 +72,9 @@ List getRestaurantsFromHtml(Response response) { null, restaurantTuple.item2, restaurantTuple.item1, + '', meals: meals, ); }).toList(); return restaurants; } - -Restaurant getRestaurantFromGSheets( - Response response, - String restaurantName, { - bool isDinner = false, -}) { - // Ignore beginning of response: "/*O_o*/\ngoogle.visualization.Query.setResponse(" - // Ignore the end of the response: ");" - // Check the structure by accessing the link: - // https://docs.google.com/spreadsheets/d/1TJauM0HwIf2RauQU2GmhdZZ1ZicFLMHuBkxWwVOw3Q4/gviz/tq?tqx=out:json&sheet=Cantina%20de%20Engenharia&range=A:D - final jsonString = response.body.substring( - response.body.indexOf('(') + 1, - response.body.lastIndexOf(')'), - ); - final parsedJson = jsonDecode(jsonString) as Map; - - final mealsList = []; - - final format = DateFormat('d/M/y'); - - final table = parsedJson['table'] as Map; - final rows = table['rows'] as List; - - for (final row in rows) { - final cellList = (row as Map)['c'] as List; - if (((cellList[1] as Map)['v'] == 'Almoço' && isDinner) || - ((cellList[1] as Map)['v'] != 'Almoço' && !isDinner)) { - continue; - } - - final meal = Meal( - (cellList[2] as Map)['v'] as String, - (cellList[3] as Map)['v'] as String, - DayOfWeek.values[format - .parseUtc((cellList[0] as Map)['f'] as String) - .weekday - - 1], - format.parseUtc((cellList[0] as Map)['f'] as String), - ); - mealsList.add(meal); - } - - return Restaurant(null, restaurantName, '', meals: mealsList); -} diff --git a/packages/uni_app/lib/generated/model/entities/restaurant.g.dart b/packages/uni_app/lib/generated/model/entities/restaurant.g.dart index 5471eb4f0..11cc0e78c 100644 --- a/packages/uni_app/lib/generated/model/entities/restaurant.g.dart +++ b/packages/uni_app/lib/generated/model/entities/restaurant.g.dart @@ -7,8 +7,9 @@ part of '../../../model/entities/restaurant.dart'; // ************************************************************************** Restaurant _$RestaurantFromJson(Map json) => Restaurant( - json['id'] as int?, + (json['id'] as num?)?.toInt(), json['name'] as String, + json['period'] as String, json['ref'] as String, meals: (json['meals'] as List) .map((e) => Meal.fromJson(e as Map)) @@ -19,6 +20,7 @@ Map _$RestaurantToJson(Restaurant instance) => { 'id': instance.id, 'name': instance.name, + 'period': instance.period, 'ref': instance.reference, 'meals': instance.meals.map((k, e) => MapEntry(_$DayOfWeekEnumMap[k]!, e)), diff --git a/packages/uni_app/lib/model/entities/restaurant.dart b/packages/uni_app/lib/model/entities/restaurant.dart index 74ef474cc..7383e6e45 100644 --- a/packages/uni_app/lib/model/entities/restaurant.dart +++ b/packages/uni_app/lib/model/entities/restaurant.dart @@ -7,7 +7,8 @@ part '../../generated/model/entities/restaurant.g.dart'; @JsonSerializable() class Restaurant { - Restaurant(this.id, this.name, this.reference, {required List meals}) + Restaurant(this.id, this.name, this.period, this.reference, + {required List meals}) : meals = groupBy(meals, (meal) => meal.dayOfWeek); factory Restaurant.fromMap(Map map, List meals) { @@ -22,6 +23,8 @@ class Restaurant { final int? id; @JsonKey(name: 'name') final String name; + @JsonKey(name: 'period') + final String period; @JsonKey(name: 'ref') final String reference; // Used only in html parser @JsonKey(includeToJson: true) diff --git a/packages/uni_app/lib/view/restaurant/widgets/restaurant_page_card.dart b/packages/uni_app/lib/view/restaurant/widgets/restaurant_page_card.dart index cd6e7852a..c3f4dae1a 100644 --- a/packages/uni_app/lib/view/restaurant/widgets/restaurant_page_card.dart +++ b/packages/uni_app/lib/view/restaurant/widgets/restaurant_page_card.dart @@ -24,7 +24,18 @@ class RestaurantPageCard extends GenericCard { @override String getTitle(BuildContext context) { - return restaurant.name; + switch (restaurant.period) { + case 'lunch': + return '${restaurant.name} - ${S.of(context).lunch}'; + case 'dinner': + return '${restaurant.name} - ${S.of(context).dinner}'; + case 'breakfast': + return '${restaurant.name} - ${S.of(context).breakfast}'; + case 'snackbar': + return '${restaurant.name} - ${S.of(context).snackbar}'; + default: + return restaurant.name; + } } @override From 748e3df60cc9e33ad7f5a9537fb9f63e540de5e4 Mon Sep 17 00:00:00 2001 From: HenriqueSFernandes Date: Tue, 3 Dec 2024 18:24:22 +0000 Subject: [PATCH 13/15] fix: fixed period on favourite restaurants --- .../lib/view/home/widgets/restaurant_card.dart | 17 +++++++++++++++-- .../widgets/restaurant_page_card.dart | 11 +++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/uni_app/lib/view/home/widgets/restaurant_card.dart b/packages/uni_app/lib/view/home/widgets/restaurant_card.dart index 65007f82d..550ca2f42 100644 --- a/packages/uni_app/lib/view/home/widgets/restaurant_card.dart +++ b/packages/uni_app/lib/view/home/widgets/restaurant_card.dart @@ -41,7 +41,7 @@ class RestaurantCard extends GenericCard { final favoriteRestaurants = restaurants .where( (restaurant) => PreferencesController.getFavoriteRestaurants() - .contains(restaurant.name), + .contains(restaurant.name + restaurant.period), ) .toList(); return generateRestaurants(favoriteRestaurants, context); @@ -117,6 +117,19 @@ class RestaurantCard extends GenericCard { DayOfWeek day, ) { final meals = restaurant.getMealsOfDay(day); + var period = ''; + switch (restaurant.period) { + case 'lunch': + period = S.of(context).lunch; + case 'dinner': + period = S.of(context).dinner; + case 'breakfast': + period = S.of(context).breakfast; + case 'snackbar': + period = S.of(context).snackbar; + default: + period = ''; + } return Column( children: [ Center( @@ -124,7 +137,7 @@ class RestaurantCard extends GenericCard { alignment: Alignment.centerLeft, padding: const EdgeInsets.fromLTRB(10, 15, 5, 10), child: Text( - restaurant.name, + '${restaurant.name} - $period', style: TextStyle( fontSize: 16, color: Theme.of(context).primaryColor, diff --git a/packages/uni_app/lib/view/restaurant/widgets/restaurant_page_card.dart b/packages/uni_app/lib/view/restaurant/widgets/restaurant_page_card.dart index c3f4dae1a..7df81063b 100644 --- a/packages/uni_app/lib/view/restaurant/widgets/restaurant_page_card.dart +++ b/packages/uni_app/lib/view/restaurant/widgets/restaurant_page_card.dart @@ -63,7 +63,7 @@ class CardFavoriteButtonState extends State { void initState() { super.initState(); isFavorite = PreferencesController.getFavoriteRestaurants() - .contains(widget.restaurant.name); + .contains(widget.restaurant.name + widget.restaurant.period); } @override @@ -73,10 +73,13 @@ class CardFavoriteButtonState extends State { onPressed: () async { final favoriteRestaurants = PreferencesController.getFavoriteRestaurants(); - if (favoriteRestaurants.contains(widget.restaurant.name)) { - favoriteRestaurants.remove(widget.restaurant.name); + if (favoriteRestaurants + .contains(widget.restaurant.name + widget.restaurant.period)) { + favoriteRestaurants + .remove(widget.restaurant.name + widget.restaurant.period); } else { - favoriteRestaurants.add(widget.restaurant.name); + favoriteRestaurants + .add(widget.restaurant.name + widget.restaurant.period); } setState(() { From 9d62d9ef04b917e7d25d633193e0aa9944a41f58 Mon Sep 17 00:00:00 2001 From: HenriqueSFernandes Date: Tue, 3 Dec 2024 19:03:02 +0000 Subject: [PATCH 14/15] refactor: simplified restaurant fetcher --- .../fetchers/restaurant_fetcher.dart | 50 +++++-------------- .../database/app_restaurant_database.dart | 1 - .../parsers/parser_restaurants.dart | 2 - .../lib/model/entities/restaurant.dart | 10 ++-- 4 files changed, 20 insertions(+), 43 deletions(-) diff --git a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart index 48c75979c..717bcb55b 100644 --- a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart +++ b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart @@ -42,52 +42,28 @@ class RestaurantFetcher { final establishments = await upMenus.establishments.list(); final restaurants = []; + const periods = [ + {'period': Period.lunch, 'meal': 'lunch'}, + {'period': Period.dinner, 'meal': 'dinner'}, + {'period': Period.snackBar, 'meal': 'snackbar'}, + {'period': Period.breakfast, 'meal': 'breakfast'}, + ]; + for (final establishment in establishments) { if (establishment.dayMenu == false) { continue; } - restaurants - ..add( - convertToRestaurant( - establishment, - await upMenus.dayMenus.get( - establishment.id, - Period.lunch, - ), - 'lunch', - ), - ) - ..add( + for (final period in periods) { + restaurants.add( convertToRestaurant( establishment, - await upMenus.dayMenus.get( - establishment.id, - Period.dinner, - ), - 'dinner', - ), - ) - ..add( - convertToRestaurant( - establishment, - await upMenus.dayMenus.get( - establishment.id, - Period.snackBar, - ), - 'snackbar', - ), - ) - ..add( - convertToRestaurant( - establishment, - await upMenus.dayMenus.get( - establishment.id, - Period.breakfast, - ), - 'breakfast', + await upMenus.dayMenus + .get(establishment.id, period['period']! as Period), + period['meal']! as String, ), ); + } } return restaurants; } diff --git a/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart b/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart index fc2ce8c3e..e7188c932 100644 --- a/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart +++ b/packages/uni_app/lib/controller/local_storage/database/app_restaurant_database.dart @@ -4,7 +4,6 @@ import 'package:uni/controller/local_storage/database/app_database.dart'; import 'package:uni/model/entities/meal.dart'; import 'package:uni/model/entities/restaurant.dart'; import 'package:uni/model/utils/day_of_week.dart'; -import 'package:up_menus/up_menus.dart'; class RestaurantDatabase extends AppDatabase> { RestaurantDatabase() diff --git a/packages/uni_app/lib/controller/parsers/parser_restaurants.dart b/packages/uni_app/lib/controller/parsers/parser_restaurants.dart index 014a019bc..bbe94e3df 100644 --- a/packages/uni_app/lib/controller/parsers/parser_restaurants.dart +++ b/packages/uni_app/lib/controller/parsers/parser_restaurants.dart @@ -1,5 +1,3 @@ -import 'dart:convert'; - import 'package:html/parser.dart'; import 'package:http/http.dart'; import 'package:intl/intl.dart'; diff --git a/packages/uni_app/lib/model/entities/restaurant.dart b/packages/uni_app/lib/model/entities/restaurant.dart index 7383e6e45..190b6f565 100644 --- a/packages/uni_app/lib/model/entities/restaurant.dart +++ b/packages/uni_app/lib/model/entities/restaurant.dart @@ -7,9 +7,13 @@ part '../../generated/model/entities/restaurant.g.dart'; @JsonSerializable() class Restaurant { - Restaurant(this.id, this.name, this.period, this.reference, - {required List meals}) - : meals = groupBy(meals, (meal) => meal.dayOfWeek); + Restaurant( + this.id, + this.name, + this.period, + this.reference, { + required List meals, + }) : meals = groupBy(meals, (meal) => meal.dayOfWeek); factory Restaurant.fromMap(Map map, List meals) { final object = Restaurant.fromJson(map); From af50845b241b5f553a1a2305ff3bc530d013cf11 Mon Sep 17 00:00:00 2001 From: HenriqueSFernandes Date: Wed, 4 Dec 2024 00:34:46 +0000 Subject: [PATCH 15/15] feat: added english translation to meals --- .../lib/controller/fetchers/restaurant_fetcher.dart | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart index 717bcb55b..c7cc0d20c 100644 --- a/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart +++ b/packages/uni_app/lib/controller/fetchers/restaurant_fetcher.dart @@ -1,3 +1,4 @@ +import 'package:intl/intl.dart'; import 'package:uni/controller/networking/network_router.dart'; import 'package:uni/controller/parsers/parser_restaurants.dart'; import 'package:uni/model/entities/meal.dart'; @@ -13,6 +14,8 @@ class RestaurantFetcher { Iterable dayMenus, String period, ) { + final currentLocale = Intl.getCurrentLocale(); + final meals = []; for (final dayMenu in dayMenus) { for (final dish in dayMenu.dishes) { @@ -20,7 +23,11 @@ class RestaurantFetcher { meals.add( Meal( dish.dishType.namePt, - dish.dish.namePt, + currentLocale.startsWith('pt') + ? dish.dish.namePt + : dish.dish.nameEn ?? + dish.dish + .namePt, // if there isn't an english name, use the portuguese one. parseDateTime(dayMenu.day), dayMenu.day, ), @@ -29,7 +36,9 @@ class RestaurantFetcher { } return Restaurant( establishment.id, - establishment.namePt, + currentLocale.startsWith('pt') + ? establishment.namePt + : establishment.nameEn, period, '', meals: meals,