|
|
@ -2,7 +2,6 @@ |
|
|
|
#[macro_use] |
|
|
|
#[macro_use] |
|
|
|
extern crate rocket; |
|
|
|
extern crate rocket; |
|
|
|
|
|
|
|
|
|
|
|
use rocket::request::Form; |
|
|
|
|
|
|
|
use rocket::response::content::Html; |
|
|
|
use rocket::response::content::Html; |
|
|
|
use rocket::response::Redirect; |
|
|
|
use rocket::response::Redirect; |
|
|
|
|
|
|
|
|
|
|
@ -30,38 +29,23 @@ fn index(session: Session) -> Html<String> { |
|
|
|
<ul> |
|
|
|
<ul> |
|
|
|
"#, |
|
|
|
"#, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
session.tap(|sess| { |
|
|
|
session.tap(|sess| { |
|
|
|
for (n, dog) in sess.iter().enumerate() { |
|
|
|
for (n, dog) in sess.iter().enumerate() { |
|
|
|
page.push_str(&format!( |
|
|
|
page.push_str(&format!( |
|
|
|
r#" |
|
|
|
r#"<li>🐶 {} <a href="/remove/{}">Remove</a></li>"#, |
|
|
|
<li>🐶 {} <a href="/remove/{}">Remove</a></li> |
|
|
|
|
|
|
|
"#, |
|
|
|
|
|
|
|
dog, n |
|
|
|
dog, n |
|
|
|
)); |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
page.push_str("</ul>"); |
|
|
|
page.push_str( |
|
|
|
|
|
|
|
r#" |
|
|
|
|
|
|
|
</ul> |
|
|
|
|
|
|
|
"#, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Html(page) |
|
|
|
Html(page) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[derive(FromForm)] |
|
|
|
|
|
|
|
struct AddForm { |
|
|
|
|
|
|
|
name: String, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[post("/add", data = "<dog>")] |
|
|
|
#[post("/add", data = "<dog>")] |
|
|
|
fn add(session: Session, dog: Form<AddForm>) -> Redirect { |
|
|
|
fn add(session: Session, dog: String) -> Redirect { |
|
|
|
session.tap(move |sess| { |
|
|
|
session.tap(move |sess| { |
|
|
|
sess.push(dog.into_inner().name); |
|
|
|
sess.push(dog); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Redirect::found("/") |
|
|
|
Redirect::found("/") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -72,6 +56,5 @@ fn remove(session: Session, dog: usize) -> Redirect { |
|
|
|
sess.remove(dog); |
|
|
|
sess.remove(dog); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Redirect::found("/") |
|
|
|
Redirect::found("/") |
|
|
|
} |
|
|
|
} |
|
|
|