diff --git a/.DS_Store b/.DS_Store index 281020a..0eb346e 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Cargo.toml b/Cargo.toml index 62449cf..dd2765e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,6 @@ ring = "0.16.20" data-encoding = "2.3.2" futures-util = "0.3" actix-web-utils = "0.2" -log = { version = "0.4", features = ["serde"] } +#log = { version = "0.4", features = ["serde"] } -dev-dtos = { git = "https://franklinblanco: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@github.com/franklinblanco/user-svc-dtos-rust.git" } +dev-dtos = { git = "https://git.franklinblanco.dev/franklinblanco/dev-dtos.git" } diff --git a/migrations/1_user.sql b/migrations/1_user.sql index 01e33a3..c6aea2c 100644 --- a/migrations/1_user.sql +++ b/migrations/1_user.sql @@ -1,5 +1,5 @@ CREATE TABLE IF NOT EXISTS user ( - id INT AUTO_INCREMENT PRIMARY KEY, + id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, time_created DATETIME, last_updated DATETIME, app VARCHAR(255) NOT NULL, diff --git a/migrations/2_token.sql b/migrations/2_token.sql index 31e5157..c2ab33f 100644 --- a/migrations/2_token.sql +++ b/migrations/2_token.sql @@ -1,6 +1,6 @@ CREATE TABLE IF NOT EXISTS token ( - id INT AUTO_INCREMENT PRIMARY KEY, - user_id INT NOT NULL, + id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, + user_id INT UNSIGNED NOT NULL, time_created DATETIME, last_updated DATETIME, auth_token TEXT NOT NULL, diff --git a/src/dao/main_dao.rs b/src/dao/main_dao.rs index 982d710..b81267a 100644 --- a/src/dao/main_dao.rs +++ b/src/dao/main_dao.rs @@ -1,7 +1,7 @@ -use std::{collections::HashMap, str::FromStr, time::Duration}; +use std::{collections::HashMap, str::FromStr}; -use log::{LevelFilter, info}; -use sqlx::{MySqlPool, mysql::{MySqlConnectOptions, MySqlPoolOptions}, ConnectOptions}; +//use log::{LevelFilter, info}; +use sqlx::{MySqlPool, mysql::{MySqlConnectOptions, MySqlPoolOptions}}; pub async fn start_database_connection(env_vars: &HashMap) -> Result{ let db_url = match env_vars.get("DATABASE_URL") { @@ -9,14 +9,14 @@ pub async fn start_database_connection(env_vars: &HashMap) -> Re None => panic!("DATABASE_URL env var not found") }; let formatted_db_url = &db_url; - let mut options = MySqlConnectOptions::from_str(formatted_db_url)?; - options.log_slow_statements(LevelFilter::Warn, Duration::from_secs(1)) - .log_statements(LevelFilter::Trace); + let options = MySqlConnectOptions::from_str(formatted_db_url)?; + //options.log_slow_statements(LevelFilter::Warn, Duration::from_secs(1)) + //.log_statements(LevelFilter::Trace); MySqlPoolOptions::new().connect_with(options).await } pub async fn run_all_migrations(conn: &MySqlPool){ match sqlx::migrate!("./migrations").run(conn).await { - Ok(()) => {info!("Successfully ran migrations.")}, + Ok(()) => {println!("Successfully ran migrations.")}, Err(error) => {panic!("{error}")} } } \ No newline at end of file diff --git a/src/dao/token_dao.rs b/src/dao/token_dao.rs index 8062ebf..7bc3f92 100644 --- a/src/dao/token_dao.rs +++ b/src/dao/token_dao.rs @@ -5,7 +5,7 @@ use sqlx::{mysql::MySqlQueryResult}; pub async fn insert_token(conn: &MySqlPool, token: &Token) -> Result { sqlx::query_file!("sql/schema/token/insert.sql", token.user_id, token.auth_token, token.refresh_token).execute(conn).await } -pub async fn get_tokens_with_user_id(conn: &MySqlPool, user_id: &i32) -> Result, sqlx::Error> { +pub async fn get_tokens_with_user_id(conn: &MySqlPool, user_id: &u32) -> Result, sqlx::Error> { sqlx::query_file_as!(Token, "sql/schema/token/find_with_user_id.sql", user_id).fetch_all(conn).await } pub async fn update_token_with_id(conn: &MySqlPool, token: &Token ) -> Result { diff --git a/src/dao/user_dao.rs b/src/dao/user_dao.rs index 0486341..8662523 100644 --- a/src/dao/user_dao.rs +++ b/src/dao/user_dao.rs @@ -9,6 +9,6 @@ pub async fn insert_user(conn: &MySqlPool, user_to_insert: &User) -> Result Result{ sqlx::query_file_as!(User, "sql/schema/user/find_with_credential.sql", credential, credential_type, app).fetch_one(conn).await } -pub async fn find_user_by_id(conn: &MySqlPool, id: &i32) -> Result { +pub async fn find_user_by_id(conn: &MySqlPool, id: &u32) -> Result { sqlx::query_file_as!(User, "sql/schema/user/find_with_id.sql", id).fetch_one(conn).await } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index a888ba4..16b1eb8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ mod routes; mod service; mod util; mod dto; mod validation; mod resources; -use actix_web_utils::utils::logger_util::{self}; +//use actix_web_utils::utils::logger_util::{self}; use r#do::shared_state::SharedStateObj; use util::env_util; use routes::main_router::{start_all_routes, after_startup_fn}; @@ -14,7 +14,7 @@ use dao::{main_dao::{self, run_all_migrations}}; #[tokio::main] async fn main(){ - logger_util::init_logger_custom(2).expect("LOGGER FAILED TO LOAD"); + //logger_util::init_logger_custom(2).expect("LOGGER FAILED TO LOAD"); // Retrieve env variables and send to services that need them. let env_vars = env_util::get_dot_env_map(); diff --git a/src/routes/main_router.rs b/src/routes/main_router.rs index eeb1bd5..9a14b79 100644 --- a/src/routes/main_router.rs +++ b/src/routes/main_router.rs @@ -1,13 +1,12 @@ use std::sync::{Mutex, Arc}; use actix_web::{HttpServer, App, web, middleware::Logger}; -use log::info; use crate::{r#do::shared_state::SharedStateObj}; use super::user_routes; // This function is to be used in case code is meant to be run after server startup pub fn after_startup_fn() { - info!("Started server.") + println!("Started server.") } pub async fn start_all_routes(after_startup_fn_call: &dyn Fn(), state: SharedStateObj) diff --git a/src/routes/user_routes.rs b/src/routes/user_routes.rs index 08307f0..903934b 100644 --- a/src/routes/user_routes.rs +++ b/src/routes/user_routes.rs @@ -42,7 +42,7 @@ pub async fn create_user(incoming_user: web::Json, db_conn: // Insert user in DB match insert_user(&db_conn, &user_to_insert).await{ Ok(resultrs) => { - user_to_insert.id = resultrs.last_insert_id() as i32; + user_to_insert.id = resultrs.last_insert_id() as u32; }, Err(error) => { println!("Error while inserting user in database from create_user method. Log: {}", error); @@ -59,7 +59,7 @@ pub async fn create_user(incoming_user: web::Json, db_conn: // Insert token in DB match insert_token(&db_conn, &token_to_insert).await{ - Ok(resultrs) => {token_to_insert.id = resultrs.last_insert_id() as i32}, + Ok(resultrs) => {token_to_insert.id = resultrs.last_insert_id() as u32}, Err(_e) => {return HttpResponse::InternalServerError().finish()} } @@ -113,7 +113,7 @@ pub async fn authenticate_user_with_password(incoming_user: web::Json {token_to_insert.id = resultrs.last_insert_id() as i32}, + Ok(resultrs) => {token_to_insert.id = resultrs.last_insert_id() as u32}, Err(_) => { message_resources.push(MessageResourceDto::new_from_error_message(ERROR_CREATING_TOKEN)); return HttpResponse::InternalServerError().json(message_resources) @@ -126,7 +126,7 @@ pub async fn authenticate_user_with_password(incoming_user: web::Json, db_conn: Data>) -> HttpResponse{ +pub async fn authenticate_user_with_auth_token(request: HttpRequest, user_id: web::Path, db_conn: Data>) -> HttpResponse{ let mut message_resources: Vec = Vec::new(); let headers = request.headers(); let auth_token = match headers.get("auth-token") { @@ -181,7 +181,7 @@ pub async fn authenticate_user_with_auth_token(request: HttpRequest, user_id: we #[patch("/user/refresh/{user_id}")] -pub async fn refresh_auth_token(request: HttpRequest, user_id: web::Path, db_conn: Data>) -> HttpResponse{ +pub async fn refresh_auth_token(request: HttpRequest, user_id: web::Path, db_conn: Data>) -> HttpResponse{ let mut message_resources: Vec = Vec::new(); let headers = request.headers(); let refresh_token = match headers.get("refresh-token") {