Skip to content

Instantly share code, notes, and snippets.

@rippinrobr
Created May 24, 2018 22:38
Show Gist options
  • Save rippinrobr/5409d72d1d8c23292ae09653f4fdb57f to your computer and use it in GitHub Desktop.
Save rippinrobr/5409d72d1d8c23292ae09653f4fdb57f to your computer and use it in GitHub Desktop.
the handler for /conspiracies/{page_id}
/// returns the conspiracy by the given id
fn get_conspiracies_by_id(req: HttpRequest<State>) -> impl Future<Item=HttpResponse, Error=Error> {
let page_id = &req.match_info()["page_id"];
// Send message to `DbExecutor` actor
req.state().db.send(GetConspiracy{page_id: page_id.to_owned()})
.from_err()
.and_then(|res| {
match res {
Ok(conspiracy) => Ok(HttpResponse::Ok().json(conspiracy)),
Err(_) => Ok(HttpResponse::NotFound().into())
}
})
.responder()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment