fix: post page panic
This commit is contained in:
parent
7960484bf9
commit
9d091d5421
5 changed files with 26 additions and 2 deletions
|
@ -231,7 +231,7 @@
|
|||
<div class="card flex flex-col gap-4">
|
||||
<!-- prettier-ignore -->
|
||||
{% 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) }}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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?;
|
||||
|
|
|
@ -164,6 +164,8 @@ impl DataManager {
|
|||
}
|
||||
}
|
||||
|
||||
self.update_user_request_count(user.id, 0).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue