Skip to content

Commit

Permalink
question POST endpoint init
Browse files Browse the repository at this point in the history
  • Loading branch information
subhojit777 committed Jun 12, 2019
1 parent 7fa5985 commit d758f2f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -15,3 +15,4 @@ futures = "^0.1"
env_logger = "^0.6"
failure = "^0.1.5"
reqwest = "^0.9.14"
actix = { version = "^0.7" }
2 changes: 2 additions & 0 deletions src/lib.rs
Expand Up @@ -104,6 +104,7 @@ extern crate reqwest;
extern crate serde_json;
#[macro_use]
extern crate diesel;
extern crate actix;
extern crate actix_web;
extern crate dotenv;
extern crate failure;
Expand Down Expand Up @@ -133,6 +134,7 @@ pub mod helpers;
pub mod middleware;
pub mod models;
pub mod presentations;
pub mod questions;
pub mod schema;
pub mod session;

Expand Down
25 changes: 25 additions & 0 deletions src/questions.rs
@@ -0,0 +1,25 @@
use actix::{Handler, Message};
use diesel::query_dsl::RunQueryDsl;
use diesel::MysqlConnection;
use models::NewQuestion;
use DbExecutor;

impl Message for NewQuestion {
type Result = Result<(), super::error::Db>;
}

impl Handler<NewQuestion> for DbExecutor {
type Result = Result<(), super::error::Db>;

fn handle(&mut self, msg: NewQuestion, _ctx: &mut Self::Context) -> Self::Result {
use schema::questions::dsl::questions;
let connection: &MysqlConnection = &self.0.get().unwrap();

diesel::insert_into(questions)
.values(&msg)
.execute(connection)
.expect("Error saving the question");

Ok(())
}
}

0 comments on commit d758f2f

Please sign in to comment.