diff --git a/json-api/client-tests/client.py b/json-api/client-tests/client.py index 44257e2..5e8fb17 100644 --- a/json-api/client-tests/client.py +++ b/json-api/client-tests/client.py @@ -145,9 +145,9 @@ def run(worker: Worker): {'init': ['get', '/channels/list', {}], 'auth': None, 'hope': 401}, {'init': ['post', '/channels/list', {}], 'auth': jwt, 'hope': 404}, - {'init': ['post', '/channels/create', {'name': str(new_channel_name), 'type': TEXT_CHAN, 'description': 'asdf'}], 'auth': jwt, 'hope': 200}, + {'init': ['post', '/channels/create', {'name': str(new_channel_name), 'kind': TEXT_CHAN, 'description': 'asdf'}], 'auth': jwt, 'hope': 200}, # Just a regular test no saving for this one - {'init': ['post', '/channels/create', {'name': str(new_channel_name+1), 'type': TEXT_CHAN,}], 'auth': jwt, 'hope': 200}, + {'init': ['post', '/channels/create', {'name': str(new_channel_name+1), 'kind': TEXT_CHAN,}], 'auth': jwt, 'hope': 200}, {'init': ['post', '/channels/create', {}], 'auth': jwt, 'hope': 400}, {'init': ['post', '/channels/create', {'name': 123, 'kind': 'adsf'}], 'auth': jwt, 'hope': 400}, @@ -163,7 +163,7 @@ def run(worker: Worker): msg_chan_name = time.time() _id = worker.request('post', '/channels/create', jwt, { 'name': str(msg_chan_name), - 'type': TEXT_CHAN, + 'kind': TEXT_CHAN, 'description': 'asdf' }, 200) diff --git a/json-api/db/src/channels.rs b/json-api/db/src/channels.rs index fbc26e0..4f7d5d7 100644 --- a/json-api/db/src/channels.rs +++ b/json-api/db/src/channels.rs @@ -20,11 +20,17 @@ impl crate::Channel { if kind != VOICE_CHANNEL || kind !=TEXT_CHANNEL { let conn = p.get_conn().await?; - let q = "SELECT id, name, description FROM channels WHERE kind = :kind"; + let result = match kind { + 0 => conn.prep_exec("SELECT id, name, description, kind FROM channels", ()).await?, + _ => { + conn.prep_exec( + "SELECT id, name, description, kind FROM channels WHERE kind = :kind", + params!{"kind" => kind}).await? + } + }; - let result = conn.prep_exec(q, params!{"kind" => kind}).await?; let (_conn, channels) = result.map_and_drop(|row| { - let (id, name, description): (UBigInt, VarChar, Option) = + let (id, name, description, kind): (UBigInt, VarChar, Option, Integer) = mysql_async::from_row(row); Self { id, diff --git a/json-api/db/src/lib.rs b/json-api/db/src/lib.rs index 9c03f75..fe67652 100644 --- a/json-api/db/src/lib.rs +++ b/json-api/db/src/lib.rs @@ -40,20 +40,24 @@ pub struct Message { pub id: UBigInt, pub time: BigInt, pub content: VarChar, + pub content_type: VarChar, pub author_id: UBigInt, pub channel_id: UBigInt } -#[derive(Serialize)] +#[derive(Debug, Serialize)] pub struct UserMessage { pub id: UBigInt, pub time: BigInt, pub content: VarChar, + pub content_type: VarChar, pub author_id: UBigInt, pub channel_id: UBigInt, pub name: VarChar } + + #[derive(Serialize)] pub struct Channel { pub id: UBigInt, diff --git a/json-api/db/src/messages.rs b/json-api/db/src/messages.rs index 0ac4be6..5b16917 100644 --- a/json-api/db/src/messages.rs +++ b/json-api/db/src/messages.rs @@ -68,7 +68,8 @@ impl crate::Message { MAX_MESSAGES }; - let q = "SELECT mem.name, msg.id, msg.time, msg.content, msg.author_id FROM messages as msg + let q = " SELECT mem.name, msg.id, msg.time, msg.content, msg.content_type, msg.author_id + FROM messages as msg JOIN members as mem ON mem.id = msg.author_id WHERE channel_id = :channel AND time >= :start AND time < :end LIMIT :limit"; @@ -82,12 +83,13 @@ impl crate::Message { }).await?; let(_conn, messages) = select_result.map_and_drop(|row| { - type Tuple = (VarChar, UBigInt, BigInt, String, UBigInt); - let (name, id, time, content, author_id): Tuple = mysql_async::from_row(row); + type Tuple = (VarChar, UBigInt, BigInt, String, String, UBigInt); + let (name, id, time, content, content_type, author_id): Tuple = mysql_async::from_row(row); UserMessage { id, time, content, + content_type, author_id, name, channel_id @@ -111,7 +113,7 @@ impl crate::Message { MAX_MESSAGES // messages at a time }; - let q = "SELECT id, time, content, author_id FROM messages WHERE + let q = "SELECT id, time, content, content_type, author_id FROM messages WHERE channel_id = :channel AND id >= :start LIMIT :limit"; let params = params!{ @@ -123,12 +125,13 @@ impl crate::Message { let select_result = conn.prep_exec(q, params).await?; let (_conn, messages) = select_result.map_and_drop(|row| { - type Tuple = (UBigInt, BigInt, String, UBigInt); - let (id, time, content, author_id): Tuple = mysql_async::from_row(row); + type Tuple = (UBigInt, BigInt, VarChar, VarChar, UBigInt); + let (id, time, content, content_type, author_id): Tuple = mysql_async::from_row(row); Self { id, time, content, + content_type, author_id, channel_id }