Still missing some fields
This commit is contained in:
parent
d7562a0947
commit
935919b70a
2
build.rs
2
build.rs
|
@ -1,6 +1,6 @@
|
||||||
|
use serde::Deserialize;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::task;
|
use crate::task;
|
||||||
|
use blake2::{Blake2b512, Digest};
|
||||||
use sqlx::postgres::{PgConnectOptions, PgConnectionInfo, PgPoolOptions};
|
use sqlx::postgres::{PgConnectOptions, PgConnectionInfo, PgPoolOptions};
|
||||||
use sqlx::Executor;
|
use sqlx::Executor;
|
||||||
use sqlx::{ConnectOptions, PgPool};
|
use sqlx::{ConnectOptions, PgPool};
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
use tracing::log::LevelFilter;
|
use tracing::log::LevelFilter;
|
||||||
use blake2::{Blake2b512, Digest};
|
|
||||||
|
|
||||||
pub struct Database(PgPool);
|
pub struct Database(PgPool);
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ impl Database {
|
||||||
)
|
)
|
||||||
.fetch_one(&self.0)
|
.fetch_one(&self.0)
|
||||||
.await?;
|
.await?;
|
||||||
return Ok(user.id)
|
return Ok(user.id);
|
||||||
}
|
}
|
||||||
Err(anyhow::anyhow!("Username is longer then 16 characters"))
|
Err(anyhow::anyhow!("Username is longer then 16 characters"))
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ impl Database {
|
||||||
.await;
|
.await;
|
||||||
if let Ok(user) = user {
|
if let Ok(user) = user {
|
||||||
if user.hash == hash {
|
if user.hash == hash {
|
||||||
return Ok(user.id))
|
return Ok(user.id);
|
||||||
} else {
|
} else {
|
||||||
return Err(anyhow::anyhow!("Passwords do not match."));
|
return Err(anyhow::anyhow!("Passwords do not match."));
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,6 @@ impl Database {
|
||||||
Err(anyhow::anyhow!("Could not find user {}.", login.username))
|
Err(anyhow::anyhow!("Could not find user {}.", login.username))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Async might become a problem here
|
|
||||||
pub fn get_tasks(&self) -> Vec<task::Task> {
|
pub fn get_tasks(&self) -> Vec<task::Task> {
|
||||||
// TODO: actually get the issues from the db
|
// TODO: actually get the issues from the db
|
||||||
vec![task::Task {
|
vec![task::Task {
|
||||||
|
@ -110,7 +109,46 @@ impl Database {
|
||||||
// TODO: move the task to the desired category
|
// TODO: move the task to the desired category
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_task(&self, task: task::Create) {
|
pub async fn create_task(
|
||||||
// TODO: insert the task into the db
|
&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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ create table if not exists tasks(
|
||||||
title varchar(128) not null,
|
title varchar(128) not null,
|
||||||
description varchar(32768) not null,
|
description varchar(32768) not null,
|
||||||
author integer references users(id) not null,
|
author integer references users(id) not null,
|
||||||
|
assignee integer references users(id),
|
||||||
category integer not null references categories(id) on delete cascade,
|
category integer not null references categories(id) on delete cascade,
|
||||||
org integer not null references org(id) on delete cascade,
|
org integer not null references org(id) on delete cascade,
|
||||||
status integer not null references status(id) on delete cascade,
|
status integer not null references status(id) on delete cascade,
|
||||||
|
|
|
@ -32,7 +32,6 @@ pub struct MoveRequest {
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct Create {
|
pub struct Create {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub status: String,
|
|
||||||
pub assignee: String,
|
pub assignee: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
}
|
}
|
||||||
|
@ -52,4 +51,3 @@ pub struct Register {
|
||||||
pub username: String,
|
pub username: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
src/web.rs
15
src/web.rs
|
@ -221,22 +221,33 @@ pub async fn post_task_sort(form: task::SortRequest, db: Arc<Database>) -> impl
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn post_task_create(form: task::Create, db: Arc<Database>) -> impl warp::Reply {
|
pub async fn post_task_create(form: task::Create, db: Arc<Database>) -> 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()
|
let date = SystemTime::now()
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
tracing::debug!("Got POST on /api/task/create: {:?}, date: {:?}", form, date);
|
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"))
|
warp::redirect(warp::http::Uri::from_static("/task"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn register(form: task::Register, db: Arc<Database>) -> impl warp::Reply {
|
pub async fn register(form: task::Register, db: Arc<Database>) -> impl warp::Reply {
|
||||||
if let Err(e) = db.create_user(form).await {
|
if let Err(e) = db.create_user(form).await {
|
||||||
|
tracing::error!("{}", e);
|
||||||
return warp::redirect(warp::http::Uri::from_static("/register"));
|
return warp::redirect(warp::http::Uri::from_static("/register"));
|
||||||
}
|
}
|
||||||
warp::redirect(warp::http::Uri::from_static("/task"))
|
warp::redirect(warp::http::Uri::from_static("/task"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn login(form: task::Register, db: Arc<Database>) -> impl warp::Reply {
|
pub async fn login(form: task::Register, db: Arc<Database>) -> 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"))
|
warp::redirect(warp::http::Uri::from_static("/task"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,6 @@
|
||||||
<label for="title">Title</label><br>
|
<label for="title">Title</label><br>
|
||||||
<input type="text" id="title" name="title" style="width:fit-content"><br>
|
<input type="text" id="title" name="title" style="width:fit-content"><br>
|
||||||
|
|
||||||
<label for="status">Status</label><br>
|
|
||||||
<select name="status" id="status">
|
|
||||||
<option value="ideas">ideas</option>
|
|
||||||
<option value="assigned">assigned</option>
|
|
||||||
<option value="in-progress">in progreess</option>
|
|
||||||
<option value="done">done</option>
|
|
||||||
</select><br>
|
|
||||||
|
|
||||||
<label for="assignee">Assignee</label><br>
|
<label for="assignee">Assignee</label><br>
|
||||||
<input type="text" id="assignee" name="assignee"><br>
|
<input type="text" id="assignee" name="assignee"><br>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue