bff-challenge/src/main.rs

49 lines
943 B
Rust
Raw Normal View History

2023-01-24 18:37:35 +00:00
#![feature(decl_macro)]
2023-01-25 18:45:04 +00:00
use rocket::{*, response::Redirect, form::Form};
2023-01-24 18:37:35 +00:00
use rocket_dyn_templates::{Template, context};
#[get("/create")]
2023-01-25 18:45:04 +00:00
fn begin_create() -> Template
2023-01-24 18:37:35 +00:00
{
2023-01-25 18:45:04 +00:00
Template::render("begin_create", context!{})
}
#[get("/create/<name>")]
fn create(name: &str) -> Template
{
Template::render("create", context!{
username: name
})
}
#[derive(FromForm)]
struct UserNameData<'r> {
pub username: &'r str,
}
#[post("/create", data = "<name>")]
fn create_post(name: Form<UserNameData<'_>>) -> Redirect
{
Redirect::to(uri!(create(name.username)))
2023-01-24 18:37:35 +00:00
}
#[get("/about")]
fn about() -> Template
{
Template::render("about", context!{})
}
#[get("/")]
fn index() -> Template
{
Template::render("index", context! {
2023-01-25 18:45:04 +00:00
create_uri: uri!(begin_create())
2023-01-24 18:37:35 +00:00
})
}
#[launch]
fn rocket() -> _ {
2023-01-25 18:45:04 +00:00
rocket::build().mount("/", routes![begin_create, create, create_post, index, about]).attach(Template::fairing())
2023-01-24 18:37:35 +00:00
}