Skip to content

Commit

Permalink
update save_content
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Dec 11, 2021
1 parent 4401e15 commit 54f16b0
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions crates/adapter_fs/src/adapter/fs/page_repository.rs
@@ -1,6 +1,11 @@
use std::{fs, path::PathBuf, str::FromStr};

use entity::{PageContent, PageId};
use std::{
fs,
path::PathBuf,
str::FromStr,
sync::{Arc, Mutex},
};

use entity::{Page, PageContent, PageGraph, PageId};
use use_case::PageRepository;

// TODO: returns PathBuf
Expand All @@ -10,11 +15,15 @@ pub fn to_file_name(page_id: &PageId) -> String {

pub struct FsPageRepository {
data_dir: PathBuf,
page_graph: Arc<Mutex<PageGraph>>,
}

impl FsPageRepository {
pub fn new(data_dir: PathBuf) -> Self {
Self { data_dir }
Self {
data_dir,
page_graph: Arc::new(Mutex::new(PageGraph::default())),
}
}
}

Expand Down Expand Up @@ -54,6 +63,11 @@ impl PageRepository for FsPageRepository {
}

fn save_content(&self, page_id: &PageId, content: PageContent) -> anyhow::Result<()> {
// TODO: graph.remove_page(page) if exists
let mut page_graph = self.page_graph.lock().unwrap(); // TODO
page_graph.add_page(Page::new(page_id.to_owned(), content.clone()));
// TODO: fix file watcher

let file_name = to_file_name(page_id);
let file_name = self.data_dir.join(file_name.as_str());
Ok(fs::write(file_name, String::from(content))?)
Expand Down

0 comments on commit 54f16b0

Please sign in to comment.