Skip to content

Instantly share code, notes, and snippets.

@shubhamkumar13
Created October 5, 2022 10:45
Show Gist options
  • Save shubhamkumar13/c919ec00b290f572d612c5f5a4c87a7f to your computer and use it in GitHub Desktop.
Save shubhamkumar13/c919ec00b290f572d612c5f5a4c87a7f to your computer and use it in GitHub Desktop.
rest of code after improved code
// update cab destination and person_id
nearest_cab.update_destination(Some(person.location.clone()));
nearest_cab.update_person_id(ObjectId::parse_str(person_id).ok());
// update cab by using `assign_person`
let cab_id = match nearest_cab.id {
Some(obj_id) => obj_id.to_hex(),
None => panic!("cannot get the cab id"),
};
let update_result = db.assign_person(&cab_id, nearest_cab.clone());
// return result as person and cab tuple
match update_result {
Ok(update) => {
if update.matched_count == 1 {
let updated_cab_info = db.get_cab(&cab_id);
match updated_cab_info {
Ok(cab) => Ok(Json((person, cab))),
Err(_) => Err(Status::InternalServerError),
}
} else {
Err(Status::NotFound)
}
}
Err(_) => Err(Status::InternalServerError),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment