feat: Create WhiteListedUser schema

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb 2024-07-16 15:38:49 +03:00
parent 89b3c09181
commit b02e2d8b4d
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F

View file

@ -14,7 +14,11 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://gnu.org/licenses/agpl-3.0>. // along with this program. If not, see <https://gnu.org/licenses/agpl-3.0>.
use std::str::FromStr;
use chrono::{DateTime, Utc};
use oxidetalis_core::{cipher::K256Secret, types::PublicKey}; use oxidetalis_core::{cipher::K256Secret, types::PublicKey};
use oxidetalis_entities::prelude::*;
use salvo::oapi::ToSchema; use salvo::oapi::ToSchema;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -25,3 +29,30 @@ pub struct RegisterUserBody {
/// The public key of the user /// The public key of the user
pub public_key: PublicKey, 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<Utc>,
}
impl Default for WhiteListedUser {
fn default() -> Self {
WhiteListedUser::new(
PublicKey::from_str("bYhbrm61ov8GLZfskUYbsCLJTfaacMsuTBYgBABEH9dy").expect("is valid"),
Utc::now(),
)
}
}
impl From<WhitelistModel> 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,
}
}
}