Sign up method.
[recipes.git] / backend / src / main.rs
index 5c6de4c..1fbfbc5 100644 (file)
@@ -4,13 +4,15 @@ use std::sync::Mutex;
 use actix_files as fs;
 use actix_web::{get, web, Responder, middleware, App, HttpServer, HttpRequest};
 use askama_actix::Template;
+use chrono::prelude::*;
 use clap::Parser;
 use ron::de::from_reader;
 use serde::Deserialize;
 
 mod consts;
-mod model;
 mod db;
+mod hash;
+mod model;
 
 #[derive(Template)]
 #[template(path = "home.html")]
@@ -98,16 +100,26 @@ async fn main() -> std::io::Result<()> {
 #[derive(Parser, Debug)]
 struct Args {
     #[arg(long)]
-    test: bool
+    dbtest: bool
 }
 
 fn process_args() -> bool {
     let args = Args::parse();
 
-    if args.test {
-        if let Err(error) = db::Connection::new() {
-            println!("Error: {:?}", error)
+    if args.dbtest {
+        match db::Connection::new() {
+            Ok(con) => {
+                if let Err(error) = con.execute_file("sql/data_test.sql") {
+                    println!("Error: {:?}", error);
+                }
+                // Set the creation datetime to 'now'.
+                con.execute_sql("UPDATE [User] SET [creation_datetime] = ?1 WHERE [email] = 'paul@test.org'", [Utc::now()]).unwrap();
+            },
+            Err(error) => {
+                println!("Error: {:?}", error)
+            },
         }
+
         return true;
     }