Add a project creation form
This commit is contained in:
parent
5911c11017
commit
895e61772f
2 changed files with 28 additions and 1 deletions
2
TODO.md
2
TODO.md
|
|
@ -9,4 +9,4 @@
|
||||||
[x] Using a Rouille router, create `GET /main.css` and `GET /project-card.js` endpoints that returns the relevant files. Use the include_bytes! macro.
|
[x] Using a Rouille router, create `GET /main.css` and `GET /project-card.js` endpoints that returns the relevant files. Use the include_bytes! macro.
|
||||||
[x] Create a `GET /projects` endpoint. Using Maud for markup generation, have this endpoint return an HTML page that shows all projects. Each project should be a `project-card` web component. Keep the page simple: no title or any buttons currently.
|
[x] Create a `GET /projects` endpoint. Using Maud for markup generation, have this endpoint return an HTML page that shows all projects. Each project should be a `project-card` web component. Keep the page simple: no title or any buttons currently.
|
||||||
[x] Create a `POST /projects` endpoint that accepts URL encoded data and creates a new project.
|
[x] Create a `POST /projects` endpoint that accepts URL encoded data and creates a new project.
|
||||||
[ ] Create a `GET /new-project` endpoint that returns a HTML page with a project creation form. Keep it simple.
|
[x] Create a `GET /new-project` endpoint that returns a HTML page with a project creation form. Keep it simple.
|
||||||
27
src/main.rs
27
src/main.rs
|
|
@ -24,6 +24,7 @@ fn main() {
|
||||||
rouille::Response::from_data("application/javascript", js.as_ref())
|
rouille::Response::from_data("application/javascript", js.as_ref())
|
||||||
},
|
},
|
||||||
(GET) ["/projects"] => display_projects(),
|
(GET) ["/projects"] => display_projects(),
|
||||||
|
(GET) ["/new-project"] => new_project_form(),
|
||||||
(POST) ["/projects"] => create_project(request),
|
(POST) ["/projects"] => create_project(request),
|
||||||
_ => rouille::Response::empty_404()
|
_ => rouille::Response::empty_404()
|
||||||
)
|
)
|
||||||
|
|
@ -95,6 +96,32 @@ fn display_projects() -> rouille::Response {
|
||||||
rouille::Response::html(markup.into_string())
|
rouille::Response::html(markup.into_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn new_project_form() -> rouille::Response {
|
||||||
|
let markup = html! {
|
||||||
|
(DOCTYPE)
|
||||||
|
html {
|
||||||
|
head {
|
||||||
|
meta charset="utf-8";
|
||||||
|
meta name="viewport" content="width=device-width, initial-scale=1";
|
||||||
|
link rel="stylesheet" href="/main.css";
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
main {
|
||||||
|
h1 { "New Project" }
|
||||||
|
form method="POST" action="/projects" {
|
||||||
|
label for="title" { "Project Title:" }
|
||||||
|
input type="text" id="title" name="title" required;
|
||||||
|
button type="submit" { "Create Project" }
|
||||||
|
}
|
||||||
|
a href="/projects" { "Cancel" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
rouille::Response::html(markup.into_string())
|
||||||
|
}
|
||||||
|
|
||||||
fn create_project(request: &rouille::Request) -> rouille::Response {
|
fn create_project(request: &rouille::Request) -> rouille::Response {
|
||||||
let input = try_or_400!(rouille::post_input!(request, {
|
let input = try_or_400!(rouille::post_input!(request, {
|
||||||
title: String,
|
title: String,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue