systemprompt_logging/services/
maintenance.rs1use chrono::{DateTime, Utc};
7use systemprompt_database::DbPool;
8
9use crate::models::{LogEntry, LogFilter, LoggingError};
10use crate::repository::LoggingRepository;
11
12#[derive(Clone, Debug)]
13pub struct LoggingMaintenanceService {
14 repo: LoggingRepository,
15}
16
17impl LoggingMaintenanceService {
18 pub fn new(db_pool: &DbPool) -> Result<Self, LoggingError> {
19 Ok(Self {
20 repo: LoggingRepository::new(db_pool)?,
21 })
22 }
23
24 pub async fn get_recent_logs(&self, limit: i64) -> Result<Vec<LogEntry>, LoggingError> {
25 self.repo.get_recent_logs(limit).await
26 }
27
28 pub async fn get_filtered_logs(
29 &self,
30 filter: &LogFilter,
31 ) -> Result<(Vec<LogEntry>, i64), LoggingError> {
32 self.repo.get_logs_paginated(filter).await
33 }
34
35 pub async fn cleanup_old_logs(&self, older_than: DateTime<Utc>) -> Result<u64, LoggingError> {
36 self.repo.cleanup_old_logs(older_than).await
37 }
38
39 pub async fn count_logs_before(&self, cutoff: DateTime<Utc>) -> Result<u64, LoggingError> {
40 self.repo.count_logs_before(cutoff).await
41 }
42
43 pub async fn clear_all_logs(&self) -> Result<u64, LoggingError> {
44 self.repo.clear_all_logs().await
45 }
46}