1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 01:32:57 +01:00

better name

This commit is contained in:
Nikolay Kim 2017-12-18 16:40:33 -08:00
parent 625c4ad0db
commit 1e1da5832f

View File

@ -16,12 +16,10 @@ extern crate actix;
extern crate actix_web; extern crate actix_web;
extern crate env_logger; extern crate env_logger;
use actix::prelude::*;
use actix_web::*; use actix_web::*;
use futures::future::{Future, ok}; use actix::prelude::*;
use diesel::Connection;
use diesel::sqlite::SqliteConnection;
use diesel::prelude::*; use diesel::prelude::*;
use futures::future::{Future, ok};
mod models; mod models;
mod schema; mod schema;
@ -36,7 +34,7 @@ fn index(req: HttpRequest<State>) -> Box<Future<Item=HttpResponse, Error=Error>>
let name = &req.match_info()["name"]; let name = &req.match_info()["name"];
Box::new( Box::new(
req.state().db.call_fut(CreatePerson{name: name.to_owned()}) req.state().db.call_fut(CreateUser{name: name.to_owned()})
.and_then(|res| { .and_then(|res| {
match res { match res {
Ok(person) => ok(httpcodes::HTTPOk.build().json(person).unwrap()), Ok(person) => ok(httpcodes::HTTPOk.build().json(person).unwrap()),
@ -51,11 +49,11 @@ struct DbExecutor(SqliteConnection);
/// This is only message that this actor can handle, but it is easy to extend number of /// This is only message that this actor can handle, but it is easy to extend number of
/// messages. /// messages.
struct CreatePerson { struct CreateUser {
name: String, name: String,
} }
impl ResponseType for CreatePerson { impl ResponseType for CreateUser {
type Item = models::User; type Item = models::User;
type Error = Error; type Error = Error;
} }
@ -64,9 +62,9 @@ impl Actor for DbExecutor {
type Context = SyncContext<Self>; type Context = SyncContext<Self>;
} }
impl Handler<CreatePerson> for DbExecutor { impl Handler<CreateUser> for DbExecutor {
fn handle(&mut self, msg: CreatePerson, _: &mut Self::Context) fn handle(&mut self, msg: CreateUser, _: &mut Self::Context)
-> Response<Self, CreatePerson> -> Response<Self, CreateUser>
{ {
use self::schema::users::dsl::*; use self::schema::users::dsl::*;
@ -90,7 +88,6 @@ impl Handler<CreatePerson> for DbExecutor {
} }
} }
fn main() { fn main() {
::std::env::set_var("RUST_LOG", "actix_web=info"); ::std::env::set_var("RUST_LOG", "actix_web=info");
let _ = env_logger::init(); let _ = env_logger::init();