add: community topic endpoints
This commit is contained in:
parent
12fa80c7c0
commit
ef029c59b3
7 changed files with 201 additions and 28 deletions
|
@ -1,19 +1,23 @@
|
|||
use super::common::NAME_REGEX;
|
||||
|
||||
use oiseau::cache::Cache;
|
||||
use crate::model::communities::{CommunityContext, CommunityJoinAccess, CommunityMembership};
|
||||
use crate::model::communities_permissions::CommunityPermission;
|
||||
use crate::model::permissions::SecondaryPermission;
|
||||
use crate::model::{
|
||||
Error, Result,
|
||||
auth::User,
|
||||
communities::Community,
|
||||
communities::{CommunityReadAccess, CommunityWriteAccess},
|
||||
permissions::FinePermission,
|
||||
use crate::{
|
||||
auto_method, DataManager,
|
||||
model::{
|
||||
Error, Result,
|
||||
auth::User,
|
||||
communities::{
|
||||
CommunityReadAccess, CommunityWriteAccess, ForumTopic, Community, CommunityContext,
|
||||
CommunityJoinAccess, CommunityMembership,
|
||||
},
|
||||
permissions::{FinePermission, SecondaryPermission},
|
||||
communities_permissions::CommunityPermission,
|
||||
},
|
||||
};
|
||||
use pathbufd::PathBufD;
|
||||
use std::fs::{exists, remove_file};
|
||||
use crate::{auto_method, DataManager};
|
||||
use std::{
|
||||
fs::{exists, remove_file},
|
||||
collections::HashMap,
|
||||
};
|
||||
|
||||
use oiseau::{PostgresRow, execute, get, query_row, query_rows, params};
|
||||
|
||||
|
@ -29,14 +33,13 @@ impl DataManager {
|
|||
read_access: serde_json::from_str(&get!(x->5(String))).unwrap(),
|
||||
write_access: serde_json::from_str(&get!(x->6(String))).unwrap(),
|
||||
join_access: serde_json::from_str(&get!(x->7(String))).unwrap(),
|
||||
// likes
|
||||
likes: get!(x->8(i32)) as isize,
|
||||
dislikes: get!(x->9(i32)) as isize,
|
||||
// ...
|
||||
member_count: get!(x->10(i32)) as usize,
|
||||
is_forge: get!(x->11(i32)) as i8 == 1,
|
||||
post_count: get!(x->12(i32)) as usize,
|
||||
is_forum: get!(x->13(i32)) as i8 == 1,
|
||||
topics: serde_json::from_str(&get!(x->14(String))).unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,7 +285,7 @@ impl DataManager {
|
|||
|
||||
let res = execute!(
|
||||
&conn,
|
||||
"INSERT INTO communities VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)",
|
||||
"INSERT INTO communities VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)",
|
||||
params![
|
||||
&(data.id as i64),
|
||||
&(data.created as i64),
|
||||
|
@ -298,6 +301,7 @@ impl DataManager {
|
|||
&{ if data.is_forge { 1 } else { 0 } },
|
||||
&0_i32,
|
||||
&{ if data.is_forum { 1 } else { 0 } },
|
||||
&serde_json::to_string(&data.topics).unwrap().as_str(),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -532,6 +536,7 @@ impl DataManager {
|
|||
auto_method!(update_community_read_access(CommunityReadAccess)@get_community_by_id_no_void:FinePermission::MANAGE_COMMUNITIES; -> "UPDATE communities SET read_access = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_community);
|
||||
auto_method!(update_community_write_access(CommunityWriteAccess)@get_community_by_id_no_void:FinePermission::MANAGE_COMMUNITIES; -> "UPDATE communities SET write_access = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_community);
|
||||
auto_method!(update_community_join_access(CommunityJoinAccess)@get_community_by_id_no_void:FinePermission::MANAGE_COMMUNITIES; -> "UPDATE communities SET join_access = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_community);
|
||||
auto_method!(update_community_topics(HashMap<usize, ForumTopic>)@get_community_by_id_no_void:FinePermission::MANAGE_COMMUNITIES; -> "UPDATE communities SET topics = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_community);
|
||||
|
||||
auto_method!(incr_community_likes()@get_community_by_id_no_void -> "UPDATE communities SET likes = likes + 1 WHERE id = $1" --cache-key-tmpl=cache_clear_community --incr);
|
||||
auto_method!(incr_community_dislikes()@get_community_by_id_no_void -> "UPDATE communities SET dislikes = dislikes + 1 WHERE id = $1" --cache-key-tmpl=cache_clear_community --incr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue