Too many todos (lemon work)

This commit is contained in:
famfo 2022-05-13 16:24:13 +02:00
parent 8c82de3077
commit 0f5db2d2aa
3 changed files with 18 additions and 9 deletions

View file

@ -16,7 +16,7 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
use crate::templates;
use crate::{task, templates};
use argon2::Argon2;
use argon2::PasswordHasher;
use sqlx::postgres::{PgConnectOptions, PgConnectionInfo, PgPoolOptions};
@ -68,6 +68,14 @@ impl Database {
templates::Tasks { tasks: vec }
}
pub async fn create_task(&self, task: &task::CreateTask) {
// TODO: insert the task into the database
}
pub async fn move_task(&self, task: &task::MoveTask) {
// TODO: change the category of the task inside the db
}
fn hash(&self, password: &str) -> Result<String, ()> {
let argon2 = Argon2::default();
let hash = argon2.hash_password(password.as_bytes(), &self.1);

View file

@ -20,7 +20,6 @@ use askama::Template;
#[derive(Template)]
#[template(path = "task/task_page.html")]
pub struct Tasks {
pub tasks: Vec<Task>,
}
@ -36,15 +35,12 @@ pub struct Task {
#[derive(Template)]
#[template(path = "task/create_task.html")]
pub struct CreateTask();
#[derive(Template)]
#[template(path = "login.html")]
pub struct Login();
#[derive(Template)]
#[template(path = "register.html")]
pub struct Register();

View file

@ -43,9 +43,7 @@ impl App {
web::resource("/api/task/move")
.app_data(web::Data::new(db.clone()))
.route(web::post().to(move_task)),
web::resource("/api/task/sort")
.app_data(web::Data::new(db.clone()))
.route(web::post().to(sort_task)),
web::resource("/api/task/sort").route(web::post().to(sort_task)),
web::resource("/api/login")
.app_data(web::Data::new(db.clone()))
.route(web::post().to(login_user)),
@ -89,6 +87,9 @@ async fn create_task(
db: web::Data<Arc<Database>>,
) -> impl Responder {
tracing::debug!("Got POST request on /api/task/create: {:#?}", req);
let db = db.clone();
let task = req.into_inner();
db.create_task(&task).await;
HttpResponse::SeeOther()
.insert_header(("Location", "/task"))
.finish()
@ -96,13 +97,17 @@ async fn create_task(
async fn move_task(req: web::Form<task::MoveTask>, db: web::Data<Arc<Database>>) -> impl Responder {
tracing::debug!("Got POST request on /api/task/move: {:#?}", req);
let db = db.clone();
let task = req.into_inner();
db.move_task(&task).await;
HttpResponse::SeeOther()
.insert_header(("Location", "/task"))
.finish()
}
async fn sort_task(req: web::Form<task::SortTask>, db: web::Data<Arc<Database>>) -> impl Responder {
async fn sort_task(req: web::Form<task::SortTask>) -> impl Responder {
tracing::debug!("Got POST request on /api/task/sort: {:#?}", req);
// TODO: save selected categories in a cookie or something
HttpResponse::SeeOther()
.insert_header(("Location", "/task"))
.finish()