systemprompt_content/services/
content.rs1use crate::error::ContentError;
2use crate::models::Content;
3use crate::repository::ContentRepository;
4use systemprompt_database::DbPool;
5use systemprompt_identifiers::SourceId;
6
7#[derive(Debug)]
8pub struct ContentService {
9 repo: ContentRepository,
10}
11
12impl ContentService {
13 pub fn new(db: &DbPool) -> Result<Self, ContentError> {
14 Ok(Self {
15 repo: ContentRepository::new(db)?,
16 })
17 }
18
19 pub async fn list_by_source(&self, source_id: &SourceId) -> Result<Vec<Content>, ContentError> {
20 self.repo
21 .list_by_source(source_id)
22 .await
23 .map_err(ContentError::from)
24 }
25
26 pub async fn get_by_source_and_slug(
27 &self,
28 source_id: &SourceId,
29 slug: &str,
30 ) -> Result<Option<Content>, ContentError> {
31 self.repo
32 .get_by_source_and_slug(source_id, slug)
33 .await
34 .map_err(ContentError::from)
35 }
36}