chat: add Id<T> type
This commit is contained in:
parent
e57bff00c2
commit
ce543e7ee1
8 changed files with 146 additions and 43 deletions
|
@ -1,18 +1,18 @@
|
|||
use eyre::Result;
|
||||
use foxchat::FoxError;
|
||||
use foxchat::{FoxError, Id, id::{ChannelType, GuildType}};
|
||||
use sqlx::PgExecutor;
|
||||
use ulid::Ulid;
|
||||
|
||||
pub struct Channel {
|
||||
pub id: String,
|
||||
pub guild_id: String,
|
||||
pub id: Id<ChannelType>,
|
||||
pub guild_id: Id<GuildType>,
|
||||
pub name: String,
|
||||
pub topic: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn create_channel(
|
||||
executor: impl PgExecutor<'_>,
|
||||
guild_id: &str,
|
||||
guild_id: &Id<GuildType>,
|
||||
name: &str,
|
||||
topic: Option<String>,
|
||||
) -> Result<Channel> {
|
||||
|
@ -20,7 +20,7 @@ pub async fn create_channel(
|
|||
Channel,
|
||||
"insert into channels (id, guild_id, name, topic) values ($1, $2, $3, $4) returning *",
|
||||
Ulid::new().to_string(),
|
||||
guild_id,
|
||||
guild_id.0,
|
||||
name,
|
||||
topic
|
||||
)
|
||||
|
@ -30,8 +30,8 @@ pub async fn create_channel(
|
|||
Ok(channel)
|
||||
}
|
||||
|
||||
pub async fn get_channel(executor: impl PgExecutor<'_>, channel_id: &str) -> Result<Channel, FoxError> {
|
||||
let channel = sqlx::query_as!(Channel, "select * from channels where id = $1", channel_id)
|
||||
pub async fn get_channel(executor: impl PgExecutor<'_>, channel_id: &Id<ChannelType>) -> Result<Channel, FoxError> {
|
||||
let channel = sqlx::query_as!(Channel, "select * from channels where id = $1", channel_id.0)
|
||||
.fetch_one(executor)
|
||||
.await
|
||||
.map_err(|e| match e {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue