From da804cd43637150379df28aabfaad2185628d66d Mon Sep 17 00:00:00 2001 From: Radical Date: Wed, 21 May 2025 20:49:13 +0200 Subject: [PATCH] feat: use diesel on Channel and ChannelPermission structs --- src/structs.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/structs.rs b/src/structs.rs index 1b339b1..7cec7c9 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -1,14 +1,15 @@ use std::str::FromStr; use actix_web::HttpResponse; +use diesel::Selectable; use log::error; use serde::{Deserialize, Serialize}; -use sqlx::{Pool, Postgres, prelude::FromRow}; use uuid::Uuid; -use crate::Data; +use crate::{Conn, Data, tables::*}; -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Deserialize, Clone, Selectable)] +#[diesel(table_name = channels)] pub struct Channel { pub uuid: Uuid, pub guild_uuid: Uuid, @@ -17,7 +18,7 @@ pub struct Channel { pub permissions: Vec, } -#[derive(Serialize, Clone, FromRow)] +#[derive(Serialize, Clone)] struct ChannelPermissionBuilder { role_uuid: String, permissions: i32, @@ -32,7 +33,8 @@ impl ChannelPermissionBuilder { } } -#[derive(Serialize, Deserialize, Clone, FromRow)] +#[derive(Serialize, Deserialize, Clone, Selectable)] +#[diesel(table_name = channel_permissions)] pub struct ChannelPermission { pub role_uuid: Uuid, pub permissions: i32, @@ -40,15 +42,10 @@ pub struct ChannelPermission { impl Channel { pub async fn fetch_all( - pool: &Pool, + conn: &mut Conn, guild_uuid: Uuid, ) -> Result, HttpResponse> { - let row = sqlx::query_as(&format!( - "SELECT CAST(uuid AS VARCHAR), name, description FROM channels WHERE guild_uuid = '{}'", - guild_uuid - )) - .fetch_all(pool) - .await; + if let Err(error) = row { error!("{}", error);