feat: adds remaining Navigator actions

This commit is contained in:
itsscb 2024-08-12 20:30:45 +02:00
parent 7ec23699a8
commit 786ab80474
3 changed files with 35 additions and 16 deletions

6
flake.lock generated

@ -30,11 +30,11 @@
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1722738111,
"narHash": "sha256-cWD5pCs9AYb+512/yCx9D0Pl5KcmyuXHeJpsDw/D1vs=",
"lastModified": 1723429325,
"narHash": "sha256-4x/32xTCd+xCwFoI/kKSiCr5LQA2ZlyTRYXKEni5HR8=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "27ec296d93cb4b2d03e8cbd019b1b4cde8c34280",
"rev": "65e3dc0fe079fe8df087cd38f1fe6836a0373aad",
"type": "github"
},
"original": {

@ -16,7 +16,7 @@ pub struct Navigator {
impl Navigator {
pub fn new(db: Rc<JiraDatabase>) -> Self {
Self {
pages: vec![],
pages: vec![Box::new(HomePage::new(Rc::clone(&db)))],
prompts: Prompts::new(),
db,
}
@ -49,28 +49,41 @@ impl Navigator {
}
Action::CreateEpic => {
// prompt the user to create a new epic and persist it in the database
self.db.create_epic((self.prompts.create_epic)());
self.db
.create_epic((self.prompts.create_epic)())
.with_context(|| format!("failed to create epic"))?;
}
Action::UpdateEpicStatus { epic_id } => {
todo!(); // prompt the user to update status and persist it in the database
// let status = (self.prompts.update_status)().(|| {
// return Err(anyhow!("failed to update epic status")
// .context(format!("invalid status given")));
// });
self.db
.update_epic_status(epic_id, crate::models::Status::Open);
// prompt the user to update status and persist it in the database
let status = (self.prompts.update_status)()
.with_context(|| format!("invalid status: {epic_id}"))?;
self.db.update_epic_status(epic_id, status)?;
}
Action::DeleteEpic { epic_id } => {
todo!() // prompt the user to delete the epic and persist it in the database
// prompt the user to delete the epic and persist it in the database
self.db
.delete_epic(epic_id)
.with_context(|| format!("failed to delete epic: {epic_id}"))?;
}
Action::CreateStory { epic_id } => {
todo!() // prompt the user to create a new story and persist it in the database
// prompt the user to create a new story and persist it in the database
self.db
.create_story((self.prompts.create_story)(), epic_id)
.with_context(|| format!("failed to create story: {epic_id}"))?;
}
Action::UpdateStoryStatus { story_id } => {
todo!() // prompt the user to update status and persist it in the database
// prompt the user to update status and persist it in the database
let status = (self.prompts.update_status)()
.with_context(|| format!("invalid status: {story_id}"))?;
self.db.update_story_status(story_id, status)?;
}
Action::DeleteStory { epic_id, story_id } => {
todo!() // prompt the user to delete the story and persist it in the database
// prompt the user to delete the story and persist it in the database
if (self.prompts.delete_story)() {
self.db
.delete_story(epic_id, story_id)
.with_context(|| format!("failed to delete story: {story_id}"))?;
}
}
Action::Exit => {
// remove all pages from the pages vector

@ -20,6 +20,12 @@ pub trait Page {
pub struct HomePage {
pub db: Rc<JiraDatabase>,
}
impl HomePage {
pub fn new(db: Rc<JiraDatabase>) -> Self {
Self { db }
}
}
impl Page for HomePage {
fn draw_page(&self) -> Result<()> {
println!("----------------------------- EPICS -----------------------------");