Skip to content

Commit

Permalink
Delete other usages of greetings
Browse files Browse the repository at this point in the history
  • Loading branch information
rychipman committed Oct 4, 2018
1 parent ce0eeb2 commit 90300d5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 43 deletions.
22 changes: 1 addition & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<input>")]
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 = "<score>")]
fn add_score(score: Json<Score>, conn: db::Conn) -> String {
let ok = score.0.insert(conn.handler());
Expand All @@ -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() {
Expand Down
22 changes: 0 additions & 22 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -26,22 +23,3 @@ impl Score {
.is_ok()
}
}

#[derive(Queryable, Insertable, Debug)]
pub struct Greeting {
pub id: Option<i32>,
pub text: String,
}

impl Greeting {
pub fn all(conn: &SqliteConnection) -> Vec<Greeting> {
all_greetings.load::<Greeting>(conn).unwrap()
}

pub fn insert(msg: Greeting, conn: &SqliteConnection) -> bool {
insert_into(greetings::table)
.values(msg)
.execute(conn)
.is_ok()
}
}

0 comments on commit 90300d5

Please sign in to comment.