diff --git a/crates/oxidetalis/src/schemas/user.rs b/crates/oxidetalis/src/schemas/user.rs index 321ce28..dd90f09 100644 --- a/crates/oxidetalis/src/schemas/user.rs +++ b/crates/oxidetalis/src/schemas/user.rs @@ -14,7 +14,11 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +use std::str::FromStr; + +use chrono::{DateTime, Utc}; use oxidetalis_core::{cipher::K256Secret, types::PublicKey}; +use oxidetalis_entities::prelude::*; use salvo::oapi::ToSchema; use serde::{Deserialize, Serialize}; @@ -25,3 +29,30 @@ pub struct RegisterUserBody { /// The public key of the user pub public_key: PublicKey, } + +#[derive(Serialize, Deserialize, Clone, Debug, ToSchema, derive_new::new)] +#[salvo(schema(name = WhiteListedUser, example = json!(WhiteListedUser::default())))] +pub struct WhiteListedUser { + /// User's public key + pub public_key: PublicKey, + /// When the user was whitelisted + pub whitelisted_at: DateTime, +} + +impl Default for WhiteListedUser { + fn default() -> Self { + WhiteListedUser::new( + PublicKey::from_str("bYhbrm61ov8GLZfskUYbsCLJTfaacMsuTBYgBABEH9dy").expect("is valid"), + Utc::now(), + ) + } +} + +impl From for WhiteListedUser { + fn from(user: WhitelistModel) -> Self { + Self { + public_key: PublicKey::from_str(&user.target).expect("Is valid public key"), + whitelisted_at: user.whitelisted_at, + } + } +}