new test for deleting channels
-x- this test will fail but the patch is required for testing self hosting our code base
This commit is contained in:
parent
7023ce2b7a
commit
4cb8f578ed
@ -91,3 +91,4 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
worker.post('/channels/create', name='send-channel', kind=TEXT_CHANNEL)
|
worker.post('/channels/create', name='send-channel', kind=TEXT_CHANNEL)
|
||||||
worker.post('/message/send', channel='send-channel', content="some random content")
|
worker.post('/message/send', channel='send-channel', content="some random content")
|
||||||
|
worker.delete('/channels/delete', name='send-channel')
|
||||||
|
@ -9,6 +9,11 @@ use crate::{UBigInt, BigInt, VarChar};
|
|||||||
|
|
||||||
use crate::common::{FromDB};
|
use crate::common::{FromDB};
|
||||||
|
|
||||||
|
macro_rules! msg_channel {
|
||||||
|
$(value:expr) => {
|
||||||
|
format!("messages_{}", value)
|
||||||
|
}
|
||||||
|
}
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub struct Message {
|
pub struct Message {
|
||||||
pub id: UBigInt,
|
pub id: UBigInt,
|
||||||
@ -23,6 +28,8 @@ impl FromDB<Message> for Message {
|
|||||||
type Row = Option<(UBigInt, BigInt, VarChar, UBigInt, VarChar)>;
|
type Row = Option<(UBigInt, BigInt, VarChar, UBigInt, VarChar)>;
|
||||||
|
|
||||||
async fn get(p: &Pool, id: UBigInt) -> Response<Self> {
|
async fn get(p: &Pool, id: UBigInt) -> Response<Self> {
|
||||||
|
//! Typically used as the backend to the .update(...) method to
|
||||||
|
//! pick out a message to later edit
|
||||||
if let Ok(conn) = p.get_conn().await {
|
if let Ok(conn) = p.get_conn().await {
|
||||||
let q = "SELECT id, time, content, author_id, channel_name WHERE id = :id";
|
let q = "SELECT id, time, content, author_id, channel_name WHERE id = :id";
|
||||||
let result: Result<(Conn, Self::Row), SqlError> =
|
let result: Result<(Conn, Self::Row), SqlError> =
|
||||||
@ -45,6 +52,7 @@ impl FromDB<Message> for Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn update(p: &Pool, row: Self) -> Response<Self> {
|
async fn update(p: &Pool, row: Self) -> Response<Self> {
|
||||||
|
//! Primarily used by users to edit previous comments
|
||||||
// NOTE: we only allow the changing of content in this since
|
// NOTE: we only allow the changing of content in this since
|
||||||
// no other column has good reason to be modified
|
// no other column has good reason to be modified
|
||||||
if let Ok(conn) = p.get_conn().await {
|
if let Ok(conn) = p.get_conn().await {
|
||||||
@ -62,6 +70,8 @@ impl FromDB<Message> for Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(p: &Pool, id: UBigInt) -> Response<Self> {
|
async fn delete(p: &Pool, id: UBigInt) -> Response<Self> {
|
||||||
|
//! Deletes a single message
|
||||||
|
//! Typically used by normal users/bots to remove unwanted comments
|
||||||
if let Ok(conn) = p.get_conn().await {
|
if let Ok(conn) = p.get_conn().await {
|
||||||
let q = "DELETE FROM messages WHERE id = :id";
|
let q = "DELETE FROM messages WHERE id = :id";
|
||||||
let result: Result<Conn, SqlError> =
|
let result: Result<Conn, SqlError> =
|
||||||
@ -74,3 +84,20 @@ impl FromDB<Message> for Message {
|
|||||||
return Response::Other(no_conn!("Message::FromDB::update"))
|
return Response::Other(no_conn!("Message::FromDB::update"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl Message {
|
||||||
|
async fn add(p: &Pool, author_id: UBigInt, content: VarChar, channel_id: UBigInt) -> Response<Self> {
|
||||||
|
//! Adds a user message to the given channel via channel_id
|
||||||
|
let conn = p.get_conn().await;
|
||||||
|
if conn.is_err() {
|
||||||
|
return Response::Other(no_conn!("Message::add"));
|
||||||
|
}
|
||||||
|
// generate the channel name
|
||||||
|
let fq_channel_id = msg_channel!(channel_id);
|
||||||
|
conn.prep_exec(
|
||||||
|
"INSERT INTO :table (id, time, content, author_id)",
|
||||||
|
params!{"cid" => fq_channel_id}
|
||||||
|
);
|
||||||
|
return Response::Success;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user