Created
May 24, 2018 22:38
-
-
Save rippinrobr/5409d72d1d8c23292ae09653f4fdb57f to your computer and use it in GitHub Desktop.
the handler for /conspiracies/{page_id}
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
/// 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