First pass build of messages::send functionality
This commit is contained in:
parent
3925e2c57f
commit
c78c8a5502
@ -112,3 +112,27 @@ impl FromDB<Message, (BigInt, UBigInt)> for Message {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Message {
|
||||
pub async fn send(p: &Pool, content: &str, cid: UBigInt, uid: UBigInt) -> Result<Response<Self>, SqlError> {
|
||||
//! @returns on_sucess -> empty
|
||||
//! @returns on_failure Err(SqlErr)
|
||||
|
||||
use chrono::Utc;
|
||||
let conn = p.get_conn().await?;
|
||||
let q = "INSERT INTO messages
|
||||
(time, content, author_id, channel_id)
|
||||
VALUES (:time, :content, :author, :channel)";
|
||||
let now = Utc::now().timestamp();
|
||||
|
||||
conn.prep_exec(q, params!{
|
||||
"time" => now,
|
||||
"content" => content,
|
||||
"author" => uid,
|
||||
"channel" => cid
|
||||
}).await?;
|
||||
|
||||
return Ok(Response::Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user