10 changed files with 270 additions and 121 deletions
@ -1,15 +1,11 @@
|
||||
// use std::fmt;
|
||||
use thiserror::Error; |
||||
|
||||
// #[derive(Debug)]
|
||||
// pub enum RepositoryError {
|
||||
// NotFound,
|
||||
// ConnectionFailed,
|
||||
// InvalidData(String),
|
||||
// Unexpected(String),
|
||||
// }
|
||||
|
||||
// impl fmt::Display for RepositoryError {
|
||||
// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// write!(f, "{:?}", self)
|
||||
// }
|
||||
// }
|
||||
#[derive(Error, Debug)] |
||||
pub enum RepositoryError { |
||||
#[error("Data source connection failed")] |
||||
ConnectionFailed, |
||||
#[error("Dictionary '{0}' not found")] |
||||
NotFound(String), |
||||
#[error("Storage error: {0}")] |
||||
StorageError(String), |
||||
} |
||||
|
||||
@ -1,15 +1,38 @@
|
||||
use super::entities::{Dict, DictEntry}; |
||||
use super::errors::RepositoryError; |
||||
|
||||
pub trait SystemEncoder { |
||||
fn encode(&self, word: &str) -> String; |
||||
} |
||||
|
||||
// pub trait WordRepository {
|
||||
// fn save(word: &WordEntry) -> Result<WordEntryId, RepositoryError>;
|
||||
// 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 SystenDecoder {
|
||||
// fn initialize(&self) -> Result<(), anyhow::Error>;
|
||||
|
||||
// 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