A PLC Mirror written in Rust

move PlcExportEntry into types and rename, can reuse for /log/audit

+14 -14
+3 -14
src/import.rs
··· 1 - use crate::types::PlcOperationType; 1 + use crate::types::{PlcEntry, PlcOperationType}; 2 2 use crate::utils::*; 3 3 use chrono::{DateTime, Utc}; 4 4 use deadpool_postgres::{Object, Pool}; ··· 62 62 client: &Client, 63 63 plc: &str, 64 64 after: Option<String>, 65 - ) -> eyre::Result<(Vec<PlcExportEntry>, Vec<serde_json::Error>)> { 65 + ) -> eyre::Result<(Vec<PlcEntry>, Vec<serde_json::Error>)> { 66 66 let mut uri = format!("{plc}/export?count=1000"); 67 67 if let Some(after) = after { 68 68 uri += format!("&after={}", after).as_str(); ··· 91 91 (oks, errors) 92 92 } 93 93 94 - async fn insert_did_and_op(conn: &Object, entry: &PlcExportEntry) -> eyre::Result<()> { 94 + async fn insert_did_and_op(conn: &Object, entry: &PlcEntry) -> eyre::Result<()> { 95 95 let insert_did_stmt = INSERT_DID_STMT 96 96 .get_or_init(|| init_insert_did_stmt(conn)) 97 97 .await; ··· 150 150 .await 151 151 .unwrap() 152 152 } 153 - 154 - #[derive(Debug, Deserialize, Serialize)] 155 - #[serde(rename_all = "camelCase")] 156 - pub struct PlcExportEntry { 157 - pub did: String, 158 - pub operation: PlcOperationType, 159 - #[serde(deserialize_with = "cid_de_string")] 160 - pub cid: Cid, 161 - pub nullified: bool, 162 - pub created_at: DateTime<Utc>, 163 - }
+11
src/types.rs
··· 6 6 use std::borrow::Cow; 7 7 use std::collections::HashMap; 8 8 use std::fmt::{Debug, Display}; 9 + use chrono::{DateTime, Utc}; 9 10 10 11 const DID_DOC_JSONLD_CTX: &[&str] = &[ 11 12 "https://www.w3.org/ns/did/v1", ··· 58 59 #[serde(rename = "type")] 59 60 pub ty: String, 60 61 pub endpoint: String, 62 + } 63 + 64 + #[derive(Debug, JsonSchema, Deserialize, Serialize)] 65 + #[serde(rename_all = "camelCase")] 66 + pub struct PlcEntry { 67 + pub did: String, 68 + pub operation: PlcOperationType, 69 + pub cid: JsonCid, 70 + pub nullified: bool, 71 + pub created_at: DateTime<Utc>, 61 72 } 62 73 63 74 #[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash, Deserialize, Serialize)]