[Add] Structure
This commit is contained in:
parent
70015c4d69
commit
826fb9ce50
44 changed files with 2210 additions and 2721 deletions
30
src/models/ids.rs
Normal file
30
src/models/ids.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
use std::fmt::{Display, Formatter};
|
||||
|
||||
macro_rules! id_type {
|
||||
($name:ident) => {
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, serde::Serialize)]
|
||||
pub struct $name(pub i64);
|
||||
|
||||
impl From<i64> for $name {
|
||||
fn from(value: i64) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<$name> for i64 {
|
||||
fn from(value: $name) -> Self {
|
||||
value.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for $name {
|
||||
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
self.0.fmt(formatter)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
id_type!(UserId);
|
||||
id_type!(IotaId);
|
||||
id_type!(OmikronId);
|
||||
9
src/models/iota.rs
Normal file
9
src/models/iota.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
use super::IotaId;
|
||||
use mtp::crypto::PublicKeyBundle;
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize)]
|
||||
pub struct Iota {
|
||||
pub id: IotaId,
|
||||
#[serde(serialize_with = "crate::models::serialize_public_key")]
|
||||
pub public_key: PublicKeyBundle,
|
||||
}
|
||||
21
src/models/mod.rs
Normal file
21
src/models/mod.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
mod ids;
|
||||
mod iota;
|
||||
mod notification;
|
||||
mod omikron;
|
||||
mod user;
|
||||
|
||||
fn serialize_public_key<S>(
|
||||
key: &mtp::crypto::PublicKeyBundle,
|
||||
serializer: S,
|
||||
) -> std::result::Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(&key.to_base64())
|
||||
}
|
||||
|
||||
pub use ids::{IotaId, OmikronId, UserId};
|
||||
pub use iota::Iota;
|
||||
pub use notification::Notification;
|
||||
pub use omikron::Omikron;
|
||||
pub use user::User;
|
||||
9
src/models/notification.rs
Normal file
9
src/models/notification.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
use super::UserId;
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize)]
|
||||
pub struct Notification {
|
||||
pub id: i64,
|
||||
pub sender_id: UserId,
|
||||
pub receiver_id: UserId,
|
||||
pub amount: i64,
|
||||
}
|
||||
12
src/models/omikron.rs
Normal file
12
src/models/omikron.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
use super::OmikronId;
|
||||
use mtp::crypto::PublicKeyBundle;
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize)]
|
||||
pub struct Omikron {
|
||||
pub id: OmikronId,
|
||||
#[serde(serialize_with = "crate::models::serialize_public_key")]
|
||||
pub public_key: PublicKeyBundle,
|
||||
pub location: String,
|
||||
pub ip_address: String,
|
||||
pub port: u16,
|
||||
}
|
||||
19
src/models/user.rs
Normal file
19
src/models/user.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
use super::{IotaId, UserId};
|
||||
use mtp::crypto::PublicKeyBundle;
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize)]
|
||||
pub struct User {
|
||||
pub id: UserId,
|
||||
pub iota_id: IotaId,
|
||||
pub username: String,
|
||||
pub display: Option<String>,
|
||||
pub status: Option<String>,
|
||||
pub about: Option<String>,
|
||||
pub avatar: Option<Vec<u8>>,
|
||||
pub sub_level: i32,
|
||||
pub sub_end: i64,
|
||||
#[serde(serialize_with = "crate::models::serialize_public_key")]
|
||||
pub public_key: PublicKeyBundle,
|
||||
#[serde(skip_serializing)]
|
||||
pub token: String,
|
||||
}
|
||||
Loading…
Reference in a new issue