Skip to main content

systemprompt_traits/
content.rs

1use async_trait::async_trait;
2use chrono::{DateTime, Utc};
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct ContentSummary {
7    pub id: String,
8    pub slug: String,
9    pub title: String,
10    pub description: String,
11    pub published_at: DateTime<Utc>,
12    pub kind: String,
13    pub source_id: String,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct ContentItem {
18    pub id: String,
19    pub slug: String,
20    pub title: String,
21    pub description: String,
22    pub body: String,
23    pub author: String,
24    pub published_at: DateTime<Utc>,
25    pub keywords: String,
26    pub kind: String,
27    pub image: Option<String>,
28    pub source_id: String,
29    pub category_id: Option<String>,
30}
31
32#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
33pub struct ContentFilter {
34    pub source_id: Option<String>,
35    pub category_id: Option<String>,
36    pub kind: Option<String>,
37    pub query: Option<String>,
38    pub limit: Option<i64>,
39    pub offset: Option<i64>,
40}
41
42#[async_trait]
43pub trait ContentProvider: Send + Sync {
44    type Error: std::error::Error + Send + Sync + 'static;
45
46    async fn get_content(&self, id: &str) -> Result<Option<ContentItem>, Self::Error>;
47
48    async fn get_content_by_slug(&self, slug: &str) -> Result<Option<ContentItem>, Self::Error>;
49
50    async fn get_content_by_source_and_slug(
51        &self,
52        source_id: &str,
53        slug: &str,
54    ) -> Result<Option<ContentItem>, Self::Error>;
55
56    async fn list_content(&self, filter: ContentFilter)
57        -> Result<Vec<ContentSummary>, Self::Error>;
58
59    async fn search(
60        &self,
61        query: &str,
62        limit: Option<i64>,
63    ) -> Result<Vec<ContentSummary>, Self::Error>;
64}