Refactoring

This commit is contained in:
2025-09-09 07:39:16 +03:00
parent e7713f3529
commit c86be31d54
7 changed files with 87 additions and 39 deletions

View File

@@ -10,19 +10,20 @@ use url::Url;
const AUTHOR_URL_PREFIX: &str = "author";
pub struct Books<R: Repository<Book, BookFilter>> {
pub repo: Arc<Mutex<R>>,
pub struct Books {
pub repo: Arc<Mutex<Box<dyn Repository<Book, BookFilter> + 'static>>>,
root: PathBuf,
base_url: Url,
}
impl<R: Repository<Book, BookFilter>> Books<R>
where
R: 'static,
{
pub fn new(repo: R, root: PathBuf, base_url: String) -> Self {
impl Books {
pub fn new(
repo: Arc<Mutex<Box<dyn Repository<Book, BookFilter> + 'static>>>,
root: PathBuf,
base_url: String,
) -> Self {
Books {
repo: Arc::new(Mutex::new(repo)),
repo,
root,
base_url: Url::parse(&base_url).unwrap(),
}
@@ -68,7 +69,15 @@ where
pub fn add_books_from_path(&mut self) {
let iter = fs::Loader::new(PathBuf::from(&self.root));
self.repo.lock().unwrap().bulk_add(iter);
match self.repo.lock() {
Ok(mut repo) => {
for book in iter {
repo.add(book);
}
}
Err(err) => eprintln!("{}", err),
}
}
pub fn watch_dir(&mut self) -> Result<(), io::Error> {