diff --git a/src/task.rs b/src/task.rs index 5b94dc2..1a426fb 100644 --- a/src/task.rs +++ b/src/task.rs @@ -20,38 +20,23 @@ use serde::{Deserialize, Serialize}; #[derive(Deserialize)] pub struct Request { - r#move: String, + pub r#move: String, +} + +#[derive(Debug, Deserialize)] +pub struct Create { + pub title: String, + pub status: String, + pub assignee: String, + pub description: String, } #[derive(Debug, Serialize)] pub struct Task { - title: String, - date: String, - status: String, - assignee: String, - description: String, + pub title: String, + pub date: String, + pub status: String, + pub assignee: String, + pub description: String, } -impl Task { - pub fn new( - title: String, - date: String, - status: String, - assignee: String, - description: String, - ) -> Task { - Task { - title, - date, - status, - assignee, - description, - } - } -} - -pub async fn handle_post(form: Request) -> impl warp::Reply { - // TODO: intelligent SQL code here (or maybe in another function idk, it's up to the reader to - // decide whats more intelligent) - warp::redirect(warp::http::Uri::from_static("/tmtd")) -} diff --git a/src/web.rs b/src/web.rs index 07940f8..09417e2 100644 --- a/src/web.rs +++ b/src/web.rs @@ -26,6 +26,7 @@ use tokio::sync::broadcast; use tracing::info; use warp::Filter; use warp_sessions::{CookieOptions, SameSiteCookieOption, SessionWithStore}; +use std::time::SystemTime; use crate::{task, Config, Database}; @@ -134,26 +135,43 @@ impl App { move || { let mut ctx = Context::new(); let mut tasks = Vec::new(); - for _ in 0..3 { - let task_ctx = task::Task::new( - "TODO".to_string(), - "TODO".to_string(), - "TODO".to_string(), - "TODO".to_string(), - "TODO".to_string(), - ); + for _ in 0..10 { + let task_ctx = task::Task { + date: "TODO".to_string(), + assignee: "TODO".to_string(), + description: "TODO".to_string(), + status: "TODO".to_string(), + title: "TODO".to_string(), + }; tasks.push(task_ctx); } ctx.insert("tasks", &tasks); - tracing::debug!("{:?}", tasks); warp::reply::html(tera.render("task_page.html", &ctx).unwrap()) } })) + .or(warp::path("task") + .and(warp::path("create")) + .map({ + let tera = self.tera.clone(); + move || { + let ctx = Context::new(); + warp::reply::html(tera.render("create_task.html", &ctx).unwrap()) + } + })) .or(warp::post() .and(warp::path("api")) - .and(warp::path("issues")) + .and(warp::path("task")) + .and(warp::path("move")) .and(warp::body::form::()) - .then(task::handle_post)); + .then(handle_post) + ) + .or(warp::post() + .and(warp::path("api")) + .and(warp::path("task")) + .and(warp::path("create")) + .and(warp::body::form::()) + .then(handle_post_create) + ); let (_, server) = warp::serve(route).bind_with_graceful_shutdown(self.config.listen_addr, async move { @@ -163,3 +181,17 @@ impl App { info!("Web app has been shut down"); } } + +pub async fn handle_post(form: task::Request) -> impl warp::Reply { + // TODO: intelligent SQL code here (or maybe in another function idk, it's up to the reader to + // decide whats more intelligent) + tracing::debug!("Got POST on /api/task/move: {}", form.r#move); + warp::redirect(warp::http::Uri::from_static("/")) +} + +pub async fn handle_post_create(form: task::Create)-> impl warp::Reply { + let date = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap(); + tracing::debug!("Got POST on /api/task/create: {:?}, date: {:?}", form, date); + warp::redirect(warp::http::Uri::from_static("/")) +} + diff --git a/templates/base.html b/templates/base.html index 3b559a3..c1a40dd 100644 --- a/templates/base.html +++ b/templates/base.html @@ -3,8 +3,33 @@ tmtd + {% block content %} {% endblock %} - \ No newline at end of file + diff --git a/templates/create_task.html b/templates/create_task.html new file mode 100644 index 0000000..ae62135 --- /dev/null +++ b/templates/create_task.html @@ -0,0 +1,35 @@ +{% extends "base.html" %} + +{% block content %} + +logo or something
+navbar
+ +tasks | +users | +(admin panel) + +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + +{% endblock content %} diff --git a/templates/form.css b/templates/form.css new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/templates/form.css @@ -0,0 +1 @@ + diff --git a/templates/task.html b/templates/task.html index d07867d..e1ae8f4 100644 --- a/templates/task.html +++ b/templates/task.html @@ -10,9 +10,9 @@ {{task.description}}
-
- - diff --git a/templates/task_page.html b/templates/task_page.html index 78d7185..00137d0 100644 --- a/templates/task_page.html +++ b/templates/task_page.html @@ -10,8 +10,10 @@ navbar
(admin panel)
+Create issue

+ -