➕ content_type now a supported column in db-lib
➕ API layer now behaves as expected, returning 'content_type' flag with each message
This commit is contained in:
parent
d8244388c2
commit
ae675d000b
@ -145,9 +145,9 @@ def run(worker: Worker):
|
|||||||
{'init': ['get', '/channels/list', {}], 'auth': None, 'hope': 401},
|
{'init': ['get', '/channels/list', {}], 'auth': None, 'hope': 401},
|
||||||
{'init': ['post', '/channels/list', {}], 'auth': jwt, 'hope': 404},
|
{'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
|
# 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', {}], 'auth': jwt, 'hope': 400},
|
||||||
{'init': ['post', '/channels/create', {'name': 123, 'kind': 'adsf'}], '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()
|
msg_chan_name = time.time()
|
||||||
_id = worker.request('post', '/channels/create', jwt, {
|
_id = worker.request('post', '/channels/create', jwt, {
|
||||||
'name': str(msg_chan_name),
|
'name': str(msg_chan_name),
|
||||||
'type': TEXT_CHAN,
|
'kind': TEXT_CHAN,
|
||||||
'description': 'asdf'
|
'description': 'asdf'
|
||||||
}, 200)
|
}, 200)
|
||||||
|
|
||||||
|
@ -20,11 +20,17 @@ impl crate::Channel {
|
|||||||
|
|
||||||
if kind != VOICE_CHANNEL || kind !=TEXT_CHANNEL {
|
if kind != VOICE_CHANNEL || kind !=TEXT_CHANNEL {
|
||||||
let conn = p.get_conn().await?;
|
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 (_conn, channels) = result.map_and_drop(|row| {
|
||||||
let (id, name, description): (UBigInt, VarChar, Option<VarChar>) =
|
let (id, name, description, kind): (UBigInt, VarChar, Option<VarChar>, Integer) =
|
||||||
mysql_async::from_row(row);
|
mysql_async::from_row(row);
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
|
@ -40,20 +40,24 @@ pub struct Message {
|
|||||||
pub id: UBigInt,
|
pub id: UBigInt,
|
||||||
pub time: BigInt,
|
pub time: BigInt,
|
||||||
pub content: VarChar,
|
pub content: VarChar,
|
||||||
|
pub content_type: VarChar,
|
||||||
pub author_id: UBigInt,
|
pub author_id: UBigInt,
|
||||||
pub channel_id: UBigInt
|
pub channel_id: UBigInt
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct UserMessage {
|
pub struct UserMessage {
|
||||||
pub id: UBigInt,
|
pub id: UBigInt,
|
||||||
pub time: BigInt,
|
pub time: BigInt,
|
||||||
pub content: VarChar,
|
pub content: VarChar,
|
||||||
|
pub content_type: VarChar,
|
||||||
pub author_id: UBigInt,
|
pub author_id: UBigInt,
|
||||||
pub channel_id: UBigInt,
|
pub channel_id: UBigInt,
|
||||||
pub name: VarChar
|
pub name: VarChar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Channel {
|
pub struct Channel {
|
||||||
pub id: UBigInt,
|
pub id: UBigInt,
|
||||||
|
@ -68,7 +68,8 @@ impl crate::Message {
|
|||||||
MAX_MESSAGES
|
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
|
JOIN members as mem ON mem.id = msg.author_id
|
||||||
WHERE channel_id = :channel AND time >= :start AND time < :end
|
WHERE channel_id = :channel AND time >= :start AND time < :end
|
||||||
LIMIT :limit";
|
LIMIT :limit";
|
||||||
@ -82,12 +83,13 @@ impl crate::Message {
|
|||||||
}).await?;
|
}).await?;
|
||||||
|
|
||||||
let(_conn, messages) = select_result.map_and_drop(|row| {
|
let(_conn, messages) = select_result.map_and_drop(|row| {
|
||||||
type Tuple = (VarChar, UBigInt, BigInt, String, UBigInt);
|
type Tuple = (VarChar, UBigInt, BigInt, String, String, UBigInt);
|
||||||
let (name, id, time, content, author_id): Tuple = mysql_async::from_row(row);
|
let (name, id, time, content, content_type, author_id): Tuple = mysql_async::from_row(row);
|
||||||
UserMessage {
|
UserMessage {
|
||||||
id,
|
id,
|
||||||
time,
|
time,
|
||||||
content,
|
content,
|
||||||
|
content_type,
|
||||||
author_id,
|
author_id,
|
||||||
name,
|
name,
|
||||||
channel_id
|
channel_id
|
||||||
@ -111,7 +113,7 @@ impl crate::Message {
|
|||||||
MAX_MESSAGES // messages at a time
|
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";
|
channel_id = :channel AND id >= :start LIMIT :limit";
|
||||||
|
|
||||||
let params = params!{
|
let params = params!{
|
||||||
@ -123,12 +125,13 @@ impl crate::Message {
|
|||||||
let select_result = conn.prep_exec(q, params).await?;
|
let select_result = conn.prep_exec(q, params).await?;
|
||||||
|
|
||||||
let (_conn, messages) = select_result.map_and_drop(|row| {
|
let (_conn, messages) = select_result.map_and_drop(|row| {
|
||||||
type Tuple = (UBigInt, BigInt, String, UBigInt);
|
type Tuple = (UBigInt, BigInt, VarChar, VarChar, UBigInt);
|
||||||
let (id, time, content, author_id): Tuple = mysql_async::from_row(row);
|
let (id, time, content, content_type, author_id): Tuple = mysql_async::from_row(row);
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
time,
|
time,
|
||||||
content,
|
content,
|
||||||
|
content_type,
|
||||||
author_id,
|
author_id,
|
||||||
channel_id
|
channel_id
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user