refactor ent comment
Instead of a two-step process handled by the application (`Issue::new_comment()` and `Comment::set_description()` or `Comment::edit_description()`), make a simpler-to-use single-step `Issue::add_comment()`. Move the implementation details from Issue to Comment. Better log message when adding a comment.
This commit is contained in:
parent
1c8d994fd9
commit
d642004ee0
3 changed files with 111 additions and 60 deletions
26
src/issue.rs
26
src/issue.rs
|
|
@ -161,25 +161,13 @@ impl Issue {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn new_comment(&mut self) -> Result<crate::comment::Comment, IssueError> {
|
||||
let mut dir = std::path::PathBuf::from(&self.dir);
|
||||
dir.push("comments");
|
||||
if !dir.exists() {
|
||||
std::fs::create_dir(&dir)?;
|
||||
}
|
||||
|
||||
let rnd: u128 = rand::random();
|
||||
let uuid = format!("{:032x}", rnd);
|
||||
dir.push(&uuid);
|
||||
std::fs::create_dir(&dir)?;
|
||||
|
||||
Ok(crate::comment::Comment {
|
||||
uuid,
|
||||
author: String::from("Sebastian Kuzminsky <seb@highlab.com>"),
|
||||
timestamp: chrono::Local::now(),
|
||||
description: String::from(""), // FIXME
|
||||
dir,
|
||||
})
|
||||
/// Add a new Comment to the Issue. Commits.
|
||||
pub fn add_comment(
|
||||
&mut self,
|
||||
description: &Option<String>,
|
||||
) -> Result<crate::comment::Comment, IssueError> {
|
||||
let comment = crate::comment::Comment::new(self, description)?;
|
||||
Ok(comment)
|
||||
}
|
||||
|
||||
/// Create a new Issue in an Issues database specified by a directory.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue