Updating schemas to support content_type

This commit is contained in:
shockrah 2021-03-09 00:03:12 -08:00
parent ae675d000b
commit ddb08818b1
3 changed files with 6 additions and 7 deletions

View File

@ -2,7 +2,8 @@
CREATE TABLE IF NOT EXISTS `messages`( CREATE TABLE IF NOT EXISTS `messages`(
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`time` BIGINT NOT NULL, `time` BIGINT NOT NULL,
`content` VARCHAR(2048) NOT NULL, `content` VARCHAR(4096) NOT NULL,
`content_type` VARCHAR NOT NULL,
`author_id` BIGINT UNSIGNED NOT NULL, `author_id` BIGINT UNSIGNED NOT NULL,
`channel_id` BIGINT UNSIGNED NOT NULL, `channel_id` BIGINT UNSIGNED NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),

View File

@ -18,14 +18,14 @@ pub async fn list_channels(pool: &Pool, response: &mut Response<Body>, params: H
*/ */
// Default to filtering for text channels only // Default to filtering for text channels only
let chan_type = match qs_param!(params, "type", i32) { let chan_type = match qs_param!(params, "kind", i32) {
Some(ctype) => ctype, Some(ctype) => ctype,
None => db::channels::TEXT_CHANNEL None => db::channels::TEXT_CHANNEL
}; };
match db::Channel::filter(pool, chan_type).await { match db::Channel::filter(pool, chan_type).await {
Ok(resp) => match resp { Ok(resp) => match resp {
db::Response::Set(channels) => set_json_body(response, json!(channels)), db::Response::Set(channels) => set_json_body(response, json!({"channels": json!(channels)}) ),
_ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR _ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR
}, },
Err(e) => { Err(e) => {
@ -45,7 +45,7 @@ pub async fn create_channel(pool: &Pool, response: &mut Response<Body>, params:
use db::Response::*; use db::Response::*;
let name = params.get("name"); let name = params.get("name");
let kind = qs_param!(params, "type", i32); let kind = qs_param!(params, "kind", i32);
let description = match params.get("description") { let description = match params.get("description") {
Some(d) => d, Some(d) => d,
None => "No description" None => "No description"

View File

@ -35,9 +35,7 @@ pub async fn get_by_time(pool: &Pool, response: &mut Response<Body>, params: Has
match db_response { match db_response {
// this absolute lack of data streaming is prolly gonna suck like // this absolute lack of data streaming is prolly gonna suck like
// a whore in hell week for performance but lets pretend servers don't get massive // a whore in hell week for performance but lets pretend servers don't get massive
db::Response::Set(messages) => { db::Response::Set(messages) => set_json_body(response, json!({"messages": messages})),
set_json_body(response, json!({"messages": messages}));
},
db::Response::RestrictedInput(_/*error message to log*/) => { db::Response::RestrictedInput(_/*error message to log*/) => {
*response.status_mut() = StatusCode::BAD_REQUEST; *response.status_mut() = StatusCode::BAD_REQUEST;
} }