add basic guild create + message create endpoints
This commit is contained in:
parent
5b23095520
commit
e57bff00c2
27 changed files with 367 additions and 36 deletions
33
chat/src/db/message.rs
Normal file
33
chat/src/db/message.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use eyre::Result;
|
||||
use foxchat::model::http::channel::CreateMessageParams;
|
||||
use sqlx::PgExecutor;
|
||||
use ulid::Ulid;
|
||||
|
||||
pub struct Message {
|
||||
pub id: String,
|
||||
pub channel_id: String,
|
||||
pub author_id: String,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
pub content: String,
|
||||
}
|
||||
|
||||
pub async fn create_message(
|
||||
executor: impl PgExecutor<'_>,
|
||||
channel_id: &str,
|
||||
user_id: &str,
|
||||
params: CreateMessageParams,
|
||||
) -> Result<Message> {
|
||||
let message = sqlx::query_as!(
|
||||
Message,
|
||||
"insert into messages (id, channel_id, author_id, content) values ($1, $2, $3, $4) returning *",
|
||||
Ulid::new().to_string(),
|
||||
channel_id,
|
||||
user_id,
|
||||
params.content,
|
||||
)
|
||||
.fetch_one(executor)
|
||||
.await?;
|
||||
|
||||
Ok(message)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue