add basic guild create + message create endpoints

This commit is contained in:
sam 2024-01-20 16:43:03 +01:00
parent 5b23095520
commit e57bff00c2
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
27 changed files with 367 additions and 36 deletions

33
chat/src/db/message.rs Normal file
View 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)
}