Created
October 5, 2022 10:45
-
-
Save shubhamkumar13/c919ec00b290f572d612c5f5a4c87a7f to your computer and use it in GitHub Desktop.
rest of code after improved code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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