From b49e5036be10ee64da8596ac1b0d6188c41ac6bf Mon Sep 17 00:00:00 2001 From: BAaboe Date: Tue, 5 Aug 2025 09:58:37 +0200 Subject: [PATCH] feat: started on auditlog object --- src/objects/auditlog.rs | 63 +++++++++++++++++++++++++++++++++++++++++ src/objects/mod.rs | 2 ++ 2 files changed, 65 insertions(+) create mode 100644 src/objects/auditlog.rs diff --git a/src/objects/auditlog.rs b/src/objects/auditlog.rs new file mode 100644 index 0000000..d55fe06 --- /dev/null +++ b/src/objects/auditlog.rs @@ -0,0 +1,63 @@ +use uuid::Uuid; +use diesel::{insert_into, Insertable, Queryable, Selectable, SelectableHelper}; +use serde::{Deserialize, Serialize}; +use crate::{error::Error, schema::audit_logs, Conn}; +use diesel_async::RunQueryDsl; + + +#[derive(Insertable, Selectable, Queryable, Serialize, Deserialize, Clone)] +#[diesel(table_name = audit_logs)] +#[diesel(check_for_backend(diesel::pg::Pg))] +pub struct AuditLog { + + pub uuid: Uuid, + pub guild_uuid: Uuid, + pub action_id: i16, + pub by_uuid: Uuid, + pub channel_uuid: Option, + pub user_uuid: Option, + pub message_uuid: Option, + pub role_uuid: Option, + pub audit_message: Option, + pub changed_from: Option, + pub changed_to: Option, +} + + +impl AuditLog { + #[allow(clippy::new_ret_no_self)] + pub async fn new( + conn: &mut Conn, + guild_uuid: Uuid, + action_id: i16, + by_uuid: Uuid, + channel_uuid: Option, + user_uuid: Option, + message_uuid: Option, + role_uuid: Option, + audit_message: Option, + changed_from: Option, + changed_to: Option, + ) ->Result<(), Error> { + let audit_log = AuditLog { + uuid: Uuid::now_v7(), + guild_uuid, + action_id, + by_uuid, + channel_uuid, + user_uuid, + message_uuid, + role_uuid, + audit_message, + changed_from, + changed_to + }; + + insert_into(audit_logs::table) + .values(audit_log.clone()) + .execute(conn) + .await?; + + Ok(()) + } +} diff --git a/src/objects/mod.rs b/src/objects/mod.rs index 3bcce9c..bedf442 100644 --- a/src/objects/mod.rs +++ b/src/objects/mod.rs @@ -19,6 +19,7 @@ mod message; mod password_reset_token; mod role; mod user; +mod auditlog; pub use bans::GuildBan; pub use channel::Channel; @@ -34,6 +35,7 @@ pub use password_reset_token::PasswordResetToken; pub use role::Permissions; pub use role::Role; pub use user::User; +pub use auditlog::AuditLog; use crate::error::Error;