add: community topic endpoints

This commit is contained in:
trisua 2025-08-03 11:45:57 -04:00
parent 12fa80c7c0
commit ef029c59b3
7 changed files with 201 additions and 28 deletions

View file

@ -1,3 +1,5 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
use super::communities_permissions::CommunityPermission;
@ -19,14 +21,20 @@ pub struct Community {
pub write_access: CommunityWriteAccess,
/// Who can join the community.
pub join_access: CommunityJoinAccess,
// likes
pub likes: isize,
pub dislikes: isize,
// ...
pub member_count: usize,
pub is_forge: bool,
pub post_count: usize,
pub is_forum: bool,
/// The topics of a community if the community has `is_forum` enabled.
///
/// Since topics are given a unique ID (the key of the hashmap), a removal of a topic
/// should be done through a specific DELETE endpoint which ALSO deletes all posts
/// within the topic.
///
/// Communities should be limited to 10 topics per community.
pub topics: HashMap<usize, ForumTopic>,
}
impl Community {
@ -50,6 +58,7 @@ impl Community {
is_forge: false,
post_count: 0,
is_forum: false,
topics: HashMap::new(),
}
}
@ -71,6 +80,7 @@ impl Community {
is_forge: false,
post_count: 0,
is_forum: false,
topics: HashMap::new(),
}
}
}
@ -521,10 +531,25 @@ impl PollVote {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ForumTopic {
pub id: usize,
pub created: usize,
pub owner: usize,
pub community: usize,
pub title: String,
pub description: String,
pub color: String,
}
impl ForumTopic {
/// Create a new [`ForumTopic`].
///
/// # Returns
/// * ID for [`Community`] hashmap
/// * [`ForumTopic`]
pub fn new(title: String, description: String, color: String) -> (usize, Self) {
(
Snowflake::new().to_string().parse::<usize>().unwrap(),
Self {
title,
description,
color,
},
)
}
}