2025-04-12 22:25:54 -04:00
|
|
|
use serde::{Serialize, Deserialize};
|
2025-05-06 16:13:48 -04:00
|
|
|
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
|
2025-04-12 22:25:54 -04:00
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, PartialEq, Eq)]
|
|
|
|
pub enum ActionType {
|
|
|
|
/// A request to join a community.
|
|
|
|
///
|
|
|
|
/// `users` table.
|
|
|
|
CommunityJoin,
|
|
|
|
/// A request to answer a question with a post.
|
|
|
|
///
|
|
|
|
/// `questions` table.
|
|
|
|
Answer,
|
2025-04-14 17:21:52 -04:00
|
|
|
/// A request follow a private account.
|
|
|
|
///
|
|
|
|
/// `users` table.
|
|
|
|
Follow,
|
2025-04-12 22:25:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
pub struct ActionRequest {
|
|
|
|
pub id: usize,
|
|
|
|
pub created: usize,
|
|
|
|
pub owner: usize,
|
|
|
|
pub action_type: ActionType,
|
|
|
|
/// The ID of the asset this request links to. Should exist in the correct
|
|
|
|
/// table for the given [`ActionType`].
|
|
|
|
pub linked_asset: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ActionRequest {
|
|
|
|
/// Create a new [`ActionRequest`].
|
|
|
|
pub fn new(owner: usize, action_type: ActionType, linked_asset: usize) -> Self {
|
|
|
|
Self {
|
2025-05-06 16:13:48 -04:00
|
|
|
id: Snowflake::new().to_string().parse::<usize>().unwrap(),
|
2025-04-12 22:25:54 -04:00
|
|
|
created: unix_epoch_timestamp() as usize,
|
|
|
|
owner,
|
|
|
|
action_type,
|
|
|
|
linked_asset,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create a new [`ActionRequest`] with the given `id`.
|
|
|
|
pub fn with_id(id: usize, owner: usize, action_type: ActionType, linked_asset: usize) -> Self {
|
|
|
|
Self {
|
|
|
|
id,
|
|
|
|
created: unix_epoch_timestamp() as usize,
|
|
|
|
owner,
|
|
|
|
action_type,
|
|
|
|
linked_asset,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|