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::fs;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Deserialize)]
|
||||
|
|
|
@ -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<task::Task> {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
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 {
|
||||
// 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<Database>) -> 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<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"))
|
||||
}
|
||||
|
|
|
@ -8,14 +8,6 @@
|
|||
<label for="title">Title</label><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>
|
||||
<input type="text" id="assignee" name="assignee"><br>
|
||||
|
||||
|
|
Loading…
Reference in a new issue