1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use miette::Result;
use crate::{id::ID, nouns::Article};
#[derive(Debug, Clone)]
pub struct NounAttemptSaved {
pub id: ID,
pub at: time::OffsetDateTime,
pub noun_attempt: NounAttempt,
}
#[derive(Debug, Clone)]
pub struct NounAttempt {
pub for_word: ID,
pub what_happened: Conclusion,
}
#[derive(Debug, Clone)]
pub enum Conclusion {
Success,
WrongArticle(Article),
}
pub trait Repo: Clone + Send + Sync + std::fmt::Debug {
/// Saves an attempt
///
/// # Errors
///
/// This function will return an error if the IO fails or the item already
/// Exists.
fn save_noun_attempt(self, attempt: NounAttemptSaved) -> Result<()>;
/// Returns all the attempts
///
/// # Errors
///
/// When IO failed.
fn all_noun_attempts(self) -> Result<Vec<NounAttemptSaved>>;
/// Find an attempt by its ID.
///
/// # Errors
///
/// This function will return an error if the item was not found or there
/// was an IO failure .
fn find_noun_attempt_by_id(self, id: ID) -> Result<NounAttemptSaved>;
/// Finds the attempts for an specific noun.
///
/// # Errors
///
/// This function will return an error if the item was not found or there
/// was an IO failure .
fn find_noun_attempt_by_noun_id(self, id: ID) -> Result<Vec<NounAttemptSaved>>;
/// Deletes an attempt by its ID.
///
/// # Errors
///
/// This function will return an error if the item was not found or there
/// was an IO failure .
fn delete_noun_attempt_by_id(self, id: ID) -> Result<()>;
}