Skip to main content

systemprompt_files/services/ai/
mod.rs

1use anyhow::Result;
2use systemprompt_database::DbPool;
3use systemprompt_identifiers::UserId;
4
5use crate::models::File;
6use crate::repository::FileRepository;
7
8#[derive(Debug, Clone)]
9pub struct AiService {
10    repository: FileRepository,
11}
12
13impl AiService {
14    pub fn new(db: &DbPool) -> Result<Self> {
15        Ok(Self {
16            repository: FileRepository::new(db)?,
17        })
18    }
19
20    pub const fn from_repository(repository: FileRepository) -> Self {
21        Self { repository }
22    }
23
24    pub const fn repository(&self) -> &FileRepository {
25        &self.repository
26    }
27
28    pub async fn list_ai_images(&self, limit: i64, offset: i64) -> Result<Vec<File>> {
29        self.repository.list_ai_images(limit, offset).await
30    }
31
32    pub async fn list_ai_images_by_user(
33        &self,
34        user_id: &UserId,
35        limit: i64,
36        offset: i64,
37    ) -> Result<Vec<File>> {
38        self.repository
39            .list_ai_images_by_user(user_id, limit, offset)
40            .await
41    }
42
43    pub async fn count_ai_images_by_user(&self, user_id: &UserId) -> Result<i64> {
44        self.repository.count_ai_images_by_user(user_id).await
45    }
46
47    pub async fn count_ai_images(&self) -> Result<i64> {
48        self.repository.count_ai_images().await
49    }
50}