From cf100651eb16b63a542c08875c94e47d595aaec7 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 4 Dec 2024 23:28:09 +0100 Subject: [PATCH] check existing event before add --- covas_mobile/lib/pages/UpdateEventImage.dart | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/covas_mobile/lib/pages/UpdateEventImage.dart b/covas_mobile/lib/pages/UpdateEventImage.dart index f405afa..bfadf0d 100644 --- a/covas_mobile/lib/pages/UpdateEventImage.dart +++ b/covas_mobile/lib/pages/UpdateEventImage.dart @@ -9,6 +9,7 @@ import 'dart:convert'; import 'dart:io'; import 'dart:typed_data'; +import 'ItemMenu.dart'; import '../classes/alert.dart'; import '../classes/eventAdded.dart'; @@ -176,6 +177,42 @@ class _UpdateeventImageState extends State data['features'][0]['geometry']['coordinates']; final longitude = coordinates[0]; // Longitude final latitude = coordinates[1]; // Latitude + var urlGet = Uri.parse( + "${globals.api}/events/search?item=${name}&date_event=${startDate}"); + + 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) { + urlGet = Uri.parse( + "${globals.api}/events/search?min_lat=$latitude&max_lat=$latitude" + "&min_lon=$longitude&max_lon=$longitude&date_event=${startDate}"); + responseGet = await http.get(urlGet, headers: { + HttpHeaders.cookieHeader: 'access_token=${accessToken}' + }); + if (responseGet.statusCode == 200) { + events = jsonDecode(utf8.decode(responseGet.bodyBytes)); + print("reponse http : ${events.length}"); + if (events.length != 0) { + Navigator.push( + context, + MaterialPageRoute( + builder: (_) => + ItemMenu(title: events[0]["id"]))); + return; + } + } + } else { + Navigator.push( + context, + MaterialPageRoute( + builder: (_) => ItemMenu(title: events[0]["id"]))); + return; + } + } final params = { 'expiration': '15552000',