Deprecate body_to_json: Use Axum Json Extractor instead
This commit is contained in:
parent
3447a9f4ff
commit
7e361cf940
2 changed files with 12 additions and 0 deletions
|
|
@ -61,6 +61,7 @@ async fn get_data(
|
|||
Ok(v) => {
|
||||
let version: i64 = v.get("version_number");
|
||||
let secret_content: HashMap<String, String> = HashMap::from([
|
||||
// TODO: use sqlx to parse the row to a struct, do not do it manually
|
||||
("secret_data".to_string(), v.get("secret_data")),
|
||||
("created_time".to_string(), v.get("created_time")),
|
||||
("deletion_time".to_string(), v.get("deletion_time")),
|
||||
|
|
|
|||
|
|
@ -4,26 +4,33 @@ use super::structs::*;
|
|||
|
||||
// TODO create default function
|
||||
|
||||
#[deprecated(note = "Use Axum functionality with structs instead, also, this should be inlined if it is actually needed")]
|
||||
/// serialize secret to JSON String
|
||||
pub fn serialize_secret_json(secret: &KvSecretReq) -> Result<String, serde_json::Error> {
|
||||
serde_json::to_string(&secret)
|
||||
}
|
||||
|
||||
#[deprecated(note = "Use Axum functionality with structs instead, also, this should be inlined if it is actually needed")]
|
||||
/// deserialize JSON String to secret
|
||||
pub fn deserialize_secret_struct(raw: &String) -> Result<KvSecretReq, serde_json::Error> {
|
||||
serde_json::from_str(raw)
|
||||
}
|
||||
|
||||
#[deprecated(note = "Use Axum functionality with structs instead, also, this should be inlined if it is actually needed")]
|
||||
/// serialize metadata to JSON String
|
||||
pub fn serialize_metadata_json(secret: &SecretMeta) -> Result<String, serde_json::Error> {
|
||||
serde_json::to_string(&secret)
|
||||
}
|
||||
|
||||
#[deprecated(note = "Use Axum functionality with structs instead, also, this should be inlined if it is actually needed")]
|
||||
/// deserialize JSON String to metadata
|
||||
pub fn deserialize_metadata_struct(raw: &String) -> Result<SecretMeta, serde_json::Error> {
|
||||
serde_json::from_str(raw)
|
||||
}
|
||||
|
||||
#[deprecated(note = "Propably not needed (remove deprecation if actually needed)")]
|
||||
/// Consider:
|
||||
/// Instead of patching JSON, we should apply the modified fields directly to the database
|
||||
pub fn patch_metadata(
|
||||
old: &mut SecretMeta,
|
||||
new: &SecretMeta,
|
||||
|
|
@ -34,7 +41,11 @@ pub fn patch_metadata(
|
|||
serde_json::from_value(patch)
|
||||
}
|
||||
|
||||
#[deprecated(note = "DO NOT USE: Use Axum extractors to structs instead")]
|
||||
#[allow(unreachable_code, unused_variables)]
|
||||
/// See [JSON extractor documentation](https://docs.rs/axum/latest/axum/struct.Json.html#extractor-example)
|
||||
pub fn body_to_json(body: String) -> Value {
|
||||
todo!("REMOVE: Use Axum extractors to structs instead");
|
||||
match serde_json::from_str::<serde_json::Value>(body.as_str()) {
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue