- Apply rustfmt to all Rust source files in backend/ - Fix trailing whitespace inconsistencies - Standardize formatting across handlers, models, and services - Improve code readability with consistent formatting These changes are purely stylistic and do not affect functionality. All CI checks now pass with proper formatting.
41 lines
1 KiB
Rust
41 lines
1 KiB
Rust
use crate::models::audit_log::{AuditEventType, AuditLog, AuditLogRepository};
|
|
use anyhow::Result;
|
|
use mongodb::bson::oid::ObjectId;
|
|
|
|
#[derive(Clone)]
|
|
pub struct AuditLogger {
|
|
repository: AuditLogRepository,
|
|
}
|
|
|
|
impl AuditLogger {
|
|
pub fn new(db: &mongodb::Database) -> Self {
|
|
Self {
|
|
repository: AuditLogRepository::new(db),
|
|
}
|
|
}
|
|
|
|
pub async fn log_event(
|
|
&self,
|
|
event_type: AuditEventType,
|
|
user_id: Option<ObjectId>,
|
|
email: Option<String>,
|
|
ip_address: String,
|
|
resource_type: Option<String>,
|
|
resource_id: Option<String>,
|
|
) -> Result<ObjectId> {
|
|
self.repository
|
|
.log(
|
|
event_type,
|
|
user_id,
|
|
email,
|
|
ip_address,
|
|
resource_type,
|
|
resource_id,
|
|
)
|
|
.await
|
|
}
|
|
|
|
pub async fn get_user_audit_logs(&self, user_id: &ObjectId) -> Result<Vec<AuditLog>> {
|
|
self.repository.find_by_user(user_id).await
|
|
}
|
|
}
|