33 lines
889 B
Rust
33 lines
889 B
Rust
use rcc::TerminalSize;
|
|
|
|
use crate::{entity::file::Page, repository::file_repo::FileRepo};
|
|
|
|
pub struct FileService {
|
|
repo: FileRepo,
|
|
}
|
|
|
|
impl TerminalSize for FileService {}
|
|
|
|
impl FileService {
|
|
pub fn new(repo: FileRepo) -> Self {
|
|
Self { repo }
|
|
}
|
|
|
|
pub fn get_page(&mut self, page_id: &usize) -> Result<(), Box<dyn std::error::Error>> {
|
|
let page = self.repo.find_page(page_id)?;
|
|
|
|
if page.is_empty() {
|
|
println!("No page found.");
|
|
} else {
|
|
page.into_iter().for_each(|page: Page| {
|
|
println!("{}", "-".repeat(self.get_width()));
|
|
println!("M-ID: {}", page.m_id);
|
|
println!("FileName: {}", page.file);
|
|
println!("Title: {}", page.title);
|
|
});
|
|
println!("{}", "-".repeat(self.get_width()));
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|