diff options
Diffstat (limited to 'ticket/src/actions.rs')
-rw-r--r-- | ticket/src/actions.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/ticket/src/actions.rs b/ticket/src/actions.rs index b6d8cb0..d2ebf24 100644 --- a/ticket/src/actions.rs +++ b/ticket/src/actions.rs @@ -1,4 +1,5 @@ use crate::{ + Status, Ticket, TicketV0, }; @@ -117,3 +118,30 @@ pub fn uuid_v1() -> Result<Uuid> { &[random(), random(), random(), random(), random(), random()], )?) } + +#[allow(clippy::needless_pass_by_value)] +pub fn save_ticket(ticket: Ticket) -> Result<()> { + fs::write(ticket_path(&ticket)?, toml::to_string_pretty(&ticket)?)?; + Ok(()) +} + +pub fn ticket_file_name(ticket: &Ticket) -> String { + let mut name = ticket + .title + .split_whitespace() + .collect::<Vec<&str>>() + .join("-"); + name.push_str(".toml"); + name = name.to_lowercase(); + name +} + +pub fn ticket_path(ticket: &Ticket) -> Result<PathBuf> { + Ok( + match ticket.status { + Status::Open => open_tickets()?, + Status::Closed => closed_tickets()?, + } + .join(ticket_file_name(&ticket)), + ) +} |