diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..dfa1771 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + mariadb + true + org.mariadb.jdbc.Driver + jdbc:mariadb://localhost:3306 + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/dataSources/f334e98a-3c30-4412-8c71-35fe124ed605.xml b/.idea/dataSources/f334e98a-3c30-4412-8c71-35fe124ed605.xml new file mode 100644 index 0000000..51b344b --- /dev/null +++ b/.idea/dataSources/f334e98a-3c30-4412-8c71-35fe124ed605.xml @@ -0,0 +1,16 @@ + + + + + lower/lower + 10.4.25 + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dataSources/f334e98a-3c30-4412-8c71-35fe124ed605/storage_v2/_src_/schema/information_schema.FNRwLQ.meta b/.idea/dataSources/f334e98a-3c30-4412-8c71-35fe124ed605/storage_v2/_src_/schema/information_schema.FNRwLQ.meta new file mode 100644 index 0000000..1ff3db2 --- /dev/null +++ b/.idea/dataSources/f334e98a-3c30-4412-8c71-35fe124ed605/storage_v2/_src_/schema/information_schema.FNRwLQ.meta @@ -0,0 +1,2 @@ +#n:information_schema +! [null, 0, null, null, -2147483648, -2147483648] diff --git a/.idea/dataSources/f334e98a-3c30-4412-8c71-35fe124ed605/storage_v2/_src_/schema/mysql.osA4Bg.meta b/.idea/dataSources/f334e98a-3c30-4412-8c71-35fe124ed605/storage_v2/_src_/schema/mysql.osA4Bg.meta new file mode 100644 index 0000000..86a53f1 --- /dev/null +++ b/.idea/dataSources/f334e98a-3c30-4412-8c71-35fe124ed605/storage_v2/_src_/schema/mysql.osA4Bg.meta @@ -0,0 +1,2 @@ +#n:mysql +! [null, 0, null, null, -2147483648, -2147483648] diff --git a/.idea/dataSources/f334e98a-3c30-4412-8c71-35fe124ed605/storage_v2/_src_/schema/performance_schema.kIw0nw.meta b/.idea/dataSources/f334e98a-3c30-4412-8c71-35fe124ed605/storage_v2/_src_/schema/performance_schema.kIw0nw.meta new file mode 100644 index 0000000..9394db1 --- /dev/null +++ b/.idea/dataSources/f334e98a-3c30-4412-8c71-35fe124ed605/storage_v2/_src_/schema/performance_schema.kIw0nw.meta @@ -0,0 +1,2 @@ +#n:performance_schema +! [null, 0, null, null, -2147483648, -2147483648] diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml new file mode 100644 index 0000000..8485c62 --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Sources/dafl_project_flutter/lib/position/location.dart b/Sources/dafl_project_flutter/lib/position/location.dart index 3be754f..6fc1f55 100644 --- a/Sources/dafl_project_flutter/lib/position/location.dart +++ b/Sources/dafl_project_flutter/lib/position/location.dart @@ -6,48 +6,52 @@ import '../main.dart'; class Location { static Future> sendCurrentLocation() async { - Uri uri = Uri.parse("https://codefirst.iut.uca.fr/containers/php_script-dorianhodin/insert.php"); + + Uri uri = Uri.parse("https://codefirst.iut.uca.fr/containers/php_script-dorianhodin/insertAndMakeListUser.php"); + Map spot = {}; LocationPermission permission; + permission = await Geolocator.checkPermission(); + if (permission == LocationPermission.denied) { + permission = await Geolocator.requestPermission(); + if (permission == LocationPermission.deniedForever) { - //faire l'interface gra pour gérer ça + return Future.error('Location Not Available'); + } } + String actualUser = MyApp.controller.currentUser.usernameDafl; String actualSong = await MyApp.api.getCurrentlyPlayingTrack(); Position current = await Geolocator.getCurrentPosition(); - await http.post(uri, body: { + + http.Response response = await http.post(uri, body: { "id": actualUser.toString(), "latitude": current.latitude.toString(), "longitude": current.longitude.toString(), "idMusic": actualSong.toString(), }); - return getData(); - } - static Future> getData() async { - Map spot = {}; - String actualUser = MyApp.controller.currentUser.usernameDafl; - Uri uri = Uri.parse("https://codefirst.iut.uca.fr/containers/php_script-dorianhodin/distance.php"); - http.Response response = await http.post(uri, body: { - "id": actualUser, - }); var data = jsonDecode(response.body); - if (data.runtimeType==String) { - if (data=="Failed to connect to MySQL, connection timeout"){ - return Future.error(data); - }else if (data=="The POST didn't return any values"){ - return Future.error(data); - }else{ - return Future.error(data); //ERROR No user found in the database - } - }else { + + if (data == 2){ + + return Future.error("Failed to connect, connection timeout"); + + }else if (data == 3) { + + return Future.error("POST method failed"); + + }else{ + data.forEach((s) => spot.putIfAbsent(s['user'], () => s['music'])); return spot; + } } } +