diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 4b41fbe..bdf93c6 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"audio_session","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\audio_session-0.1.13\\\\","native_build":true,"dependencies":[]},{"name":"flutter_beacon","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_beacon-0.5.1\\\\","native_build":true,"dependencies":[]},{"name":"just_audio","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\just_audio-0.9.31\\\\","native_build":true,"dependencies":["audio_session"]},{"name":"path_provider_foundation","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.1.1\\\\","native_build":true,"dependencies":[]},{"name":"permission_handler","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler-8.3.0\\\\","native_build":true,"dependencies":[]},{"name":"qr_code_scanner","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\qr_code_scanner-1.0.1\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sqflite-2.2.4+1\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"audio_session","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\audio_session-0.1.13\\\\","native_build":true,"dependencies":[]},{"name":"flutter_beacon","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_beacon-0.5.1\\\\","native_build":true,"dependencies":[]},{"name":"just_audio","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\just_audio-0.9.31\\\\","native_build":true,"dependencies":["audio_session"]},{"name":"path_provider_android","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.0.22\\\\","native_build":true,"dependencies":[]},{"name":"permission_handler","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler-8.3.0\\\\","native_build":true,"dependencies":[]},{"name":"qr_code_scanner","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\qr_code_scanner-1.0.1\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sqflite-2.2.4+1\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"audio_session","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\audio_session-0.1.13\\\\","native_build":true,"dependencies":[]},{"name":"just_audio","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\just_audio-0.9.31\\\\","native_build":true,"dependencies":["audio_session"]},{"name":"path_provider_foundation","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.1.1\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sqflite-2.2.4+1\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.1.7\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.1.3\\\\","native_build":false,"dependencies":[]}],"web":[{"name":"audio_session","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\audio_session-0.1.13\\\\","dependencies":[]},{"name":"just_audio_web","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\just_audio_web-0.4.7\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"audio_session","dependencies":[]},{"name":"flutter_beacon","dependencies":[]},{"name":"just_audio","dependencies":["just_audio_web","audio_session","path_provider"]},{"name":"just_audio_web","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"qr_code_scanner","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2023-01-28 02:26:08.187656","version":"3.7.0"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"audio_session","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\audio_session-0.1.13\\\\","native_build":true,"dependencies":[]},{"name":"flutter_beacon","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_beacon-0.5.1\\\\","native_build":true,"dependencies":[]},{"name":"just_audio","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\just_audio-0.9.31\\\\","native_build":true,"dependencies":["audio_session"]},{"name":"path_provider_foundation","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.1.1\\\\","native_build":true,"dependencies":[]},{"name":"permission_handler","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler-8.3.0\\\\","native_build":true,"dependencies":[]},{"name":"qr_code_scanner","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\qr_code_scanner-1.0.1\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sqflite-2.2.4+1\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"audio_session","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\audio_session-0.1.13\\\\","native_build":true,"dependencies":[]},{"name":"flutter_beacon","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\flutter_beacon-0.5.1\\\\","native_build":true,"dependencies":[]},{"name":"just_audio","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\just_audio-0.9.31\\\\","native_build":true,"dependencies":["audio_session"]},{"name":"path_provider_android","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.0.22\\\\","native_build":true,"dependencies":[]},{"name":"permission_handler","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler-8.3.0\\\\","native_build":true,"dependencies":[]},{"name":"qr_code_scanner","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\qr_code_scanner-1.0.1\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sqflite-2.2.4+1\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"audio_session","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\audio_session-0.1.13\\\\","native_build":true,"dependencies":[]},{"name":"just_audio","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\just_audio-0.9.31\\\\","native_build":true,"dependencies":["audio_session"]},{"name":"path_provider_foundation","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.1.1\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sqflite-2.2.4+1\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.1.7\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.1.3\\\\","native_build":false,"dependencies":[]}],"web":[{"name":"audio_session","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\audio_session-0.1.13\\\\","dependencies":[]},{"name":"just_audio_web","path":"C:\\\\Users\\\\thoma\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\just_audio_web-0.4.7\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"audio_session","dependencies":[]},{"name":"flutter_beacon","dependencies":[]},{"name":"just_audio","dependencies":["just_audio_web","audio_session","path_provider"]},{"name":"just_audio_web","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"qr_code_scanner","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2023-02-10 17:09:46.854097","version":"3.7.0"} \ No newline at end of file diff --git a/README.md b/README.md index 08fe67b..436fd72 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,10 @@ This README would normally document whatever steps are necessary to get your app # OPENAPI Generation cmd +flutter clean + +flutter pub get + flutter pub run build_runner build --delete-conflicting-outputs Le fichier est dans le projet. diff --git a/lib/Helpers/DatabaseHelper.dart b/lib/Helpers/DatabaseHelper.dart index 50ea9e4..ffe3bd2 100644 --- a/lib/Helpers/DatabaseHelper.dart +++ b/lib/Helpers/DatabaseHelper.dart @@ -126,10 +126,14 @@ class DatabaseHelper { //print("languages BEFORE"); //print(info["languages"]); } - var test = await instance.getData(type); - if((type == DatabaseTableType.main && test != null) || (type != DatabaseTableType.main && test!.where((t) => info[columnId] == t.id).isNotEmpty)) { + //var test = await instance.getData(type); + + var test = await DatabaseHelper.instance.queryWithColumnId(type, info[columnId].toString()); + + if((type == DatabaseTableType.main && test != null) || (type != DatabaseTableType.main && test.isNotEmpty)) { //test!.where((t) => info[columnId] == t.id).isNotEmpty if(type != DatabaseTableType.main) { - print("UPDATE $type - length before ${test.length}"); + //print("UPDATE $type - length before ${test.length}"); + print("UPDATE $type"); } else { print("UPDATE $type - main table"); } @@ -142,7 +146,8 @@ class DatabaseHelper { return res; } else { if(type != DatabaseTableType.main) { - print("INSERT $type - length before ${test.length}"); + //print("INSERT $type - length before ${test.length}"); + print("INSERT $type"); } else { print("INSERT $type - main table"); } diff --git a/lib/Models/resourceModel.dart b/lib/Models/resourceModel.dart index 23a1ecd..141c73c 100644 --- a/lib/Models/resourceModel.dart +++ b/lib/Models/resourceModel.dart @@ -14,7 +14,7 @@ class ResourceModel { 'id': id, 'data': data, 'source': source, - 'type': type!.value + 'type': type?.value }; } diff --git a/lib/Screens/Home/home.dart b/lib/Screens/Home/home.dart index e564c56..d3b04bb 100644 --- a/lib/Screens/Home/home.dart +++ b/lib/Screens/Home/home.dart @@ -119,15 +119,18 @@ class _HomePageState extends State with WidgetsBindingObserver { bool isOnline = await hasNetwork(); VisitAppContext visitAppContext = appContext.getContext(); + List? configurations; + configurations = List.from(await DatabaseHelper.instance.getData(DatabaseTableType.configurations)); + alreadyDownloaded = configurations.map((c) => c.id).toList(); + + print("alreadyDownloadedalreadyDownloadedalreadyDownloadedalreadyDownloadedalreadyDownloadedalreadyDownloaded"); + print(alreadyDownloaded); + if(!isOnline) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text(TranslationHelper.getFromLocale("noInternet", appContext)), backgroundColor: kBlue2), ); - List? configurations; - configurations = List.from(await DatabaseHelper.instance.getData(DatabaseTableType.configurations)); - alreadyDownloaded = configurations.map((c) => c.id).toList(); - // TODO HANDLE BEACON IN LOCAL (CREATE TABLE) return configurations; @@ -143,6 +146,7 @@ class _HomePageState extends State with WidgetsBindingObserver { appContext.setContext(visitAppContext); // STORE IT, TODO Store it locally } } + return await ApiService.getConfigurations(client, visitAppContext); } } \ No newline at end of file diff --git a/lib/Services/apiService.dart b/lib/Services/apiService.dart index e3189a3..77d9714 100644 --- a/lib/Services/apiService.dart +++ b/lib/Services/apiService.dart @@ -172,5 +172,22 @@ class ApiService { return ResourceModel(); // To mock } } + + static Future exportConfiguration(Client client, String configurationId) async { + try { + bool isOnline = await hasNetwork(); + if(isOnline) { + ExportConfigurationDTO? exportConfiguration = await client.configurationApi!.configurationExport(configurationId); + + return exportConfiguration; + } else { + return null; // TODO return local list.. + } + } catch (e) { + print(e); + print("exportConfiguration IN CATCH"); + return null; + } + } } diff --git a/lib/Services/downloadConfiguration.dart b/lib/Services/downloadConfiguration.dart index eb2a1db..58a4c04 100644 --- a/lib/Services/downloadConfiguration.dart +++ b/lib/Services/downloadConfiguration.dart @@ -11,8 +11,93 @@ import 'package:mymuseum_visitapp/app_context.dart'; class DownloadConfiguration { static Future downloadClicked(AppContext appContext, ConfigurationDTO configuration) async { - // Update local DB - Configuration - await DatabaseHelper.instance.insert(DatabaseTableType.configurations, ModelsHelper.configurationToMap(configuration)); + print("COUCOUCOU IIIIINNNN"); + // TODO TEST VIA EXPORT + ExportConfigurationDTO? exportConfigurationDTO = await ApiService.exportConfiguration(appContext.clientAPI, configuration.id!); + + if(exportConfigurationDTO != null) { + // Delete all from local DB ref to this configurationId then add it all + + await DatabaseHelper.instance.insert(DatabaseTableType.configurations, ModelsHelper.configurationToMap(configuration)); + List usedImageOrAudioIds = []; + + var currentLanguage = (appContext.getContext() as VisitAppContext).language; + + if(configuration.imageId != null) { + usedImageOrAudioIds.add(configuration.imageId!); + + var imageData = exportConfigurationDTO.resources!.where((element) => element.id == configuration.imageId); + if(imageData.isNotEmpty) { + ResourceModel resourceModel = ResourceModel(id: imageData.first.id, source: configuration.imageSource, data: imageData.first.data, type: imageData.first.type); + await DatabaseHelper.instance.insert(DatabaseTableType.resources, resourceModel.toMap()); + } + } + + List? sections = exportConfigurationDTO.sections; + + if(sections!.isNotEmpty) { + + List sectionsInDB = await DatabaseHelper.instance.queryWithConfigurationId(DatabaseTableType.sections, configuration.id!); + List sectionsToKeep = sections.where((s) => s.type == SectionType.Article).toList(); // TODO handle other type of section + + sectionsToKeep.sort((a,b) => a.order!.compareTo(b.order!)); + int newOrder = 0; + // Update local DB - Sections + for(var section in sectionsToKeep) { + section.order = newOrder; + await DatabaseHelper.instance.insert(DatabaseTableType.sections, ModelsHelper.sectionToMap(section)); + + // Download section image + if(section.imageId != null) { + usedImageOrAudioIds.add(section.imageId!); + var imageData = exportConfigurationDTO.resources!.where((element) => element.id == section.imageId); + if(imageData.isNotEmpty) { + ResourceModel resourceModel = ResourceModel(id: imageData.first.id, source: section.imageSource, data: imageData.first.data, type: imageData.first.type); + await DatabaseHelper.instance.insert(DatabaseTableType.resources, resourceModel.toMap()); + } + } + + // Download all images.. + ArticleDTO? articleDTO = ArticleDTO.fromJson(jsonDecode(section.data!)); + + if(articleDTO != null) { + for(var image in articleDTO.images!) { + usedImageOrAudioIds.add(image.resourceId!); + var imageData = exportConfigurationDTO.resources!.where((element) => element.id == image.resourceId); + if(imageData.isNotEmpty) { + ResourceModel resourceModel = ResourceModel(id: imageData.first.id, source: image.source_, data: imageData.first.data, type: imageData.first.type); + await DatabaseHelper.instance.insert(DatabaseTableType.resources, resourceModel.toMap()); + } + } + + var audioIdArticle = articleDTO.audioIds!.where((audioId) => audioId.language == currentLanguage); + if(audioIdArticle.isNotEmpty && audioIdArticle.first.value != null) + { + usedImageOrAudioIds.add(audioIdArticle.first.value!); + var audioData = exportConfigurationDTO.resources!.where((element) => element.id == audioIdArticle.first.value); + if(audioData.isNotEmpty) { + ResourceModel resourceModel = ResourceModel(id: audioData.first.id, source: "", data: audioData.first.data, type: audioData.first.type); + await DatabaseHelper.instance.insert(DatabaseTableType.resources, resourceModel.toMap()); + } + } + } + newOrder = newOrder + 1; + } + + List sectionIdsToRemove = sectionsInDB.map((s) => s.id).where((sectionId) => !sectionsToKeep.map((sk) => sk.id).contains(sectionId)).toList(); + + for(var sectionIdToRemove in sectionIdsToRemove) { + print("section with id removed"); + print(sectionIdToRemove); + await DatabaseHelper.instance.delete(sectionIdToRemove!, DatabaseTableType.sections); + } + + cleanLocalResources(usedImageOrAudioIds, configuration); + } + } + + // Update local DB - Configuration - OLD COOODE + /*await DatabaseHelper.instance.insert(DatabaseTableType.configurations, ModelsHelper.configurationToMap(configuration)); List usedImageOrAudioIds = []; var currentLanguage = (appContext.getContext() as VisitAppContext).language; @@ -72,7 +157,7 @@ class DownloadConfiguration { } cleanLocalResources(usedImageOrAudioIds, configuration); - } + }*/ return true; } diff --git a/lib/translations.dart b/lib/translations.dart index ef12c04..06db35a 100644 --- a/lib/translations.dart +++ b/lib/translations.dart @@ -7,7 +7,7 @@ List translations = [ "noData": "Pas de données", "invalidQRCode": "Code QR invalide", "languageNotSupported": "Cette visite ne prend pas en charge votre langue", - "downloadConfiguration": "Chargement de la visite en cours...", + "downloadConfiguration": "Téléchargement de la visite en cours...", "noInternet": "Aucune connexion internet détectée", "search": "Rechercher", "play": "Lecture", diff --git a/manager_api/lib/api/configuration_api.dart b/manager_api/lib/api/configuration_api.dart index ffc3cf0..a1208eb 100644 --- a/manager_api/lib/api/configuration_api.dart +++ b/manager_api/lib/api/configuration_api.dart @@ -144,7 +144,7 @@ class ConfigurationApi { /// Parameters: /// /// * [String] id (required): - Future configurationExport(String id,) async { + Future configurationExport(String id,) async { final response = await configurationExportWithHttpInfo(id,); if (response.statusCode >= HttpStatus.badRequest) { throw ApiException(response.statusCode, await _decodeBodyBytes(response)); @@ -153,8 +153,12 @@ class ConfigurationApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body.isNotEmpty && response.statusCode != HttpStatus.noContent) { - return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'MultipartFile',) as MultipartFile; - + var test = await _decodeBodyBytes(response); + var responseJSON = json.decode(test); + var export = ExportConfigurationDTO.fromJson(responseJSON); + + return export; + //return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'MultipartFile',) as MultipartFile; } return null; } diff --git a/manager_api/lib/model/map_type_app.dart b/manager_api/lib/model/map_type_app.dart index df1fda6..deee49b 100644 --- a/manager_api/lib/model/map_type_app.dart +++ b/manager_api/lib/model/map_type_app.dart @@ -23,19 +23,19 @@ class MapTypeApp { int toJson() => value; - static const number0 = MapTypeApp._(0); - static const number1 = MapTypeApp._(1); - static const number2 = MapTypeApp._(2); - static const number3 = MapTypeApp._(3); - static const number4 = MapTypeApp._(4); + static const none = MapTypeApp._(0); + static const normal = MapTypeApp._(1); + static const satellite = MapTypeApp._(2); + static const terrain = MapTypeApp._(3); + static const hybrid = MapTypeApp._(4); /// List of all possible values in this [enum][MapTypeApp]. static const values = [ - number0, - number1, - number2, - number3, - number4, + none, + normal, + satellite, + terrain, + hybrid, ]; static MapTypeApp? fromJson(dynamic value) => MapTypeAppTypeTransformer().decode(value); @@ -73,18 +73,48 @@ class MapTypeAppTypeTransformer { /// and users are still using an old app with the old code. MapTypeApp? decode(dynamic data, {bool allowNull = true}) { if (data != null) { - switch (data) { - case 0: return MapTypeApp.number0; - case 1: return MapTypeApp.number1; - case 2: return MapTypeApp.number2; - case 3: return MapTypeApp.number3; - case 4: return MapTypeApp.number4; + switch (data.toString()) { + case r'None': return MapTypeApp.none; + case r'Normal': return MapTypeApp.normal; + case r'Satellite': return MapTypeApp.satellite; + case r'Terrain': return MapTypeApp.terrain; + case r'Hybrid': return MapTypeApp.hybrid; default: if (!allowNull) { throw ArgumentError('Unknown enum value to decode: $data'); } } } + if (data != null) { + if(data.runtimeType == String) { + switch (data.toString()) { + case r'None': return MapTypeApp.none; + case r'Normal': return MapTypeApp.normal; + case r'Satellite': return MapTypeApp.satellite; + case r'Terrain': return MapTypeApp.terrain; + case r'Hybrid': return MapTypeApp.hybrid; + default: + if (!allowNull) { + throw ArgumentError('Unknown enum value to decode: $data'); + } + } + } else { + if(data.runtimeType == int) { + switch (data) { + case 0: return MapTypeApp.none; + case 1: return MapTypeApp.normal; + case 2: return MapTypeApp.satellite; + case 3: return MapTypeApp.terrain; + case 4: return MapTypeApp.hybrid; + default: + if (!allowNull) { + throw ArgumentError('Unknown enum value to decode: $data'); + } + } + } + } + + } return null; } diff --git a/manager_api/lib/model/resource_type.dart b/manager_api/lib/model/resource_type.dart index 9fa5bb6..f9022f2 100644 --- a/manager_api/lib/model/resource_type.dart +++ b/manager_api/lib/model/resource_type.dart @@ -73,16 +73,32 @@ class ResourceTypeTypeTransformer { /// and users are still using an old app with the old code. ResourceType? decode(dynamic data, {bool allowNull = true}) { if (data != null) { - switch (data) { - case "Image": return ResourceType.Image; - case "Video": return ResourceType.Video; - case "ImageUrl": return ResourceType.ImageUrl; - case "VideoUrl": return ResourceType.VideoUrl; - case "Audio": return ResourceType.Audio; - default: - if (!allowNull) { - throw ArgumentError('Unknown enum value to decode: $data'); + if(data.runtimeType == String) { + switch (data.toString()) { + case r'Image': return ResourceType.Image; + case r'Video': return ResourceType.Video; + case r'ImageUrl': return ResourceType.ImageUrl; + case r'VideoUrl': return ResourceType.VideoUrl; + case r'Audio': return ResourceType.Audio; + default: + if (!allowNull) { + throw ArgumentError('Unknown enum value to decode: $data'); + } + } + } else { + if(data.runtimeType == int) { + switch (data) { + case 0: return ResourceType.Image; + case 1: return ResourceType.Video; + case 2: return ResourceType.ImageUrl; + case 3: return ResourceType.VideoUrl; + case 4: return ResourceType.Audio; + default: + if (!allowNull) { + throw ArgumentError('Unknown enum value to decode: $data'); + } } + } } } return null; diff --git a/manager_api/lib/model/section_type.dart b/manager_api/lib/model/section_type.dart index 3441269..56bf3f0 100644 --- a/manager_api/lib/model/section_type.dart +++ b/manager_api/lib/model/section_type.dart @@ -77,18 +77,42 @@ class SectionTypeTypeTransformer { /// and users are still using an old app with the old code. SectionType? decode(dynamic data, {bool allowNull = true}) { if (data != null) { - switch (data) { - case 'Map': return SectionType.Map; - case 'Slider': return SectionType.Slider; - case 'Video': return SectionType.Video; - case 'Web': return SectionType.Web; - case 'Menu': return SectionType.Menu; - case 'Quizz': return SectionType.Quizz; - case 'Article': return SectionType.Article; - default: - if (!allowNull) { - throw ArgumentError('Unknown enum value to decode: $data'); + /*print("data.toString()"); + print(data.toString()); + print(data.runtimeType);*/ + if(data.runtimeType == String) { + switch (data.toString()) { + case r'Map': return SectionType.Map; + case r'Slider': return SectionType.Slider; + case r'Video': return SectionType.Video; + case r'Web': return SectionType.Web; + case r'Menu': return SectionType.Menu; + case r'Quizz': return SectionType.Quizz; + case r'Article': return SectionType.Article; + default: + if (!allowNull) { + throw ArgumentError('Unknown enum value to decode: $data'); + } + } + } else { + if(data.runtimeType == int) { + //print("HELLOWWWWW INT"); + switch (data) { + case 0: + print("RETURN MAP"); + return SectionType.Map; + case 1: return SectionType.Slider; + case 2: return SectionType.Video; + case 3: return SectionType.Web; + case 4: return SectionType.Menu; + case 5: return SectionType.Quizz; + case 6: return SectionType.Article; + default: + if (!allowNull) { + throw ArgumentError('Unknown enum value to decode: $data'); + } } + } } } return null;