Skip to content

Commit

Permalink
Update main.rs
Browse files Browse the repository at this point in the history
add coord arrival route
  • Loading branch information
GuillaumeGANGLOFF authored Apr 15, 2024
1 parent 79abb29 commit dc8f081
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions services/drink/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@ extern crate common;
use common::google::nearly_place_model::{Emplacement, exploit_json};
use common::google::Google;

#[derive(Serialize, Deserialize, Debug)]
struct CityCoord {
lat: f64,
long: f64,
}

impl CityCoord {
fn new(lat: f64, long: f64) -> Self {
Self {
lat,
long
}
}
}

#[get("/coord/<localisation>")]
async fn coord(localisation: String) -> Json<CityCoord> {
let mut google = Google::new();
google
.geocoding(localisation)
.await
.expect("geocoding n'a pas été éxécuté correctement");
let result = CityCoord::new(google.lat, google.lng);
Json(result)
}

#[get("/service/drink/<localisation>/<radius>")]
async fn index(localisation: String, radius: i32) -> Json<HashMap<String, Vec<Emplacement>>> {
Expand All @@ -25,7 +50,7 @@ async fn index(localisation: String, radius: i32) -> Json<HashMap<String, Vec<Em

#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![index])
rocket::build().mount("/", routes![index, coord])
}

pub(crate) async fn get_google(localisation: String, radius: i32, types: String) -> Value {
Expand All @@ -39,4 +64,4 @@ pub(crate) async fn get_google(localisation: String, radius: i32, types: String)
.await
.expect("Erreur dans la récupération des données dans la fonction get_google");
result
}
}

0 comments on commit dc8f081

Please sign in to comment.