Last active
June 6, 2018 22:32
-
-
Save rippinrobr/5047511276e8e1ce5e2b58ebd119b833 to your computer and use it in GitHub Desktop.
The code for the retrieving a particular conspiracy
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
/// The DbExecutor is contains the database connection which will be used by all of the | |
/// message handlers | |
pub struct DbExecutor(pub SqliteConnection); | |
impl Actor for DbExecutor { | |
type Context = SyncContext<Self>; | |
} | |
/// Sent to the DbExecutor to fetch the conspiracy with the given page_id | |
pub struct GetConspiracy { | |
pub page_id: String | |
} | |
/// Sets up the Result that is returned by the GetConspiracy handler | |
/// which is either the Conspiracy model or an error message | |
impl Message for GetConspiracy { | |
type Result = Result<Conspiracy, String>; | |
} | |
impl Handler<GetConspiracy> for DbExecutor { | |
type Result = Result<Conspiracy, String>; | |
/// The first two parameters are what we care about, the instance of self is where | |
/// I get the database connection from. The msg paramter contains the page_id that | |
/// was passed as part of the message and will be used to query the db for the requested | |
/// conspiracy. It makes a single call and returns the results of the results of the query. | |
fn handle(&mut self, msg: GetConspiracy, _: &mut Self::Context) -> Self::Result | |
{ | |
db::get_conspiracy_by_id(&self.0, &msg.page_id) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment