added page/file service
parent
277a69334d
commit
0278baf597
|
@ -32,5 +32,9 @@ pub enum Commands {
|
|||
config: bool,
|
||||
#[arg(short, long)]
|
||||
log: bool,
|
||||
},
|
||||
Page {
|
||||
// #[arg(short, long)]
|
||||
page_id: usize
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use mysql::PooledConn;
|
||||
|
||||
use crate::{
|
||||
repository::{filter_repo::FilterRepo, merchant_repo::MerchantRepo, schema_repo::SchemaRepo},
|
||||
repository::{filter_repo::FilterRepo, merchant_repo::MerchantRepo, schema_repo::SchemaRepo, file_repo::FileRepo},
|
||||
service::{
|
||||
filter_service::FilterService, merchant_service::MerchantService,
|
||||
schema_service::SchemaService,
|
||||
schema_service::SchemaService, file_service::FileService,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -22,3 +22,8 @@ pub fn get_schema_service(pool: &mut PooledConn) -> SchemaService {
|
|||
let repo = SchemaRepo::new(pool);
|
||||
return SchemaService::new(repo);
|
||||
}
|
||||
|
||||
pub fn get_page_service(pool: &mut PooledConn) -> FileService {
|
||||
let repo = FileRepo::new(pool);
|
||||
return FileService::new(repo);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct Page {
|
||||
pub m_id: usize,
|
||||
pub title: String,
|
||||
pub file: String,
|
||||
}
|
|
@ -3,3 +3,4 @@ pub mod schema;
|
|||
pub mod filter;
|
||||
pub mod filter_log;
|
||||
pub mod filter_config;
|
||||
pub mod file;
|
||||
|
|
|
@ -3,7 +3,7 @@ use cli::command::{Cli, Commands};
|
|||
use database::db::Db;
|
||||
use mysql::PooledConn;
|
||||
use service::{
|
||||
filter_service::FilterService, merchant_service::MerchantService, schema_service::SchemaService,
|
||||
filter_service::FilterService, merchant_service::MerchantService, schema_service::SchemaService, file_service::FileService,
|
||||
};
|
||||
|
||||
pub mod cli;
|
||||
|
@ -43,6 +43,10 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
|||
filter_service.get_filter_log(&filter_id)
|
||||
}
|
||||
}
|
||||
Commands::Page { page_id } => {
|
||||
let file_service: FileService = container::get_page_service(&mut conn);
|
||||
file_service.get_page(&page_id);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
use mysql::{PooledConn, params, prelude::Queryable};
|
||||
|
||||
use crate::entity::file::Page;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FileRepo<'a> {
|
||||
db_pool: &'a mut PooledConn,
|
||||
}
|
||||
|
||||
impl<'a> FileRepo<'a> {
|
||||
pub fn new(db_pool: &'a mut PooledConn) -> Self {
|
||||
Self { db_pool }
|
||||
}
|
||||
|
||||
pub fn find_page(self, file_id: &usize) -> Result<Vec<Page>, mysql::Error> {
|
||||
let stat = self.db_pool
|
||||
.prep("SELECT m_id, description, file FROM global_data.effi_file_mapping WHERE file_id = :file_id")
|
||||
.unwrap();
|
||||
|
||||
|
||||
self.db_pool.exec_map(
|
||||
stat,
|
||||
params! {"file_id" => file_id},
|
||||
|(m_id, description, file)| Page { m_id, title: description, file },
|
||||
)
|
||||
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
pub mod merchant_repo;
|
||||
pub mod schema_repo;
|
||||
pub mod filter_repo;
|
||||
pub mod file_repo;
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
use crate::{entity::file::Page, repository::file_repo::FileRepo};
|
||||
|
||||
pub struct FileService<'a> {
|
||||
repo: FileRepo<'a>,
|
||||
}
|
||||
|
||||
impl<'a> FileService<'a> {
|
||||
pub fn new(repo: FileRepo<'a>) -> Self {
|
||||
Self { repo }
|
||||
}
|
||||
|
||||
pub fn get_page(self, page_id: &usize) {
|
||||
let result = self.repo.find_page(page_id);
|
||||
|
||||
match result {
|
||||
Ok(page) => {
|
||||
if page.is_empty() {
|
||||
println!("No page found.");
|
||||
} else {
|
||||
page.into_iter().for_each(|page: Page| {
|
||||
println!("{}", "-".repeat(150));
|
||||
println!("M-ID: {}", page.m_id);
|
||||
println!("FileName: {}", page.file);
|
||||
println!("Title: {}", page.title);
|
||||
});
|
||||
println!("{}", "-".repeat(150));
|
||||
}
|
||||
}
|
||||
Err(err) => panic!("{}", err),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
pub mod merchant_service;
|
||||
pub mod schema_service;
|
||||
pub mod filter_service;
|
||||
pub mod file_service;
|
||||
|
|
Loading…
Reference in New Issue