Add project creation endpoint
This commit is contained in:
parent
8c4691e8bf
commit
497144029e
2 changed files with 14 additions and 2 deletions
14
src/main.rs
14
src/main.rs
|
|
@ -1,5 +1,5 @@
|
|||
use maud::{DOCTYPE, html};
|
||||
use rouille::router;
|
||||
use rouille::{router, try_or_400};
|
||||
|
||||
mod db;
|
||||
mod project;
|
||||
|
|
@ -24,6 +24,7 @@ fn main() {
|
|||
rouille::Response::from_data("application/javascript", js.as_ref())
|
||||
},
|
||||
(GET) ["/projects"] => display_projects(),
|
||||
(POST) ["/projects"] => create_project(request),
|
||||
_ => rouille::Response::empty_404()
|
||||
)
|
||||
});
|
||||
|
|
@ -93,3 +94,14 @@ fn display_projects() -> rouille::Response {
|
|||
|
||||
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,
|
||||
}));
|
||||
|
||||
match db::create_project(input.title) {
|
||||
Ok(_) => rouille::Response::redirect_302("/projects"),
|
||||
Err(_) => rouille::Response::text("Failed to create project").with_status_code(500),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
todo.md
2
todo.md
|
|
@ -8,5 +8,5 @@
|
|||
[x] Create a `project-card.js` file in src that creates a web component for displaying a project.
|
||||
[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.
|
||||
[ ] 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.
|
||||
Loading…
Add table
Add a link
Reference in a new issue