started implementation on post_secret

This commit is contained in:
someone 2024-05-30 15:26:12 +02:00
parent 40b7e74088
commit 363cd11aa5
3 changed files with 33 additions and 32 deletions

1
Cargo.lock generated
View file

@ -1304,6 +1304,7 @@ dependencies = [
"env_logger",
"log",
"serde",
"serde_json",
"sqlx",
"tokio",
"tower",

View file

@ -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"

View file

@ -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")
}