/channels/list/voice + text now implemted and ready for testing
This commit is contained in:
parent
e99e30b45c
commit
5a2a87fff7
@ -5,11 +5,13 @@
|
||||
use diesel::{self, prelude::*};
|
||||
use rocket_contrib::json::Json;
|
||||
use std::vec::Vec;
|
||||
use crate::models::{InsertableChannel, Channel, VOICE_CHANNEL, TEXT_CHANNEL};
|
||||
use crate::auth::{AuthResult, AuthErr, AuthKey};
|
||||
use crate::models::{InsertableChannel, Channel};
|
||||
use crate::auth::AuthResult;
|
||||
use crate::{DBConn, schema, payload};
|
||||
use crate::err::{self, DbError};
|
||||
|
||||
const VOICE_CHANNEL: i32 = 1;
|
||||
const TEXT_CHANNEL: i32 = 2;
|
||||
|
||||
#[post("/create/<qname>/<perms>/<lim>/<ctype>")]
|
||||
pub fn insert_new_channel(qname: String, perms: i32, lim: i32, ctype: i32, conn: DBConn) ->
|
||||
@ -32,12 +34,23 @@ pub fn insert_new_channel(qname: String, perms: i32, lim: i32, ctype: i32, conn:
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_channel_by_type(conn: &MysqlConnection, ctype: i32/*short for channel type*/) -> Result<Vec<Channel>, err::DbResponse> {
|
||||
use schema::channels::dsl::*;
|
||||
if let Ok(result) = channels.filter(type_.eq(ctype)).load(conn) {
|
||||
Ok(result)
|
||||
}
|
||||
else {
|
||||
Err(err::DbResponse{err_msg: "/channeels/list/<type> Could not query database"})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[get("/list/voice")]
|
||||
pub fn get_voice_channels(conn: DBConn) -> AuthResult<Json<Vec<Channel>>, err::DbResponse> {
|
||||
use schema::channels::dsl::*;
|
||||
|
||||
let result = channels.filter(type_.eq(VOICE_CHANNEL)).load(&conn.0);
|
||||
if let Ok(data) = result {
|
||||
let db_result = get_channel_by_type(&conn.0, VOICE_CHANNEL);
|
||||
// We have to rewrap the data given to us which is annoying but hey
|
||||
// at least its safe.jpg
|
||||
if let Ok(data) = db_result {
|
||||
Ok(Json(data))
|
||||
}
|
||||
else {
|
||||
@ -48,10 +61,8 @@ pub fn get_voice_channels(conn: DBConn) -> AuthResult<Json<Vec<Channel>>, err::D
|
||||
|
||||
#[get("/list/text")]
|
||||
pub fn get_text_chanels(conn: DBConn) -> DbError<Json<Vec<Channel>>, err::DbResponse> {
|
||||
use schema::channels::dsl::*;
|
||||
|
||||
let result = channels.filter(type_.eq(TEXT_CHANNEL)).load(&conn.0);
|
||||
if let Ok(data) = result {
|
||||
let db_result = get_channel_by_type(&conn.0, TEXT_CHANNEL);
|
||||
if let Ok(data) = db_result {
|
||||
Ok(Json(data))
|
||||
}
|
||||
else {
|
||||
|
Loading…
Reference in New Issue
Block a user