diff --git a/src/main.rs b/src/main.rs index 9484972..c18af04 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,26 +15,6 @@ use models::Score; use rocket::Rocket; use rocket_contrib::Json; -#[get("/")] -fn index() -> String { - String::from("Hello, world!") -} - -#[get("/dynamic")] -fn dynamic(conn: db::Conn) -> String { - format!("all greetings: {:?}", models::Greeting::all(conn.handler())) -} - -#[post("/greeting", data = "")] -fn set_greeting(input: String, conn: db::Conn) -> String { - let msg = models::Greeting{ id: None, text: input }; - let ok = models::Greeting::insert(msg, conn.handler()); - match ok { - true => String::from("success!"), - false => String::from("failed"), - } -} - #[post("/scores/new", format = "application/json", data = "")] fn add_score(score: Json, conn: db::Conn) -> String { let ok = score.0.insert(conn.handler()); @@ -52,7 +32,7 @@ fn get_scores(conn: db::Conn) -> String { fn rocket() -> Rocket { rocket::ignite() .manage(db::init_pool()) - .mount("/", routes![index,dynamic,set_greeting,add_score,get_scores]) + .mount("/", routes![add_score,get_scores]) } fn main() { diff --git a/src/models.rs b/src/models.rs index d9aaa04..7bbc56d 100644 --- a/src/models.rs +++ b/src/models.rs @@ -4,9 +4,6 @@ use diesel::insert_into; use super::schema::scores; use super::schema::scores::dsl::{scores as all_scores}; -use super::schema::greetings; -use super::schema::greetings::dsl::{greetings as all_greetings}; - #[derive(Serialize, Deserialize, Queryable, Insertable, Debug)] pub struct Score { pub id: i32, @@ -26,22 +23,3 @@ impl Score { .is_ok() } } - -#[derive(Queryable, Insertable, Debug)] -pub struct Greeting { - pub id: Option, - pub text: String, -} - -impl Greeting { - pub fn all(conn: &SqliteConnection) -> Vec { - all_greetings.load::(conn).unwrap() - } - - pub fn insert(msg: Greeting, conn: &SqliteConnection) -> bool { - insert_into(greetings::table) - .values(msg) - .execute(conn) - .is_ok() - } -}