feat: started on auditlog object
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
This commit is contained in:
parent
e8de96b2d0
commit
b49e5036be
2 changed files with 65 additions and 0 deletions
63
src/objects/auditlog.rs
Normal file
63
src/objects/auditlog.rs
Normal file
|
@ -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<Uuid>,
|
||||||
|
pub user_uuid: Option<Uuid>,
|
||||||
|
pub message_uuid: Option<Uuid>,
|
||||||
|
pub role_uuid: Option<Uuid>,
|
||||||
|
pub audit_message: Option<String>,
|
||||||
|
pub changed_from: Option<String>,
|
||||||
|
pub changed_to: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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<Uuid>,
|
||||||
|
user_uuid: Option<Uuid>,
|
||||||
|
message_uuid: Option<Uuid>,
|
||||||
|
role_uuid: Option<Uuid>,
|
||||||
|
audit_message: Option<String>,
|
||||||
|
changed_from: Option<String>,
|
||||||
|
changed_to: Option<String>,
|
||||||
|
) ->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(())
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,6 +19,7 @@ mod message;
|
||||||
mod password_reset_token;
|
mod password_reset_token;
|
||||||
mod role;
|
mod role;
|
||||||
mod user;
|
mod user;
|
||||||
|
mod auditlog;
|
||||||
|
|
||||||
pub use bans::GuildBan;
|
pub use bans::GuildBan;
|
||||||
pub use channel::Channel;
|
pub use channel::Channel;
|
||||||
|
@ -34,6 +35,7 @@ pub use password_reset_token::PasswordResetToken;
|
||||||
pub use role::Permissions;
|
pub use role::Permissions;
|
||||||
pub use role::Role;
|
pub use role::Role;
|
||||||
pub use user::User;
|
pub use user::User;
|
||||||
|
pub use auditlog::AuditLog;
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue