10 changed files with 270 additions and 121 deletions
@ -1,15 +1,11 @@ |
|||||||
// use std::fmt;
|
use thiserror::Error; |
||||||
|
|
||||||
// #[derive(Debug)]
|
#[derive(Error, Debug)] |
||||||
// pub enum RepositoryError {
|
pub enum RepositoryError { |
||||||
// NotFound,
|
#[error("Data source connection failed")] |
||||||
// ConnectionFailed,
|
ConnectionFailed, |
||||||
// InvalidData(String),
|
#[error("Dictionary '{0}' not found")] |
||||||
// Unexpected(String),
|
NotFound(String), |
||||||
// }
|
#[error("Storage error: {0}")] |
||||||
|
StorageError(String), |
||||||
// impl fmt::Display for RepositoryError {
|
} |
||||||
// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
// write!(f, "{:?}", self)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|||||||
@ -1,15 +1,38 @@ |
|||||||
|
use super::entities::{Dict, DictEntry}; |
||||||
|
use super::errors::RepositoryError; |
||||||
|
|
||||||
pub trait SystemEncoder { |
pub trait SystemEncoder { |
||||||
fn encode(&self, word: &str) -> String; |
fn encode(&self, word: &str) -> String; |
||||||
} |
} |
||||||
|
|
||||||
// pub trait WordRepository {
|
// pub trait SystenDecoder {
|
||||||
// fn save(word: &WordEntry) -> Result<WordEntryId, RepositoryError>;
|
// fn initialize(&self) -> Result<(), anyhow::Error>;
|
||||||
// fn save_many(words: &Vec<WordEntry>) -> Result<(), RepositoryError>;
|
|
||||||
// fn fetch(id: WordEntryId) -> Result<WordEntry, RepositoryError>;
|
|
||||||
// fn fetch_many(ids: &Vec<WordEntryId>) -> Result<Vec<WordEntry>, RepositoryError>;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub trait DictRepository {
|
|
||||||
// fn save(dict: &Dict) -> Result<(), RepositoryError>;
|
|
||||||
// fn fetch(name: &str) -> Result<Dict, RepositoryError>;
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
#[async_trait::async_trait] |
||||||
|
pub trait DictRepository: Send + Sync { |
||||||
|
async fn create(&self, name: &str) -> Result<(), RepositoryError>; |
||||||
|
|
||||||
|
/// "Upsert" logic:
|
||||||
|
/// - If entry exists (by text), update metadata.
|
||||||
|
/// - If not, insert new.
|
||||||
|
/// - IDs are handled by the Database.
|
||||||
|
async fn save_entries( |
||||||
|
&self, |
||||||
|
dict_name: &str, |
||||||
|
entries: &[DictEntry], |
||||||
|
) -> Result<(), RepositoryError>; |
||||||
|
|
||||||
|
/// Fetch a page of entries.
|
||||||
|
async fn fetch_many( |
||||||
|
&self, |
||||||
|
name: &str, |
||||||
|
limit: Option<u32>, |
||||||
|
offset: Option<u32>, |
||||||
|
) -> Result<Dict, RepositoryError>; |
||||||
|
} |
||||||
|
|
||||||
|
pub trait DictSource { |
||||||
|
fn next_entry(&mut self) -> Option<Result<DictEntry, anyhow::Error>>; |
||||||
|
} |
||||||
|
|||||||
Loading…
Reference in new issue