From 5bd2319a6a778c869707ec2519bd60c3da96a141 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 24 Jul 2024 23:17:11 +0200 Subject: [PATCH 1/9] create function --- covas_mobile/lib/pages/DisplayPictureScreen.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/covas_mobile/lib/pages/DisplayPictureScreen.dart b/covas_mobile/lib/pages/DisplayPictureScreen.dart index 62007b4..7a4aba4 100644 --- a/covas_mobile/lib/pages/DisplayPictureScreen.dart +++ b/covas_mobile/lib/pages/DisplayPictureScreen.dart @@ -60,6 +60,10 @@ class DisplayPictureScreenState extends State "L'IA de Google n'a pas su analyser l'image. Recommecer avec une autre"); } + Future searchEvents(String json) async { + showDescImageAddDialog(context, json); + } + Future _getEventInfosFromImage() async { await dotenv.load(); @@ -74,8 +78,7 @@ class DisplayPictureScreenState extends State "Peux-tu donner le nom, la date et le lieu de l'évènement sous format JSON avec les valeurs suivantes : name, place et date", images: [file.readAsBytesSync()], modelName: "models/gemini-1.5-flash-latest") - .then((value) => showDescImageAddDialog( - context, value?.content?.parts?.last.text ?? '')) + .then((value) => searchEvents(value?.content?.parts?.last.text ?? '')) .catchError((e) => displayError); } From cf8d636f948e34f656a938453990fe317cb4036c Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 25 Jul 2024 00:18:00 +0200 Subject: [PATCH 2/9] fix convert json --- covas_mobile/lib/pages/DisplayPictureScreen.dart | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/covas_mobile/lib/pages/DisplayPictureScreen.dart b/covas_mobile/lib/pages/DisplayPictureScreen.dart index 7a4aba4..2807f41 100644 --- a/covas_mobile/lib/pages/DisplayPictureScreen.dart +++ b/covas_mobile/lib/pages/DisplayPictureScreen.dart @@ -5,6 +5,9 @@ import '../classes/alert.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_gemini/flutter_gemini.dart'; +import 'dart:io'; +import 'dart:convert'; + void main() { runApp(MyApp()); } @@ -61,7 +64,13 @@ class DisplayPictureScreenState extends State } Future searchEvents(String json) async { - showDescImageAddDialog(context, json); + print(json); + Map jsonData = jsonDecode(json); + var name = jsonData["name"]; + var place = jsonData["place"]; + var message = "Nom : ${name}\nLieu: ${place}"; + print(message); + showDescImageAddDialog(context, message); } Future _getEventInfosFromImage() async { @@ -75,7 +84,7 @@ class DisplayPictureScreenState extends State gemini .textAndImage( text: - "Peux-tu donner le nom, la date et le lieu de l'évènement sous format JSON avec les valeurs suivantes : name, place et date", + "Peux-tu donner le nom, la date et le lieu de l'évènement sous format JSON avec les valeurs suivantes : name, place et date, et sans la présence de json dans la chaîne de caractère", images: [file.readAsBytesSync()], modelName: "models/gemini-1.5-flash-latest") .then((value) => searchEvents(value?.content?.parts?.last.text ?? '')) From 4af1d12283e6433f9843b78d052e19dd557a45de Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 25 Jul 2024 21:49:52 +0200 Subject: [PATCH 3/9] search events on backend --- .../lib/pages/DisplayPictureScreen.dart | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/covas_mobile/lib/pages/DisplayPictureScreen.dart b/covas_mobile/lib/pages/DisplayPictureScreen.dart index 2807f41..b26da97 100644 --- a/covas_mobile/lib/pages/DisplayPictureScreen.dart +++ b/covas_mobile/lib/pages/DisplayPictureScreen.dart @@ -4,10 +4,14 @@ import '../classes/descriptionImage.dart'; import '../classes/alert.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_gemini/flutter_gemini.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:http/http.dart' as http; import 'dart:io'; import 'dart:convert'; +import '../variable/globals.dart' as globals; + void main() { runApp(MyApp()); } @@ -65,12 +69,30 @@ class DisplayPictureScreenState extends State Future searchEvents(String json) async { print(json); + SharedPreferences prefs = await SharedPreferences.getInstance(); + Map jsonData = jsonDecode(json); var name = jsonData["name"]; var place = jsonData["place"]; - var message = "Nom : ${name}\nLieu: ${place}"; - print(message); - showDescImageAddDialog(context, message); + var accessToken = prefs.getString("access_token") ?? ""; + + if (accessToken.isNotEmpty) { + var urlGet = Uri.parse("${globals.api}/events?name=${name}"); + + var responseGet = await http.get(urlGet, + headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'}); + if (responseGet.statusCode == 200) { + var events = jsonDecode(utf8.decode(responseGet.bodyBytes)); + print("reponse http : ${events.length}"); + if (events.length == 0) { + showDescImageAddDialog(context, "${name} n'a pas été trouvé"); + } + } + } else { + showErrorDialog(context, "Erreur de token"); + } + + //showDescImageAddDialog(context, message); } Future _getEventInfosFromImage() async { From dc605b1a7c6088779939a1f4204ee8846aa424ef Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 25 Jul 2024 22:23:45 +0200 Subject: [PATCH 4/9] display message to add events --- .../lib/classes/descriptionImage.dart | 19 +++++++++++++++---- .../lib/pages/DisplayPictureScreen.dart | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/covas_mobile/lib/classes/descriptionImage.dart b/covas_mobile/lib/classes/descriptionImage.dart index fdd6710..ad9543e 100644 --- a/covas_mobile/lib/classes/descriptionImage.dart +++ b/covas_mobile/lib/classes/descriptionImage.dart @@ -1,14 +1,25 @@ import 'package:flutter/material.dart'; +import 'events.dart'; mixin ShowDescImageAdd on State { - void showDescImageAddDialog(BuildContext context, String text) { + void showDescImageAddDialog(BuildContext context, var events) { // Create AlertDialog + String name = events['name']; AlertDialog dialog = AlertDialog( - title: Text("Description image"), - content: Text(text), + title: Text("Ajouter un evenement"), + content: Text("${name} n'a pas été trouvé. Voulez-vous l'ajouter ? "), actions: [ ElevatedButton( - child: Text("OK"), + child: Text("Oui"), + style: ElevatedButton.styleFrom( + padding: EdgeInsets.symmetric(horizontal: 50, vertical: 20), + textStyle: + TextStyle(fontSize: 15, fontWeight: FontWeight.normal)), + onPressed: () { + Navigator.of(context).pop("Yes, Of course!"); // Return value + }), + ElevatedButton( + child: Text("Non"), style: ElevatedButton.styleFrom( padding: EdgeInsets.symmetric(horizontal: 50, vertical: 20), textStyle: diff --git a/covas_mobile/lib/pages/DisplayPictureScreen.dart b/covas_mobile/lib/pages/DisplayPictureScreen.dart index b26da97..dfe6c75 100644 --- a/covas_mobile/lib/pages/DisplayPictureScreen.dart +++ b/covas_mobile/lib/pages/DisplayPictureScreen.dart @@ -85,7 +85,7 @@ class DisplayPictureScreenState extends State var events = jsonDecode(utf8.decode(responseGet.bodyBytes)); print("reponse http : ${events.length}"); if (events.length == 0) { - showDescImageAddDialog(context, "${name} n'a pas été trouvé"); + showDescImageAddDialog(context, jsonData); } } } else { From ab297ffc77c84e10e3c0c2ef565a4b235ce3822b Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 25 Jul 2024 22:34:35 +0200 Subject: [PATCH 5/9] change elevatedbutton to textbutton --- covas_mobile/lib/classes/descriptionImage.dart | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/covas_mobile/lib/classes/descriptionImage.dart b/covas_mobile/lib/classes/descriptionImage.dart index ad9543e..b6243d8 100644 --- a/covas_mobile/lib/classes/descriptionImage.dart +++ b/covas_mobile/lib/classes/descriptionImage.dart @@ -9,21 +9,13 @@ mixin ShowDescImageAdd on State { title: Text("Ajouter un evenement"), content: Text("${name} n'a pas été trouvé. Voulez-vous l'ajouter ? "), actions: [ - ElevatedButton( - child: Text("Oui"), - style: ElevatedButton.styleFrom( - padding: EdgeInsets.symmetric(horizontal: 50, vertical: 20), - textStyle: - TextStyle(fontSize: 15, fontWeight: FontWeight.normal)), + TextButton( + child: Text("Annuler"), onPressed: () { Navigator.of(context).pop("Yes, Of course!"); // Return value }), - ElevatedButton( - child: Text("Non"), - style: ElevatedButton.styleFrom( - padding: EdgeInsets.symmetric(horizontal: 50, vertical: 20), - textStyle: - TextStyle(fontSize: 15, fontWeight: FontWeight.normal)), + TextButton( + child: Text("Oui"), onPressed: () { Navigator.of(context).pop("Yes, Of course!"); // Return value }), From c44f1e51ea1917ec5ebff68fba40bc7317a1f558 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 25 Jul 2024 22:44:06 +0200 Subject: [PATCH 6/9] add events function --- covas_mobile/lib/classes/descriptionImage.dart | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/covas_mobile/lib/classes/descriptionImage.dart b/covas_mobile/lib/classes/descriptionImage.dart index b6243d8..daed5b8 100644 --- a/covas_mobile/lib/classes/descriptionImage.dart +++ b/covas_mobile/lib/classes/descriptionImage.dart @@ -1,7 +1,14 @@ import 'package:flutter/material.dart'; import 'events.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + mixin ShowDescImageAdd on State { + Future addEvents(var events) async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + var accessToken = prefs.getString("access_token") ?? ""; + } + void showDescImageAddDialog(BuildContext context, var events) { // Create AlertDialog String name = events['name']; @@ -17,7 +24,7 @@ mixin ShowDescImageAdd on State { TextButton( child: Text("Oui"), onPressed: () { - Navigator.of(context).pop("Yes, Of course!"); // Return value + addEvents(events); // Return value }), ], ); From e320fccefa98aeca86dad787a4bdd1ab6ce1b17a Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Fri, 26 Jul 2024 15:06:15 +0200 Subject: [PATCH 7/9] add reponse http --- covas_mobile/lib/classes/descriptionImage.dart | 8 ++++++++ covas_mobile/lib/pages/DisplayPictureScreen.dart | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/covas_mobile/lib/classes/descriptionImage.dart b/covas_mobile/lib/classes/descriptionImage.dart index daed5b8..ccad849 100644 --- a/covas_mobile/lib/classes/descriptionImage.dart +++ b/covas_mobile/lib/classes/descriptionImage.dart @@ -1,5 +1,8 @@ import 'package:flutter/material.dart'; import 'events.dart'; +import '../variable/globals.dart' as globals; +import 'package:http/http.dart' as http; +import 'dart:io'; import 'package:shared_preferences/shared_preferences.dart'; @@ -7,6 +10,11 @@ mixin ShowDescImageAdd on State { Future addEvents(var events) async { SharedPreferences prefs = await SharedPreferences.getInstance(); var accessToken = prefs.getString("access_token") ?? ""; + if (accessToken.isNotEmpty) { + var urlGet = Uri.parse("${globals.api}/events"); + var responseGet = await http.get(urlGet, + headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'}); + } } void showDescImageAddDialog(BuildContext context, var events) { diff --git a/covas_mobile/lib/pages/DisplayPictureScreen.dart b/covas_mobile/lib/pages/DisplayPictureScreen.dart index dfe6c75..1a51781 100644 --- a/covas_mobile/lib/pages/DisplayPictureScreen.dart +++ b/covas_mobile/lib/pages/DisplayPictureScreen.dart @@ -7,7 +7,6 @@ import 'package:flutter_gemini/flutter_gemini.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:http/http.dart' as http; -import 'dart:io'; import 'dart:convert'; import '../variable/globals.dart' as globals; From de527cb84bcaafc641367dbacf3bae11c992f2dd Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 27 Jul 2024 16:44:19 +0200 Subject: [PATCH 8/9] add put http --- .../lib/classes/descriptionImage.dart | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/covas_mobile/lib/classes/descriptionImage.dart b/covas_mobile/lib/classes/descriptionImage.dart index ccad849..cbce573 100644 --- a/covas_mobile/lib/classes/descriptionImage.dart +++ b/covas_mobile/lib/classes/descriptionImage.dart @@ -3,6 +3,7 @@ import 'events.dart'; import '../variable/globals.dart' as globals; import 'package:http/http.dart' as http; import 'dart:io'; +import 'dart:convert'; import 'package:shared_preferences/shared_preferences.dart'; @@ -10,10 +11,24 @@ mixin ShowDescImageAdd on State { Future addEvents(var events) async { SharedPreferences prefs = await SharedPreferences.getInstance(); var accessToken = prefs.getString("access_token") ?? ""; + List send = ["toto"]; + if (accessToken.isNotEmpty) { - var urlGet = Uri.parse("${globals.api}/events"); - var responseGet = await http.get(urlGet, - headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'}); + var urlPut = Uri.parse("${globals.api}/events"); + var responsePut = await http.put(urlPut, + headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'}, + body: jsonEncode({ + 'name': events["name"], + 'place': events["place"], + 'start_date': events['start_date'], + 'end_date': events['start_date'], + 'organizers': send, + 'latitude': '0.0', + 'longitude': '0.0', + })); + + print("http put code status : ${responsePut.statusCode}"); + print("http put body : ${responsePut.body}"); } } From f081363c657168956a1d0edb532f870addb6a52c Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 27 Jul 2024 17:06:13 +0200 Subject: [PATCH 9/9] put http successful --- covas_mobile/lib/classes/descriptionImage.dart | 11 ++++++++--- covas_mobile/lib/pages/DisplayPictureScreen.dart | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/covas_mobile/lib/classes/descriptionImage.dart b/covas_mobile/lib/classes/descriptionImage.dart index cbce573..f55f3ce 100644 --- a/covas_mobile/lib/classes/descriptionImage.dart +++ b/covas_mobile/lib/classes/descriptionImage.dart @@ -15,13 +15,18 @@ mixin ShowDescImageAdd on State { if (accessToken.isNotEmpty) { var urlPut = Uri.parse("${globals.api}/events"); + print("start date : ${events["start_date"]}"); var responsePut = await http.put(urlPut, - headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'}, + headers: { + HttpHeaders.cookieHeader: 'access_token=${accessToken}', + HttpHeaders.acceptHeader: 'application/json, text/plain, */*', + HttpHeaders.contentTypeHeader: 'application/json' + }, body: jsonEncode({ 'name': events["name"], 'place': events["place"], - 'start_date': events['start_date'], - 'end_date': events['start_date'], + 'start_date': events['date'], + 'end_date': events['date'], 'organizers': send, 'latitude': '0.0', 'longitude': '0.0', diff --git a/covas_mobile/lib/pages/DisplayPictureScreen.dart b/covas_mobile/lib/pages/DisplayPictureScreen.dart index 1a51781..64a7e58 100644 --- a/covas_mobile/lib/pages/DisplayPictureScreen.dart +++ b/covas_mobile/lib/pages/DisplayPictureScreen.dart @@ -105,7 +105,7 @@ class DisplayPictureScreenState extends State gemini .textAndImage( text: - "Peux-tu donner le nom, la date et le lieu de l'évènement sous format JSON avec les valeurs suivantes : name, place et date, et sans la présence de json dans la chaîne de caractère", + "Peux-tu donner le nom, la date et le lieu de l'évènement sous format JSON avec les valeurs suivantes : name, place et date avec le format suivant YYYY-MM-ddTTHH:mm, et sans la présence de json dans la chaîne de caractère", images: [file.readAsBytesSync()], modelName: "models/gemini-1.5-flash-latest") .then((value) => searchEvents(value?.content?.parts?.last.text ?? ''))