check duplicate event
This commit is contained in:
parent
32532246eb
commit
303447ff1e
@ -102,6 +102,24 @@ class DisplayPictureScreenState extends State<DisplayPictureScreen>
|
||||
"L'IA de Google n'a pas su analyser l'image. Recommecer avec une autre");
|
||||
}
|
||||
|
||||
void _showErrorDialog(BuildContext context, String title, String message) {
|
||||
showAlertDialog(context, title, message);
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>?> _fetchGeolocation(String place) async {
|
||||
final apiKey = dotenv.env['PLACE_API_KEY'] ?? '';
|
||||
final response = await http.get(Uri.parse(
|
||||
'https://maps.googleapis.com/maps/api/place/textsearch/json?query=${place}}&key=$apiKey'));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = json.decode(response.body);
|
||||
if (data['results'].isNotEmpty) {
|
||||
return data['results'][0]['geometry']['location'];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<bool> _isDuplicateEvent(String accessToken,
|
||||
Map<String, dynamic> jsonData, Map<String, dynamic> location) async {
|
||||
final url = Uri.parse(
|
||||
@ -133,13 +151,22 @@ class DisplayPictureScreenState extends State<DisplayPictureScreen>
|
||||
var accessToken = prefs.getString("access_token") ?? "";
|
||||
|
||||
if (accessToken.isNotEmpty) {
|
||||
var urlGet = Uri.parse(
|
||||
"${globals.api}/events/search?item=${name}&date_event=${date}");
|
||||
final location = await _fetchGeolocation(place);
|
||||
if (location == null) {
|
||||
_showErrorDialog(
|
||||
context, "Erreur serveur", "Aucune donnée geographique");
|
||||
return;
|
||||
}
|
||||
|
||||
var responseGet = await http.get(urlGet,
|
||||
headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'});
|
||||
if (responseGet.statusCode == 200) {
|
||||
var events = jsonDecode(utf8.decode(responseGet.bodyBytes));
|
||||
final url = Uri.parse(
|
||||
"${globals.api}/events/search?item=${name}&date_event=${date}"
|
||||
"&min_lat=${location['lat']}&max_lat=${location['lat']}"
|
||||
"&min_lon=${location['lng']}&max_lon=${location['lng']}");
|
||||
|
||||
final response = await http.get(url,
|
||||
headers: {HttpHeaders.cookieHeader: 'access_token=$accessToken'});
|
||||
if (response.statusCode == 200) {
|
||||
var events = jsonDecode(utf8.decode(response.bodyBytes));
|
||||
print("reponse http : ${events.length}");
|
||||
if (events.length == 0) {
|
||||
Navigator.push(
|
||||
@ -155,7 +182,7 @@ class DisplayPictureScreenState extends State<DisplayPictureScreen>
|
||||
}
|
||||
} else {
|
||||
showAlertDialog(context, 'Erreur de reponse',
|
||||
"response status code update : ${responseGet.statusCode}");
|
||||
"response status code update : ${response.statusCode}");
|
||||
}
|
||||
} else {
|
||||
showAlertDialog(context, "Erreur de reponse", "Erreur de token");
|
||||
|
Loading…
x
Reference in New Issue
Block a user