diff --git a/build.rs b/build.rs index 021f16d..51e55b2 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,6 @@ +use serde::Deserialize; use std::env; use std::fs; -use serde::Deserialize; #[allow(dead_code)] #[derive(Deserialize)] diff --git a/src/database.rs b/src/database.rs index a9a31fb..9bbad72 100644 --- a/src/database.rs +++ b/src/database.rs @@ -17,12 +17,12 @@ */ use crate::task; +use blake2::{Blake2b512, Digest}; use sqlx::postgres::{PgConnectOptions, PgConnectionInfo, PgPoolOptions}; use sqlx::Executor; use sqlx::{ConnectOptions, PgPool}; use tracing::info; use tracing::log::LevelFilter; -use blake2::{Blake2b512, Digest}; pub struct Database(PgPool); @@ -66,7 +66,7 @@ impl Database { ) .fetch_one(&self.0) .await?; - return Ok(user.id) + return Ok(user.id); } Err(anyhow::anyhow!("Username is longer then 16 characters")) } @@ -84,7 +84,7 @@ impl Database { .await; if let Ok(user) = user { if user.hash == hash { - return Ok(user.id)) + return Ok(user.id); } else { return Err(anyhow::anyhow!("Passwords do not match.")); } @@ -92,7 +92,6 @@ impl Database { Err(anyhow::anyhow!("Could not find user {}.", login.username)) } - // Async might become a problem here pub fn get_tasks(&self) -> Vec { // TODO: actually get the issues from the db vec![task::Task { @@ -110,7 +109,46 @@ impl Database { // TODO: move the task to the desired category } - pub async fn create_task(&self, task: task::Create) { - // TODO: insert the task into the db + pub async fn create_task( + &self, + task: task::Create, + author_id: i32, + category_id: i32, + org_id: i32, + status_id: i32, + created: sqlx::types::chrono::NaiveDateTime, + ) { + let tasks = sqlx::query!( + "INSERT INTO tasks ( + title, + description, + author, + category, + org, + status, + created + ) + VALUES ( + $1::Varchar, + $2::Varchar, + $3::Integer, + $4::Integer, + $5::Integer, + $6::Integer, + $7::Timestamp + )", + task.title, + task.description, + author_id, + category_id, + org_id, + status_id, + created, + ) + .execute(&self.0) + .await; + if let Err(tasks) = tasks { + tracing::error!("{}", tasks); + } } } diff --git a/src/sql/schema.sql b/src/sql/schema.sql index 6ff34f2..2a35c4d 100644 --- a/src/sql/schema.sql +++ b/src/sql/schema.sql @@ -45,6 +45,7 @@ create table if not exists tasks( title varchar(128) not null, description varchar(32768) not null, author integer references users(id) not null, + assignee integer references users(id), category integer not null references categories(id) on delete cascade, org integer not null references org(id) on delete cascade, status integer not null references status(id) on delete cascade, diff --git a/src/task.rs b/src/task.rs index 3d4726f..29d2c40 100644 --- a/src/task.rs +++ b/src/task.rs @@ -32,7 +32,6 @@ pub struct MoveRequest { #[derive(Debug, Deserialize)] pub struct Create { pub title: String, - pub status: String, pub assignee: String, pub description: String, } @@ -52,4 +51,3 @@ pub struct Register { pub username: String, pub password: String, } - diff --git a/src/web.rs b/src/web.rs index c8ee040..b2e50d2 100644 --- a/src/web.rs +++ b/src/web.rs @@ -221,22 +221,33 @@ pub async fn post_task_sort(form: task::SortRequest, db: Arc) -> impl } pub async fn post_task_create(form: task::Create, db: Arc) -> impl warp::Reply { + // TODO: get additional information from for example cookies + // Values still required: + // author_id + // category_id + // org_id + // status_id + // TODO: convert to sqlx::types::chrono::NaiveDateTime let date = SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .unwrap(); tracing::debug!("Got POST on /api/task/create: {:?}, date: {:?}", form, date); - db.create_task(form).await; + //db.create_task(form).await; warp::redirect(warp::http::Uri::from_static("/task")) } pub async fn register(form: task::Register, db: Arc) -> impl warp::Reply { if let Err(e) = db.create_user(form).await { + tracing::error!("{}", e); return warp::redirect(warp::http::Uri::from_static("/register")); } warp::redirect(warp::http::Uri::from_static("/task")) } pub async fn login(form: task::Register, db: Arc) -> impl warp::Reply { - db.login(form).await.unwrap(); + if let Err(e) = db.login(form).await { + tracing::error!("{}", e); + return warp::redirect(warp::http::Uri::from_static("/login")); + } warp::redirect(warp::http::Uri::from_static("/task")) } diff --git a/templates/task/create_task.html b/templates/task/create_task.html index 9cbc1f4..e819506 100644 --- a/templates/task/create_task.html +++ b/templates/task/create_task.html @@ -8,14 +8,6 @@

-
-
-