Split db::Connection implementation in submodules (db::user and db::recipe).

This commit is contained in:
Greg Burri 2024-12-18 23:10:19 +01:00
parent 4248d11aa9
commit fce4eade73
17 changed files with 1307 additions and 1234 deletions

View file

@ -15,7 +15,7 @@ use config::Config;
use tower_http::{services::ServeDir, trace::TraceLayer};
use tracing::{event, Level};
use data::db;
use data::{db, model};
mod config;
mod consts;
@ -23,7 +23,6 @@ mod data;
mod email;
mod hash;
mod html_templates;
mod model;
mod ron_extractor;
mod ron_utils;
mod services;
@ -111,6 +110,8 @@ async fn main() {
get(services::reset_password_get).post(services::reset_password_post),
)
// Recipes.
.route("/recipe/new", get(services::create_recipe))
// .route("/recipe/edit/:id", get(services::edit_recipe))
.route("/recipe/view/:id", get(services::view_recipe))
// User.
.route(
@ -163,8 +164,8 @@ async fn get_current_user(
.authentication(token_cookie.value(), &client_ip, &client_user_agent)
.await
{
Ok(db::AuthenticationResult::NotValidToken) => None,
Ok(db::AuthenticationResult::Ok(user_id)) => {
Ok(db::user::AuthenticationResult::NotValidToken) => None,
Ok(db::user::AuthenticationResult::Ok(user_id)) => {
match connection.load_user(user_id).await {
Ok(user) => user,
Err(error) => {
@ -227,7 +228,7 @@ async fn process_args() -> bool {
// Set the creation datetime to 'now'.
con.execute_sql(
sqlx::query(
"UPDATE [User] SET [creation_datetime] = ?1 WHERE [email] = 'paul@test.org'")
"UPDATE [User] SET [validation_token_datetime] = $1 WHERE [email] = 'paul@test.org'")
.bind(Utc::now())
)
.await