diff --git a/crates/app/src/public/html/communities/post.html b/crates/app/src/public/html/communities/post.html index a62c4e2..7afdad4 100644 --- a/crates/app/src/public/html/communities/post.html +++ b/crates/app/src/public/html/communities/post.html @@ -231,7 +231,7 @@
{% for post in replies %} - {{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, show_community=false) }} + {{ components::post(post=post[0], owner=post[1], question=post[3], secondary=true, show_community=false) }} {% endfor %} {{ components::pagination(page=page, items=replies|length) }} diff --git a/crates/core/src/database/auth.rs b/crates/core/src/database/auth.rs index cdbe247..9535997 100644 --- a/crates/core/src/database/auth.rs +++ b/crates/core/src/database/auth.rs @@ -592,6 +592,7 @@ impl DataManager { auto_method!(incr_user_post_count()@get_user_by_id -> "UPDATE users SET post_count = post_count + 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --incr); auto_method!(decr_user_post_count()@get_user_by_id -> "UPDATE users SET post_count = post_count - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --decr); + auto_method!(update_user_request_count(i64)@get_user_by_id -> "UPDATE users SET request_count = $1 WHERE id = $2" --cache-key-tmpl=cache_clear_user); auto_method!(incr_user_request_count()@get_user_by_id -> "UPDATE users SET request_count = request_count + 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --incr); auto_method!(decr_user_request_count()@get_user_by_id -> "UPDATE users SET request_count = request_count - 1 WHERE id = $1" --cache-key-tmpl=cache_clear_user --decr); } diff --git a/crates/core/src/database/common.rs b/crates/core/src/database/common.rs index 95d3429..182af60 100644 --- a/crates/core/src/database/common.rs +++ b/crates/core/src/database/common.rs @@ -551,6 +551,27 @@ macro_rules! auto_method { } }; + ($name:ident($x:ty)@$select_fn:ident -> $query:literal --cache-key-tmpl=$cache_key_tmpl:ident) => { + pub async fn $name(&self, id: usize, x: $x) -> Result<()> { + let y = self.$select_fn(id).await?; + + let conn = match self.connect().await { + Ok(c) => c, + Err(e) => return Err(Error::DatabaseConnection(e.to_string())), + }; + + let res = execute!(&conn, $query, params![&x, &(id as i64)]); + + if let Err(e) = res { + return Err(Error::DatabaseError(e.to_string())); + } + + self.$cache_key_tmpl(&y).await; + + Ok(()) + } + }; + ($name:ident($x:ty)@$select_fn:ident -> $query:literal --serde --cache-key-tmpl=$cache_key_tmpl:ident) => { pub async fn $name(&self, id: usize, x: $x) -> Result<()> { let y = self.$select_fn(id).await?; diff --git a/crates/core/src/database/requests.rs b/crates/core/src/database/requests.rs index 2b17abb..9161590 100644 --- a/crates/core/src/database/requests.rs +++ b/crates/core/src/database/requests.rs @@ -164,6 +164,8 @@ impl DataManager { } } + self.update_user_request_count(user.id, 0).await?; + Ok(()) } } diff --git a/crates/core/src/model/communities.rs b/crates/core/src/model/communities.rs index 51316d9..ca290e8 100644 --- a/crates/core/src/model/communities.rs +++ b/crates/core/src/model/communities.rs @@ -285,7 +285,7 @@ pub struct Question { pub receiver: usize, pub content: String, /// The `is_global` flag allows any (authenticated) user to respond - /// to the question. Normally, ownly the `receiver` can do so. + /// to the question. Normally, only the `receiver` can do so. /// /// If `is_global` is true, `receiver` should be 0 (and vice versa). pub is_global: bool,