mirror of
https://git.dirksys.ovh/dirk/bankserver.git
synced 2025-12-20 02:59:20 +01:00
add members to chat info endpoint
This commit is contained in:
parent
975fc1d567
commit
a0e3d2b55a
@ -19,6 +19,7 @@ pub struct ChatInfo {
|
|||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub created: DateTime<Utc>,
|
pub created: DateTime<Utc>,
|
||||||
pub read_until: Option<Uuid>,
|
pub read_until: Option<Uuid>,
|
||||||
|
pub members: Vec<Uuid>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
||||||
|
|||||||
@ -21,6 +21,7 @@ fn chat_info_from_row(row: Row) -> ChatInfo {
|
|||||||
id: row.get("id"),
|
id: row.get("id"),
|
||||||
created: row.get("created"),
|
created: row.get("created"),
|
||||||
read_until: row.get("read_until"),
|
read_until: row.get("read_until"),
|
||||||
|
members: row.get("members"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +83,7 @@ impl Chats {
|
|||||||
id: Uuid,
|
id: Uuid,
|
||||||
user: Uuid,
|
user: Uuid,
|
||||||
) -> Result<Option<ChatInfo>, tokio_postgres::Error> {
|
) -> Result<Option<ChatInfo>, tokio_postgres::Error> {
|
||||||
let stmt = client.prepare_cached("select c.id as id, c.created as created, cm.read_until as read_until from chat_members cm join chats c on cm.chat = c.id where c.id = $1 and cm.\"user\" = $2").await?;
|
let stmt = client.prepare_cached("select c.*, cmru.read_until, array_agg(cm.\"user\") as members from chats c join chat_members cm on cm.chat = c.id join chat_members cmru on cmru.chat = c.id and cmru.\"user\" = $2 where c.id = $1 group by c.id, cmru.read_until").await?;
|
||||||
let res = client.query_opt(&stmt, &[&id, &user]).await?;
|
let res = client.query_opt(&stmt, &[&id, &user]).await?;
|
||||||
Ok(res.map(chat_info_from_row))
|
Ok(res.map(chat_info_from_row))
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user