From 44d920f6eaafcd39f737cf3cc643b717fc322702 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Tue, 15 Feb 2022 22:56:29 +0530 Subject: [PATCH] feat: implement serialization and deserialiation for Gist, GIstPrivacy and GistComments in db_core --- Cargo.lock | 2 ++ database/db-core/Cargo.toml | 4 ++++ database/db-core/src/lib.rs | 9 ++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7700c85..14f7f02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -683,6 +683,8 @@ name = "db-core" version = "0.1.0" dependencies = [ "async-trait", + "serde 1.0.136", + "serde_json", "thiserror", ] diff --git a/database/db-core/Cargo.toml b/database/db-core/Cargo.toml index f64f4fd..f45f52a 100644 --- a/database/db-core/Cargo.toml +++ b/database/db-core/Cargo.toml @@ -15,7 +15,11 @@ authors = ["realaravinth "] [dependencies] async-trait = "0.1.51" thiserror = "1.0.30" +serde = { version = "1", features = ["derive"]} [features] default = [] test = [] + +[dev-dependencies] +serde_json = "1" diff --git a/database/db-core/src/lib.rs b/database/db-core/src/lib.rs index f97fc9b..bf24ea7 100644 --- a/database/db-core/src/lib.rs +++ b/database/db-core/src/lib.rs @@ -14,6 +14,8 @@ //! - [errors](crate::auth): error data structures used in this crate //! - [ops](crate::ops): meta operations like connection pool creation, migrations and getting //! connection from pool +use serde::{Deserialize, Serialize}; + pub mod errors; pub mod ops; #[cfg(feature = "test")] @@ -66,7 +68,8 @@ pub struct CreateGist<'a> { } /// Gist visibility -#[derive(Clone, PartialEq, Debug)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] pub enum GistVisibility { /// Everyone can see the gist, will be displayed on /explore and /// search engines might index it too @@ -109,7 +112,7 @@ impl From for String { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] /// Represents a gist pub struct Gist { /// owner of the gist @@ -126,7 +129,7 @@ pub struct Gist { pub visibility: GistVisibility, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] /// Represents a comment on a Gist pub struct GistComment { /// Unique identifier, possible database assigned, auto-incremented ID