Skip to main content

scitadel_core/models/
question.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4use super::{QuestionId, SearchTermId};
5
6/// First-class research question entity.
7#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8pub struct ResearchQuestion {
9    pub id: QuestionId,
10    pub text: String,
11    #[serde(default)]
12    pub description: String,
13    pub created_at: DateTime<Utc>,
14    pub updated_at: DateTime<Utc>,
15}
16
17impl ResearchQuestion {
18    #[must_use]
19    pub fn new(text: impl Into<String>) -> Self {
20        let now = Utc::now();
21        Self {
22            id: QuestionId::new(),
23            text: text.into(),
24            description: String::new(),
25            created_at: now,
26            updated_at: now,
27        }
28    }
29}
30
31/// Keyword combination linked to a research question.
32#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
33pub struct SearchTerm {
34    pub id: SearchTermId,
35    pub question_id: QuestionId,
36    #[serde(default)]
37    pub terms: Vec<String>,
38    #[serde(default)]
39    pub query_string: String,
40    pub created_at: DateTime<Utc>,
41}
42
43impl SearchTerm {
44    #[must_use]
45    pub fn new(question_id: QuestionId) -> Self {
46        Self {
47            id: SearchTermId::new(),
48            question_id,
49            terms: Vec::new(),
50            query_string: String::new(),
51            created_at: Utc::now(),
52        }
53    }
54}