tetratto-core 17.0.0

The core behind Tetratto
Documentation
use serde::{Deserialize, Serialize};
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};

/// All of the items which support reactions.
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum AssetType {
    #[serde(alias = "community")]
    Community,
    #[serde(alias = "post")]
    Post,
    #[serde(alias = "question")]
    Question,
    #[serde(alias = "user")]
    User,
    #[serde(alias = "letter")]
    Letter,
}

#[derive(Clone, Serialize, Deserialize)]
pub struct Reaction {
    pub id: usize,
    pub created: usize,
    pub owner: usize,
    pub asset: usize,
    pub asset_type: AssetType,
    pub is_like: bool,
}

impl Reaction {
    /// Create a new [`Reaction`].
    pub fn new(owner: usize, asset: usize, asset_type: AssetType, is_like: bool) -> Self {
        Self {
            id: Snowflake::new().to_string().parse::<usize>().unwrap(),
            created: unix_epoch_timestamp(),
            owner,
            asset,
            asset_type,
            is_like,
        }
    }
}