add: questions, requests
This commit is contained in:
parent
24f67221ca
commit
7960484bf9
52 changed files with 1698 additions and 100 deletions
52
crates/core/src/model/requests.rs
Normal file
52
crates/core/src/model/requests.rs
Normal file
|
@ -0,0 +1,52 @@
|
|||
use serde::{Serialize, Deserialize};
|
||||
use tetratto_shared::{snow::AlmostSnowflake, unix_epoch_timestamp};
|
||||
|
||||
#[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,
|
||||
}
|
||||
|
||||
#[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 {
|
||||
id: AlmostSnowflake::new(1234567890)
|
||||
.to_string()
|
||||
.parse::<usize>()
|
||||
.unwrap(),
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue