add: profiles ui, communities ui, posts ui
This commit is contained in:
parent
00abbc8fa2
commit
eecf357325
36 changed files with 1460 additions and 147 deletions
|
@ -24,26 +24,29 @@ impl DataManager {
|
|||
#[cfg(feature = "postgres")] x: &Row,
|
||||
) -> Community {
|
||||
Community {
|
||||
id: get!(x->0(i64)) as usize,
|
||||
created: get!(x->1(i64)) as usize,
|
||||
id: get!(x->0(isize)) as usize,
|
||||
created: get!(x->1(isize)) as usize,
|
||||
title: get!(x->2(String)),
|
||||
context: serde_json::from_str(&get!(x->3(String))).unwrap(),
|
||||
owner: get!(x->4(i64)) as usize,
|
||||
owner: get!(x->4(isize)) as usize,
|
||||
read_access: serde_json::from_str(&get!(x->5(String))).unwrap(),
|
||||
write_access: serde_json::from_str(&get!(x->6(String))).unwrap(),
|
||||
// likes
|
||||
likes: get!(x->6(i64)) as isize,
|
||||
dislikes: get!(x->7(i64)) as isize,
|
||||
likes: get!(x->7(isize)) as isize,
|
||||
dislikes: get!(x->8(isize)) as isize,
|
||||
// counts
|
||||
member_count: get!(x->9(isize)) as usize,
|
||||
}
|
||||
}
|
||||
|
||||
auto_method!(get_community_by_id()@get_community_from_row -> "SELECT * FROM communities WHERE id = $1" --name="community" --returns=Community --cache-key-tmpl="atto.community:{}");
|
||||
auto_method!(get_community_by_title(&str)@get_community_from_row -> "SELECT * FROM communities WHERE title = $1" --name="community" --returns=Community --cache-key-tmpl="atto.community:{}");
|
||||
|
||||
/// Create a new community in the database.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `data` - a mock [`Community`] to insert
|
||||
pub async fn create_community(&self, data: Community) -> Result<()> {
|
||||
pub async fn create_community(&self, data: Community) -> Result<String> {
|
||||
// check values
|
||||
if data.title.len() < 2 {
|
||||
return Err(Error::DataTooShort("title".to_string()));
|
||||
|
@ -51,6 +54,17 @@ impl DataManager {
|
|||
return Err(Error::DataTooLong("title".to_string()));
|
||||
}
|
||||
|
||||
if !data.title.is_ascii() | data.title.contains(" ") {
|
||||
return Err(Error::MiscError(
|
||||
"Title contains characters which aren't allowed".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
// make sure community doesn't already exist with title
|
||||
if self.get_community_by_title(&data.title).await.is_ok() {
|
||||
return Err(Error::MiscError("Title already in use".to_string()));
|
||||
}
|
||||
|
||||
// ...
|
||||
let conn = match self.connect().await {
|
||||
Ok(c) => c,
|
||||
|
@ -59,7 +73,7 @@ impl DataManager {
|
|||
|
||||
let res = execute!(
|
||||
&conn,
|
||||
"INSERT INTO communities VALUES ($1, $2, $3, $4, $5, $6, $7)",
|
||||
"INSERT INTO communities VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
||||
&[
|
||||
&data.id.to_string().as_str(),
|
||||
&data.created.to_string().as_str(),
|
||||
|
@ -68,6 +82,9 @@ impl DataManager {
|
|||
&data.owner.to_string().as_str(),
|
||||
&serde_json::to_string(&data.read_access).unwrap().as_str(),
|
||||
&serde_json::to_string(&data.write_access).unwrap().as_str(),
|
||||
&0.to_string().as_str(),
|
||||
&0.to_string().as_str(),
|
||||
&0.to_string().as_str()
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -85,17 +102,29 @@ impl DataManager {
|
|||
.unwrap();
|
||||
|
||||
// return
|
||||
Ok(())
|
||||
Ok(data.title)
|
||||
}
|
||||
|
||||
auto_method!(delete_community()@get_community_by_id:MANAGE_COMMUNITY_PAGES -> "DELETE communities pages WHERE id = $1" --cache-key-tmpl="atto.community:{}");
|
||||
auto_method!(update_community_title(String)@get_community_by_id:MANAGE_COMMUNITY_PAGES -> "UPDATE communities SET title = $1 WHERE id = $2" --cache-key-tmpl="atto.community:{}");
|
||||
auto_method!(update_community_context(CommunityContext)@get_community_by_id:MANAGE_COMMUNITY_PAGES -> "UPDATE communities SET prompt = $1 WHERE id = $2" --serde --cache-key-tmpl="atto.community:{}");
|
||||
auto_method!(update_community_read_access(CommunityReadAccess)@get_community_by_id:MANAGE_COMMUNITY_PAGES -> "UPDATE communities SET read_access = $1 WHERE id = $2" --serde --cache-key-tmpl="atto.community:{}");
|
||||
auto_method!(update_community_write_access(CommunityWriteAccess)@get_community_by_id:MANAGE_COMMUNITY_PAGES -> "UPDATE communities SET write_access = $1 WHERE id = $2" --serde --cache-key-tmpl="atto.community:{}");
|
||||
pub async fn cache_clear_community(&self, community: &Community) {
|
||||
self.2
|
||||
.remove(format!("atto.community:{}", community.id))
|
||||
.await;
|
||||
self.2
|
||||
.remove(format!("atto.community:{}", community.title))
|
||||
.await;
|
||||
}
|
||||
|
||||
auto_method!(incr_community_likes() -> "UPDATE communities SET likes = likes + 1 WHERE id = $1" --cache-key-tmpl="atto.community:{}" --incr);
|
||||
auto_method!(incr_community_dislikes() -> "UPDATE communities SET likes = dislikes + 1 WHERE id = $1" --cache-key-tmpl="atto.community:{}" --incr);
|
||||
auto_method!(decr_community_likes() -> "UPDATE communities SET likes = likes - 1 WHERE id = $1" --cache-key-tmpl="atto.community:{}" --decr);
|
||||
auto_method!(decr_community_dislikes() -> "UPDATE communities SET likes = dislikes - 1 WHERE id = $1" --cache-key-tmpl="atto.community:{}" --decr);
|
||||
auto_method!(delete_community()@get_community_by_id:MANAGE_COMMUNITIES -> "DELETE communities pages WHERE id = $1" --cache-key-tmpl=cache_clear_community);
|
||||
auto_method!(update_community_title(String)@get_community_by_id:MANAGE_COMMUNITIES -> "UPDATE communities SET title = $1 WHERE id = $2" --cache-key-tmpl=cache_clear_community);
|
||||
auto_method!(update_community_context(CommunityContext)@get_community_by_id:MANAGE_COMMUNITIES -> "UPDATE communities SET prompt = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_community);
|
||||
auto_method!(update_community_read_access(CommunityReadAccess)@get_community_by_id: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:MANAGE_COMMUNITIES -> "UPDATE communities SET write_access = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_community);
|
||||
|
||||
auto_method!(incr_community_likes()@get_community_by_id -> "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 -> "UPDATE communities SET likes = dislikes + 1 WHERE id = $1" --cache-key-tmpl=cache_clear_community --incr);
|
||||
auto_method!(decr_community_likes()@get_community_by_id -> "UPDATE communities SET likes = likes - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_community --decr);
|
||||
auto_method!(decr_community_dislikes()@get_community_by_id -> "UPDATE communities SET likes = dislikes - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_community --decr);
|
||||
|
||||
auto_method!(incr_community_member_count()@get_community_by_id -> "UPDATE communities SET member_count = member_count + 1 WHERE id = $1" --cache-key-tmpl=cache_clear_community --incr);
|
||||
auto_method!(decr_community_member_count()@get_community_by_id -> "UPDATE communities SET member_count = member_count - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_community --decr);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue