Implement DTOs, add managed state for schedule, export to txt
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
// here lies the logic for the export of the final schedule into docx/pdf formats
|
||||
|
||||
use crate::schedule::MonthlySchedule;
|
||||
use std::{fs::File, io::Write};
|
||||
|
||||
use log::info;
|
||||
|
||||
use crate::{
|
||||
config::UserConfig,
|
||||
schedule::MonthlySchedule,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum FileType {
|
||||
Txt,
|
||||
Json,
|
||||
Csv,
|
||||
Doc,
|
||||
@@ -11,16 +19,17 @@ pub enum FileType {
|
||||
}
|
||||
|
||||
pub trait Export {
|
||||
fn export(&self, file_type: FileType);
|
||||
fn export(&self, file_type: FileType, config: &UserConfig);
|
||||
}
|
||||
|
||||
impl Export for MonthlySchedule {
|
||||
fn export(&self, file_type: FileType) {
|
||||
fn export(&self, file_type: FileType, config: &UserConfig) {
|
||||
match file_type {
|
||||
FileType::Csv => self.export_as_csv(),
|
||||
FileType::Json => self.export_as_json(),
|
||||
FileType::Doc => self.export_as_doc(),
|
||||
FileType::Pdf => self.export_as_pdf(),
|
||||
FileType::Txt => self.export_as_txt(config),
|
||||
FileType::Csv => self.export_as_csv(config),
|
||||
FileType::Json => self.export_as_json(config),
|
||||
FileType::Doc => self.export_as_doc(config),
|
||||
FileType::Pdf => self.export_as_pdf(config),
|
||||
};
|
||||
|
||||
// TODO: make this env var from a config file? Option to change this in-app
|
||||
@@ -29,27 +38,35 @@ impl Export for MonthlySchedule {
|
||||
"exported type {:?}. Saved at folder path {}",
|
||||
file_type, env_path
|
||||
);
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl MonthlySchedule {
|
||||
// return error result as string or nothing, maybe use anyhow
|
||||
// or just return a string.. for now
|
||||
pub fn export_as_txt(&self, config: &UserConfig) -> String {
|
||||
let file = File::create("schedule.txt").unwrap();
|
||||
let mut writer = std::io::BufWriter::new(file);
|
||||
writer
|
||||
.write_all(self.pretty_print(config).as_bytes())
|
||||
.expect("Failed to write to buffer");
|
||||
|
||||
pub fn export_as_csv(&self) -> String {
|
||||
writer.flush().expect("Failed to flush buffer");
|
||||
info!("im here");
|
||||
"ok".to_string()
|
||||
}
|
||||
|
||||
pub fn export_as_csv(&self, config: &UserConfig) -> String {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn export_as_json(&self) -> String {
|
||||
pub fn export_as_json(&self, config: &UserConfig) -> String {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn export_as_doc(&self) -> String {
|
||||
pub fn export_as_doc(&self, config: &UserConfig) -> String {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn export_as_pdf(&self) -> String {
|
||||
pub fn export_as_pdf(&self, config: &UserConfig) -> String {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user