fix: user notification/request counts
This commit is contained in:
parent
29155ddb0c
commit
46e38042ce
4 changed files with 46 additions and 15 deletions
|
@ -13,6 +13,7 @@ impl DataManager {
|
|||
subject: get!(x->4(String)),
|
||||
content: get!(x->5(String)),
|
||||
read_by: serde_json::from_str(&get!(x->6(String))).unwrap(),
|
||||
replying_to: get!(x->7(i32)) as usize,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,6 +67,30 @@ impl DataManager {
|
|||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Get all letters which are replying to the given letter.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `id` - the ID of the letter to fetch letters for
|
||||
pub async fn get_letters_by_replying_to(&self, id: usize) -> Result<Vec<Letter>> {
|
||||
let conn = match self.0.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
||||
let res = query_rows!(
|
||||
&conn,
|
||||
"SELECT * FROM letters WHERE replying_to = $1 ORDER BY created DESC",
|
||||
&[&(id as i64)],
|
||||
|x| { Self::get_letter_from_row(x) }
|
||||
);
|
||||
|
||||
if res.is_err() {
|
||||
return Err(Error::GeneralNotFound("letter".to_string()));
|
||||
}
|
||||
|
||||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Create a new letter in the database.
|
||||
///
|
||||
/// # Arguments
|
||||
|
@ -92,7 +117,7 @@ impl DataManager {
|
|||
|
||||
let res = execute!(
|
||||
&conn,
|
||||
"INSERT INTO letters VALUES ($1, $2, $3, $4, $5, $6, $7)",
|
||||
"INSERT INTO letters VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
|
||||
params![
|
||||
&(data.id as i64),
|
||||
&(data.created as i64),
|
||||
|
@ -101,6 +126,7 @@ impl DataManager {
|
|||
&data.subject,
|
||||
&data.content,
|
||||
&serde_json::to_string(&data.read_by).unwrap(),
|
||||
&(data.replying_to as i64)
|
||||
]
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue