Add a project creation form

This commit is contained in:
Nettika 2026-01-25 15:29:12 -08:00
parent 5911c11017
commit 895e61772f
No known key found for this signature in database
2 changed files with 28 additions and 1 deletions

View file

@ -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] 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.
[ ] 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.

View file

@ -24,6 +24,7 @@ fn main() {
rouille::Response::from_data("application/javascript", js.as_ref())
},
(GET) ["/projects"] => display_projects(),
(GET) ["/new-project"] => new_project_form(),
(POST) ["/projects"] => create_project(request),
_ => rouille::Response::empty_404()
)
@ -95,6 +96,32 @@ fn display_projects() -> rouille::Response {
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 {
let input = try_or_400!(rouille::post_input!(request, {
title: String,