diff --git a/bank_core/src/chat.rs b/bank_core/src/chat.rs index fc12877..b55e98d 100644 --- a/bank_core/src/chat.rs +++ b/bank_core/src/chat.rs @@ -19,6 +19,7 @@ pub struct ChatInfo { pub id: Uuid, pub created: DateTime, pub read_until: Option, + pub members: Vec, } #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)] diff --git a/src/model/chats.rs b/src/model/chats.rs index 91e84de..8f532d5 100644 --- a/src/model/chats.rs +++ b/src/model/chats.rs @@ -21,6 +21,7 @@ fn chat_info_from_row(row: Row) -> ChatInfo { id: row.get("id"), created: row.get("created"), read_until: row.get("read_until"), + members: row.get("members"), } } @@ -82,7 +83,7 @@ impl Chats { id: Uuid, user: Uuid, ) -> Result, 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?; Ok(res.map(chat_info_from_row)) }