diff --git a/Cargo.lock b/Cargo.lock index 1d86c8d..617f6c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1304,6 +1304,7 @@ dependencies = [ "env_logger", "log", "serde", + "serde_json", "sqlx", "tokio", "tower", diff --git a/Cargo.toml b/Cargo.toml index 75c6a2a..725f52f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ tokio = { version = "1.37.0", features = ["full"] } tower = { version = "0.4.13", features = [] } axum = "0.7.5" serde = "1.0.201" -# serde_json = "1.0.117" +serde_json = "1.0.117" # json-patch = "2.0.0" # serde_with = "3.8.1" diff --git a/src/engines/kv.rs b/src/engines/kv.rs index 441f951..777d001 100644 --- a/src/engines/kv.rs +++ b/src/engines/kv.rs @@ -9,7 +9,7 @@ pub mod db_structs; // mod tests; use std::{collections::HashMap, convert::Infallible}; - +use serde_json; use crate::{ engines::kv::http_structs::*, storage::DatabaseDriver, @@ -100,38 +100,38 @@ async fn post_data( // Insert Metadata first -> Else: Error because of foreign key constraint - // log::debug!( - // "Secret: {}, Content: {:?}, Version: {:?}, path: {}", - // path, - // payload.data, - // payload.options, - // path - // ); + log::debug!( + "Secret: {}, Content: {:?}, Version: {:?}, path: {}", + path, + payload.data, + payload.options, + path + ); - // let data = payload.data.get("data"); - // log::debug!("{:?}", data); - // let created_time = Utc::now(); - // let deletion_time = "05-03-2024 12:00:00"; // TODO: - // let version = "0"; - // match sqlx::query!( - // "INSERT INTO secret_versions VALUES ($1, $2, $3, $4, $5)", - // data, - // created_time, - // deletion_time, - // version, - // path - // ) - // .execute(&pool) - // .await - // { - // Ok(v) => { - // info!("{:?}", v); - // } - // Err(e) => { - // error!("{:?}", e); - // } - // } + let data = serde_json::to_string(&payload.data).unwrap(); + log::debug!("Received data: {:?}", data); + let created_time = Utc::now().to_string(); + let deletion_time = "12-12-2024 12:00:00"; // TODO: + let version = "1"; + match sqlx::query( + "INSERT INTO secret_versions VALUES ($1, $2, $3, $4, $5)", + ) + .bind(data) + .bind(created_time) + .bind (deletion_time) + .bind(version) + .bind(path) + .execute(&pool) + .await + { + Ok(v) => { + info!("{:?}", v); + } + Err(e) => { + error!("{:?}", e); + } + } todo!("not implemented") }