refactor: Improve app context creation

This commit is contained in:
Erik Kundt
2023-10-06 10:55:38 +02:00
parent f4eaf5c17e
commit f58c93a36f
11 changed files with 81 additions and 107 deletions
-68
View File
@@ -1,68 +0,0 @@
use radicle::cob::issue::{Issue, IssueId};
use radicle::cob::patch::{Patch, PatchId};
use radicle::prelude::{Id, Project, Signer};
use radicle::Profile;
use radicle::storage::git::Repository;
use radicle::storage::ReadStorage;
pub struct Context {
profile: Profile,
id: Id,
project: Project,
repository: Repository,
issues: Vec<(IssueId, Issue)>,
patches: Vec<(PatchId, Patch)>,
signer: Box<dyn Signer>,
}
impl Context {
pub fn new(profile: Profile, id: Id, project: Project, signer: Box<dyn Signer>) -> Self {
let repository = profile.storage.repository(id).unwrap();
let issues = crate::cob::issue::all(&repository).unwrap_or_default();
let patches = crate::cob::patch::all(&repository).unwrap_or_default();
Self {
id,
profile,
project,
repository,
issues,
patches,
signer,
}
}
pub fn profile(&self) -> &Profile {
&self.profile
}
pub fn id(&self) -> &Id {
&self.id
}
pub fn project(&self) -> &Project {
&self.project
}
pub fn repository(&self) -> &Repository {
&self.repository
}
pub fn issues(&self) -> &Vec<(IssueId, Issue)> {
&self.issues
}
pub fn patches(&self) -> &Vec<(PatchId, Patch)> {
&self.patches
}
#[allow(clippy::borrowed_box)]
pub fn signer(&self) -> &Box<dyn Signer> {
&self.signer
}
pub fn reload(&mut self) {
self.issues = crate::cob::issue::all(&self.repository).unwrap_or_default();
self.patches = crate::cob::patch::all(&self.repository).unwrap_or_default();
}
}