diff --git a/src/api/mod.rs b/src/api/mod.rs index c0c3a9d..a456bd4 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -28,7 +28,7 @@ use project::{ use space::Space; use space_notification::SpaceNotification; use team::Team; -use user::{RecentlyViewedIssue, User}; +use user::{RecentlyViewedIssue, RecentlyViewedProject, RecentlyViewedWiki, Star, StarCount, User}; use wiki::{Wiki, WikiAttachment, WikiHistory, WikiListItem}; pub trait BacklogApi { @@ -36,6 +36,9 @@ pub trait BacklogApi { fn get_myself(&self) -> Result; fn get_users(&self) -> Result>; fn get_user(&self, user_id: u64) -> Result; + fn add_user(&self, params: &[(String, String)]) -> Result; + fn update_user(&self, user_id: u64, params: &[(String, String)]) -> Result; + fn delete_user(&self, user_id: u64) -> Result; fn get_space_activities(&self, params: &[(String, String)]) -> Result>; fn get_space_disk_usage(&self) -> Result; fn get_space_notification(&self) -> Result; @@ -86,6 +89,16 @@ pub trait BacklogApi { &self, params: &[(String, String)], ) -> Result>; + fn get_recently_viewed_projects( + &self, + params: &[(String, String)], + ) -> Result>; + fn get_recently_viewed_wikis( + &self, + params: &[(String, String)], + ) -> Result>; + fn get_user_stars(&self, user_id: u64, params: &[(String, String)]) -> Result>; + fn count_user_stars(&self, user_id: u64) -> Result; fn get_notifications(&self, params: &[(String, String)]) -> Result>; fn count_notifications(&self) -> Result; fn read_notification(&self, id: u64) -> Result<()>; @@ -109,6 +122,18 @@ impl BacklogApi for BacklogClient { self.get_user(user_id) } + fn add_user(&self, params: &[(String, String)]) -> Result { + self.add_user(params) + } + + fn update_user(&self, user_id: u64, params: &[(String, String)]) -> Result { + self.update_user(user_id, params) + } + + fn delete_user(&self, user_id: u64) -> Result { + self.delete_user(user_id) + } + fn get_space_activities(&self, params: &[(String, String)]) -> Result> { self.get_space_activities(params) } @@ -261,6 +286,28 @@ impl BacklogApi for BacklogClient { self.get_recently_viewed_issues(params) } + fn get_recently_viewed_projects( + &self, + params: &[(String, String)], + ) -> Result> { + self.get_recently_viewed_projects(params) + } + + fn get_recently_viewed_wikis( + &self, + params: &[(String, String)], + ) -> Result> { + self.get_recently_viewed_wikis(params) + } + + fn get_user_stars(&self, user_id: u64, params: &[(String, String)]) -> Result> { + self.get_user_stars(user_id, params) + } + + fn count_user_stars(&self, user_id: u64) -> Result { + self.count_user_stars(user_id) + } + fn get_notifications(&self, params: &[(String, String)]) -> Result> { self.get_notifications(params) } diff --git a/src/api/user.rs b/src/api/user.rs index cf72b7b..d8ad2de 100644 --- a/src/api/user.rs +++ b/src/api/user.rs @@ -42,6 +42,59 @@ pub struct RecentlyViewedIssue { pub extra: BTreeMap, } +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ProjectSummary { + pub id: u64, + pub project_key: String, + pub name: String, + #[serde(flatten)] + pub extra: BTreeMap, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RecentlyViewedProject { + pub project: ProjectSummary, + pub updated: String, + #[serde(flatten)] + pub extra: BTreeMap, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct WikiSummary { + pub id: u64, + pub name: String, + #[serde(flatten)] + pub extra: BTreeMap, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RecentlyViewedWiki { + pub page: WikiSummary, + pub updated: String, + #[serde(flatten)] + pub extra: BTreeMap, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Star { + pub id: u64, + pub comment: Option, + pub url: String, + pub title: String, + pub presenter: User, + pub created: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct StarCount { + pub count: u64, +} + impl BacklogClient { pub fn get_myself(&self) -> Result { let value = self.get("/users/myself")?; @@ -58,6 +111,21 @@ impl BacklogClient { deserialize(value, "user response") } + pub fn add_user(&self, params: &[(String, String)]) -> Result { + let value = self.post_form("/users", params)?; + deserialize(value, "user response") + } + + pub fn update_user(&self, user_id: u64, params: &[(String, String)]) -> Result { + let value = self.patch_form(&format!("/users/{user_id}"), params)?; + deserialize(value, "user response") + } + + pub fn delete_user(&self, user_id: u64) -> Result { + let value = self.delete_req(&format!("/users/{user_id}"))?; + deserialize(value, "user response") + } + pub fn get_user_activities( &self, user_id: u64, @@ -74,6 +142,32 @@ impl BacklogClient { let value = self.get_with_query("/users/myself/recentlyViewedIssues", params)?; deserialize(value, "recently viewed issues response") } + + pub fn get_recently_viewed_projects( + &self, + params: &[(String, String)], + ) -> Result> { + let value = self.get_with_query("/users/myself/recentlyViewedProjects", params)?; + deserialize(value, "recently viewed projects response") + } + + pub fn get_recently_viewed_wikis( + &self, + params: &[(String, String)], + ) -> Result> { + let value = self.get_with_query("/users/myself/recentlyViewedWikis", params)?; + deserialize(value, "recently viewed wikis response") + } + + pub fn get_user_stars(&self, user_id: u64, params: &[(String, String)]) -> Result> { + let value = self.get_with_query(&format!("/users/{user_id}/stars"), params)?; + deserialize(value, "user stars response") + } + + pub fn count_user_stars(&self, user_id: u64) -> Result { + let value = self.get(&format!("/users/{user_id}/stars/count"))?; + deserialize(value, "star count response") + } } #[cfg(test)] diff --git a/src/cmd/auth.rs b/src/cmd/auth.rs index 45b4f0e..498a9d8 100644 --- a/src/cmd/auth.rs +++ b/src/cmd/auth.rs @@ -387,6 +387,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, @@ -580,6 +593,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/issue/attachment/list.rs b/src/cmd/issue/attachment/list.rs index 0b77e8a..fc5e819 100644 --- a/src/cmd/issue/attachment/list.rs +++ b/src/cmd/issue/attachment/list.rs @@ -86,6 +86,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -257,6 +270,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/issue/comment/add.rs b/src/cmd/issue/comment/add.rs index f7bd3a8..9a7bcab 100644 --- a/src/cmd/issue/comment/add.rs +++ b/src/cmd/issue/comment/add.rs @@ -59,6 +59,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -228,6 +241,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/issue/comment/delete.rs b/src/cmd/issue/comment/delete.rs index 09fcef6..57f872c 100644 --- a/src/cmd/issue/comment/delete.rs +++ b/src/cmd/issue/comment/delete.rs @@ -61,6 +61,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -230,6 +243,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/issue/comment/list.rs b/src/cmd/issue/comment/list.rs index 9ff51eb..4aaa585 100644 --- a/src/cmd/issue/comment/list.rs +++ b/src/cmd/issue/comment/list.rs @@ -100,6 +100,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -269,6 +282,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/issue/comment/update.rs b/src/cmd/issue/comment/update.rs index 77c1b75..d6a4fc7 100644 --- a/src/cmd/issue/comment/update.rs +++ b/src/cmd/issue/comment/update.rs @@ -65,6 +65,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -234,6 +247,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/issue/count.rs b/src/cmd/issue/count.rs index 815a2cc..199d583 100644 --- a/src/cmd/issue/count.rs +++ b/src/cmd/issue/count.rs @@ -114,6 +114,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -285,6 +298,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/issue/create.rs b/src/cmd/issue/create.rs index 14b250d..895f7d5 100644 --- a/src/cmd/issue/create.rs +++ b/src/cmd/issue/create.rs @@ -98,6 +98,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -267,6 +280,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/issue/delete.rs b/src/cmd/issue/delete.rs index 3fbc1a4..95ad345 100644 --- a/src/cmd/issue/delete.rs +++ b/src/cmd/issue/delete.rs @@ -56,6 +56,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -225,6 +238,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/issue/list.rs b/src/cmd/issue/list.rs index 12bf8c8..e898f71 100644 --- a/src/cmd/issue/list.rs +++ b/src/cmd/issue/list.rs @@ -207,6 +207,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -376,6 +389,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/issue/show.rs b/src/cmd/issue/show.rs index b0d1afe..f0db8cf 100644 --- a/src/cmd/issue/show.rs +++ b/src/cmd/issue/show.rs @@ -80,6 +80,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -249,6 +262,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/issue/update.rs b/src/cmd/issue/update.rs index 4aaf293..85f2c3b 100644 --- a/src/cmd/issue/update.rs +++ b/src/cmd/issue/update.rs @@ -121,6 +121,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -290,6 +303,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/notification/count.rs b/src/cmd/notification/count.rs index d9db956..de40ffb 100644 --- a/src/cmd/notification/count.rs +++ b/src/cmd/notification/count.rs @@ -65,6 +65,19 @@ mod tests { fn get_user(&self, _: u64) -> Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities(&self, _: &[(String, String)]) -> Result> { unimplemented!() } @@ -175,6 +188,28 @@ mod tests { ) -> Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications(&self, _: &[(String, String)]) -> Result> { unimplemented!() } diff --git a/src/cmd/notification/list.rs b/src/cmd/notification/list.rs index f37a4ad..6c42c65 100644 --- a/src/cmd/notification/list.rs +++ b/src/cmd/notification/list.rs @@ -128,6 +128,19 @@ mod tests { fn get_user(&self, _: u64) -> Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities(&self, _: &[(String, String)]) -> Result> { unimplemented!() } @@ -238,6 +251,28 @@ mod tests { ) -> Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications(&self, _: &[(String, String)]) -> Result> { Ok(self.notifications.clone()) } @@ -410,6 +445,19 @@ mod tests { fn get_user(&self, _: u64) -> Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities(&self, _: &[(String, String)]) -> Result> { unimplemented!() } @@ -520,6 +568,28 @@ mod tests { ) -> Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications(&self, params: &[(String, String)]) -> Result> { *self.captured.borrow_mut() = params.to_vec(); Ok(vec![]) diff --git a/src/cmd/notification/read.rs b/src/cmd/notification/read.rs index 9f2361e..72402d0 100644 --- a/src/cmd/notification/read.rs +++ b/src/cmd/notification/read.rs @@ -58,6 +58,19 @@ mod tests { fn get_user(&self, _: u64) -> Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities(&self, _: &[(String, String)]) -> Result> { unimplemented!() } @@ -168,6 +181,28 @@ mod tests { ) -> Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications(&self, _: &[(String, String)]) -> Result> { unimplemented!() } diff --git a/src/cmd/notification/reset_unread.rs b/src/cmd/notification/reset_unread.rs index db326c0..cf40eb3 100644 --- a/src/cmd/notification/reset_unread.rs +++ b/src/cmd/notification/reset_unread.rs @@ -46,6 +46,19 @@ mod tests { fn get_user(&self, _: u64) -> Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities(&self, _: &[(String, String)]) -> Result> { unimplemented!() } @@ -156,6 +169,28 @@ mod tests { ) -> Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications(&self, _: &[(String, String)]) -> Result> { unimplemented!() } diff --git a/src/cmd/project/activities.rs b/src/cmd/project/activities.rs index 13f24eb..ab6f412 100644 --- a/src/cmd/project/activities.rs +++ b/src/cmd/project/activities.rs @@ -112,6 +112,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities(&self, _: &[(String, String)]) -> anyhow::Result> { unimplemented!() } @@ -300,6 +313,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], @@ -471,6 +506,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities(&self, _: &[(String, String)]) -> anyhow::Result> { unimplemented!() } @@ -657,6 +705,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/project/category.rs b/src/cmd/project/category.rs index 8e2aa64..cb55ca1 100644 --- a/src/cmd/project/category.rs +++ b/src/cmd/project/category.rs @@ -60,6 +60,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -247,6 +260,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/project/disk_usage.rs b/src/cmd/project/disk_usage.rs index b3d5567..9eecf7d 100644 --- a/src/cmd/project/disk_usage.rs +++ b/src/cmd/project/disk_usage.rs @@ -67,6 +67,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -254,6 +267,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/project/issue_type.rs b/src/cmd/project/issue_type.rs index 1abae1c..332c44b 100644 --- a/src/cmd/project/issue_type.rs +++ b/src/cmd/project/issue_type.rs @@ -60,6 +60,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -247,6 +260,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/project/list.rs b/src/cmd/project/list.rs index 69aa3a5..e75dfb8 100644 --- a/src/cmd/project/list.rs +++ b/src/cmd/project/list.rs @@ -68,6 +68,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -256,6 +269,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/project/show.rs b/src/cmd/project/show.rs index b2fc593..35df4bf 100644 --- a/src/cmd/project/show.rs +++ b/src/cmd/project/show.rs @@ -62,6 +62,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -250,6 +263,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/project/status.rs b/src/cmd/project/status.rs index 07c2c1b..ffea2b9 100644 --- a/src/cmd/project/status.rs +++ b/src/cmd/project/status.rs @@ -60,6 +60,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -245,6 +258,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/project/user.rs b/src/cmd/project/user.rs index e4a3698..fb7c812 100644 --- a/src/cmd/project/user.rs +++ b/src/cmd/project/user.rs @@ -64,6 +64,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -249,6 +262,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/project/version.rs b/src/cmd/project/version.rs index a8865a2..f042706 100644 --- a/src/cmd/project/version.rs +++ b/src/cmd/project/version.rs @@ -67,6 +67,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -252,6 +265,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/space/activities.rs b/src/cmd/space/activities.rs index 9b85fba..0bc5ee6 100644 --- a/src/cmd/space/activities.rs +++ b/src/cmd/space/activities.rs @@ -109,6 +109,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities(&self, _: &[(String, String)]) -> Result> { self.activities .clone() @@ -293,6 +306,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], @@ -412,6 +447,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities(&self, params: &[(String, String)]) -> Result> { *self.captured.borrow_mut() = params.to_vec(); Ok(vec![]) @@ -595,6 +643,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/space/disk_usage.rs b/src/cmd/space/disk_usage.rs index 95d4376..43e167a 100644 --- a/src/cmd/space/disk_usage.rs +++ b/src/cmd/space/disk_usage.rs @@ -67,6 +67,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -254,6 +267,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/space/notification.rs b/src/cmd/space/notification.rs index b5d9694..a706c23 100644 --- a/src/cmd/space/notification.rs +++ b/src/cmd/space/notification.rs @@ -63,6 +63,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -248,6 +261,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/space/show.rs b/src/cmd/space/show.rs index 5498941..fdd7d8b 100644 --- a/src/cmd/space/show.rs +++ b/src/cmd/space/show.rs @@ -66,6 +66,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -251,6 +264,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/team/list.rs b/src/cmd/team/list.rs index e26b400..7fdce0d 100644 --- a/src/cmd/team/list.rs +++ b/src/cmd/team/list.rs @@ -85,6 +85,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -273,6 +286,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], @@ -377,6 +412,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -566,6 +614,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/team/show.rs b/src/cmd/team/show.rs index 4ff2d55..c6d5112 100644 --- a/src/cmd/team/show.rs +++ b/src/cmd/team/show.rs @@ -80,6 +80,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -268,6 +281,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/user/activities.rs b/src/cmd/user/activities.rs index 7d14e73..49fcae9 100644 --- a/src/cmd/user/activities.rs +++ b/src/cmd/user/activities.rs @@ -112,6 +112,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities(&self, _: &[(String, String)]) -> anyhow::Result> { unimplemented!() } @@ -299,6 +312,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], @@ -420,6 +455,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities(&self, _: &[(String, String)]) -> anyhow::Result> { unimplemented!() } @@ -606,6 +654,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/user/add.rs b/src/cmd/user/add.rs new file mode 100644 index 0000000..501eec0 --- /dev/null +++ b/src/cmd/user/add.rs @@ -0,0 +1,397 @@ +use anstream::println; +use anyhow::{Context, Result}; + +use crate::api::{BacklogApi, BacklogClient}; +use crate::cmd::user::show::format_user_text; + +pub struct UserAddArgs { + user_id: String, + password: String, + name: String, + mail_address: String, + role_type: u8, + json: bool, +} + +impl UserAddArgs { + pub fn new( + user_id: String, + password: String, + name: String, + mail_address: String, + role_type: u8, + json: bool, + ) -> Self { + Self { + user_id, + password, + name, + mail_address, + role_type, + json, + } + } +} + +pub fn add(args: &UserAddArgs) -> Result<()> { + let client = BacklogClient::from_config()?; + add_with(args, &client) +} + +pub fn add_with(args: &UserAddArgs, api: &dyn BacklogApi) -> Result<()> { + let params = vec![ + ("userId".to_string(), args.user_id.clone()), + ("password".to_string(), args.password.clone()), + ("name".to_string(), args.name.clone()), + ("mailAddress".to_string(), args.mail_address.clone()), + ("roleType".to_string(), args.role_type.to_string()), + ]; + let user = api.add_user(¶ms)?; + if args.json { + println!( + "{}", + serde_json::to_string_pretty(&user).context("Failed to serialize JSON")? + ); + } else { + println!("{}", format_user_text(&user)); + } + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::api::user::User; + use anyhow::anyhow; + use std::collections::BTreeMap; + + struct MockApi { + user: Option, + } + + impl crate::api::BacklogApi for MockApi { + fn get_space(&self) -> anyhow::Result { + unimplemented!() + } + fn get_myself(&self) -> anyhow::Result { + unimplemented!() + } + fn get_users(&self) -> anyhow::Result> { + unimplemented!() + } + fn get_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + self.user.clone().ok_or_else(|| anyhow!("no user")) + } + fn update_user(&self, _user_id: u64, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } + fn get_space_activities( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_space_disk_usage(&self) -> anyhow::Result { + unimplemented!() + } + fn get_space_notification( + &self, + ) -> anyhow::Result { + unimplemented!() + } + fn get_projects(&self) -> anyhow::Result> { + unimplemented!() + } + fn get_project(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn get_project_activities( + &self, + _key: &str, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_disk_usage( + &self, + _key: &str, + ) -> anyhow::Result { + unimplemented!() + } + fn get_project_users( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_statuses( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_issue_types( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_categories( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_versions( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_issues( + &self, + _params: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_issues( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn get_issue(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn create_issue( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_issue( + &self, + _key: &str, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_issue(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn get_issue_comments( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn add_issue_comment( + &self, + _key: &str, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_issue_comment( + &self, + _key: &str, + _comment_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_issue_comment( + &self, + _key: &str, + _comment_id: u64, + ) -> anyhow::Result { + unimplemented!() + } + fn get_issue_attachments( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wikis( + &self, + _params: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wiki(&self, _wiki_id: u64) -> anyhow::Result { + unimplemented!() + } + fn create_wiki( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_wiki( + &self, + _wiki_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_wiki( + &self, + _wiki_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn get_wiki_history( + &self, + _wiki_id: u64, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wiki_attachments( + &self, + _wiki_id: u64, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_teams(&self, _: &[(String, String)]) -> anyhow::Result> { + unimplemented!() + } + fn get_team(&self, _team_id: u64) -> anyhow::Result { + unimplemented!() + } + fn get_user_activities( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_issues( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } + fn get_notifications( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_notifications( + &self, + ) -> anyhow::Result { + unimplemented!() + } + fn read_notification(&self, _: u64) -> anyhow::Result<()> { + unimplemented!() + } + fn reset_unread_notifications( + &self, + ) -> anyhow::Result { + unimplemented!() + } + } + + fn sample_user() -> User { + User { + id: 1, + user_id: Some("john".to_string()), + name: "John Doe".to_string(), + mail_address: Some("john@example.com".to_string()), + role_type: 1, + lang: None, + last_login_time: None, + extra: BTreeMap::new(), + } + } + + #[test] + fn add_with_text_output_succeeds() { + let api = MockApi { + user: Some(sample_user()), + }; + assert!( + add_with( + &UserAddArgs::new( + "john".to_string(), + "pass".to_string(), + "John Doe".to_string(), + "john@example.com".to_string(), + 1, + false, + ), + &api + ) + .is_ok() + ); + } + + #[test] + fn add_with_json_output_succeeds() { + let api = MockApi { + user: Some(sample_user()), + }; + assert!( + add_with( + &UserAddArgs::new( + "john".to_string(), + "pass".to_string(), + "John Doe".to_string(), + "john@example.com".to_string(), + 1, + true, + ), + &api + ) + .is_ok() + ); + } + + #[test] + fn add_with_propagates_api_error() { + let api = MockApi { user: None }; + let err = add_with( + &UserAddArgs::new( + "john".to_string(), + "pass".to_string(), + "John Doe".to_string(), + "john@example.com".to_string(), + 1, + false, + ), + &api, + ) + .unwrap_err(); + assert!(err.to_string().contains("no user")); + } +} diff --git a/src/cmd/user/delete.rs b/src/cmd/user/delete.rs new file mode 100644 index 0000000..6b1230f --- /dev/null +++ b/src/cmd/user/delete.rs @@ -0,0 +1,335 @@ +use anstream::println; +use anyhow::{Context, Result}; + +use crate::api::{BacklogApi, BacklogClient}; + +pub struct UserDeleteArgs { + user_id: u64, + json: bool, +} + +impl UserDeleteArgs { + pub fn new(user_id: u64, json: bool) -> Self { + Self { user_id, json } + } +} + +pub fn delete(args: &UserDeleteArgs) -> Result<()> { + let client = BacklogClient::from_config()?; + delete_with(args, &client) +} + +pub fn delete_with(args: &UserDeleteArgs, api: &dyn BacklogApi) -> Result<()> { + let user = api.delete_user(args.user_id)?; + if args.json { + println!( + "{}", + serde_json::to_string_pretty(&user).context("Failed to serialize JSON")? + ); + } else { + let user_id = user.user_id.as_deref().unwrap_or("-"); + println!("Deleted: {} ({})", user.name, user_id); + } + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::api::user::User; + use anyhow::anyhow; + use std::collections::BTreeMap; + + struct MockApi { + user: Option, + } + + impl crate::api::BacklogApi for MockApi { + fn get_space(&self) -> anyhow::Result { + unimplemented!() + } + fn get_myself(&self) -> anyhow::Result { + unimplemented!() + } + fn get_users(&self) -> anyhow::Result> { + unimplemented!() + } + fn get_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user(&self, _user_id: u64, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + self.user.clone().ok_or_else(|| anyhow!("no user")) + } + fn get_space_activities( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_space_disk_usage(&self) -> anyhow::Result { + unimplemented!() + } + fn get_space_notification( + &self, + ) -> anyhow::Result { + unimplemented!() + } + fn get_projects(&self) -> anyhow::Result> { + unimplemented!() + } + fn get_project(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn get_project_activities( + &self, + _key: &str, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_disk_usage( + &self, + _key: &str, + ) -> anyhow::Result { + unimplemented!() + } + fn get_project_users( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_statuses( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_issue_types( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_categories( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_versions( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_issues( + &self, + _params: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_issues( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn get_issue(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn create_issue( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_issue( + &self, + _key: &str, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_issue(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn get_issue_comments( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn add_issue_comment( + &self, + _key: &str, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_issue_comment( + &self, + _key: &str, + _comment_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_issue_comment( + &self, + _key: &str, + _comment_id: u64, + ) -> anyhow::Result { + unimplemented!() + } + fn get_issue_attachments( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wikis( + &self, + _params: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wiki(&self, _wiki_id: u64) -> anyhow::Result { + unimplemented!() + } + fn create_wiki( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_wiki( + &self, + _wiki_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_wiki( + &self, + _wiki_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn get_wiki_history( + &self, + _wiki_id: u64, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wiki_attachments( + &self, + _wiki_id: u64, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_teams(&self, _: &[(String, String)]) -> anyhow::Result> { + unimplemented!() + } + fn get_team(&self, _team_id: u64) -> anyhow::Result { + unimplemented!() + } + fn get_user_activities( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_issues( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } + fn get_notifications( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_notifications( + &self, + ) -> anyhow::Result { + unimplemented!() + } + fn read_notification(&self, _: u64) -> anyhow::Result<()> { + unimplemented!() + } + fn reset_unread_notifications( + &self, + ) -> anyhow::Result { + unimplemented!() + } + } + + fn sample_user() -> User { + User { + id: 1, + user_id: Some("john".to_string()), + name: "John Doe".to_string(), + mail_address: Some("john@example.com".to_string()), + role_type: 1, + lang: None, + last_login_time: None, + extra: BTreeMap::new(), + } + } + + #[test] + fn delete_with_text_output_succeeds() { + let api = MockApi { + user: Some(sample_user()), + }; + assert!(delete_with(&UserDeleteArgs::new(1, false), &api).is_ok()); + } + + #[test] + fn delete_with_json_output_succeeds() { + let api = MockApi { + user: Some(sample_user()), + }; + assert!(delete_with(&UserDeleteArgs::new(1, true), &api).is_ok()); + } + + #[test] + fn delete_with_propagates_api_error() { + let api = MockApi { user: None }; + let err = delete_with(&UserDeleteArgs::new(999, false), &api).unwrap_err(); + assert!(err.to_string().contains("no user")); + } +} diff --git a/src/cmd/user/list.rs b/src/cmd/user/list.rs index 824436e..f4f8e8b 100644 --- a/src/cmd/user/list.rs +++ b/src/cmd/user/list.rs @@ -63,6 +63,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -251,6 +264,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/user/mod.rs b/src/cmd/user/mod.rs index 5edd814..f499138 100644 --- a/src/cmd/user/mod.rs +++ b/src/cmd/user/mod.rs @@ -1,9 +1,21 @@ mod activities; +mod add; +mod delete; mod list; mod recently_viewed; -mod show; +mod recently_viewed_projects; +mod recently_viewed_wikis; +pub mod show; +mod star; +mod update; pub use activities::{UserActivitiesArgs, activities}; +pub use add::{UserAddArgs, add}; +pub use delete::{UserDeleteArgs, delete}; pub use list::{UserListArgs, list}; pub use recently_viewed::{UserRecentlyViewedArgs, recently_viewed}; +pub use recently_viewed_projects::{UserRecentlyViewedProjectsArgs, recently_viewed_projects}; +pub use recently_viewed_wikis::{UserRecentlyViewedWikisArgs, recently_viewed_wikis}; pub use show::{UserShowArgs, show}; +pub use star::{UserStarCountArgs, UserStarListArgs, star_count, star_list}; +pub use update::{UserUpdateArgs, update}; diff --git a/src/cmd/user/recently_viewed.rs b/src/cmd/user/recently_viewed.rs index 5114c38..42be679 100644 --- a/src/cmd/user/recently_viewed.rs +++ b/src/cmd/user/recently_viewed.rs @@ -94,6 +94,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities(&self, _: &[(String, String)]) -> anyhow::Result> { unimplemented!() } @@ -279,6 +292,28 @@ mod tests { ) -> anyhow::Result> { self.items.clone().ok_or_else(|| anyhow!("no items")) } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], @@ -435,6 +470,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities(&self, _: &[(String, String)]) -> anyhow::Result> { unimplemented!() } @@ -621,6 +669,28 @@ mod tests { *self.captured.borrow_mut() = params.to_vec(); Ok(vec![]) } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/user/recently_viewed_projects.rs b/src/cmd/user/recently_viewed_projects.rs new file mode 100644 index 0000000..bed62fa --- /dev/null +++ b/src/cmd/user/recently_viewed_projects.rs @@ -0,0 +1,401 @@ +use anstream::println; +use anyhow::{Context, Result}; + +use crate::api::{BacklogApi, BacklogClient, user::RecentlyViewedProject}; + +pub struct UserRecentlyViewedProjectsArgs { + json: bool, + pub count: u32, + pub offset: u64, + pub order: Option, +} + +impl UserRecentlyViewedProjectsArgs { + pub fn try_new( + json: bool, + count: u32, + offset: u64, + order: Option, + ) -> anyhow::Result { + if !(1..=100).contains(&count) { + anyhow::bail!("count must be between 1 and 100"); + } + Ok(Self { + json, + count, + offset, + order, + }) + } +} + +pub fn recently_viewed_projects(args: &UserRecentlyViewedProjectsArgs) -> Result<()> { + let client = BacklogClient::from_config()?; + recently_viewed_projects_with(args, &client) +} + +pub fn recently_viewed_projects_with( + args: &UserRecentlyViewedProjectsArgs, + api: &dyn BacklogApi, +) -> Result<()> { + let mut params: Vec<(String, String)> = Vec::new(); + params.push(("count".to_string(), args.count.to_string())); + params.push(("offset".to_string(), args.offset.to_string())); + if let Some(ref order) = args.order { + params.push(("order".to_string(), order.clone())); + } + let items = api.get_recently_viewed_projects(¶ms)?; + if args.json { + println!( + "{}", + serde_json::to_string_pretty(&items).context("Failed to serialize JSON")? + ); + } else { + for item in &items { + println!("{}", format_row(item)); + } + } + Ok(()) +} + +fn format_row(item: &RecentlyViewedProject) -> String { + format!("[{}] {}", item.project.project_key, item.project.name) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::api::user::{ProjectSummary, RecentlyViewedWiki, Star, StarCount}; + use anyhow::anyhow; + use std::collections::BTreeMap; + + struct MockApi { + items: Option>, + } + + impl crate::api::BacklogApi for MockApi { + fn get_space(&self) -> anyhow::Result { + unimplemented!() + } + fn get_myself(&self) -> anyhow::Result { + unimplemented!() + } + fn get_users(&self) -> anyhow::Result> { + unimplemented!() + } + fn get_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } + fn get_space_activities( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_space_disk_usage(&self) -> anyhow::Result { + unimplemented!() + } + fn get_space_notification( + &self, + ) -> anyhow::Result { + unimplemented!() + } + fn get_projects(&self) -> anyhow::Result> { + unimplemented!() + } + fn get_project(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn get_project_activities( + &self, + _key: &str, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_disk_usage( + &self, + _key: &str, + ) -> anyhow::Result { + unimplemented!() + } + fn get_project_users( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_statuses( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_issue_types( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_categories( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_versions( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_issues( + &self, + _params: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_issues( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn get_issue(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn create_issue( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_issue( + &self, + _key: &str, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_issue(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn get_issue_comments( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn add_issue_comment( + &self, + _key: &str, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_issue_comment( + &self, + _key: &str, + _comment_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_issue_comment( + &self, + _key: &str, + _comment_id: u64, + ) -> anyhow::Result { + unimplemented!() + } + fn get_issue_attachments( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wikis( + &self, + _params: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wiki(&self, _wiki_id: u64) -> anyhow::Result { + unimplemented!() + } + fn create_wiki( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_wiki( + &self, + _wiki_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_wiki( + &self, + _wiki_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn get_wiki_history( + &self, + _wiki_id: u64, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wiki_attachments( + &self, + _wiki_id: u64, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_teams(&self, _: &[(String, String)]) -> anyhow::Result> { + unimplemented!() + } + fn get_team(&self, _team_id: u64) -> anyhow::Result { + unimplemented!() + } + fn get_user_activities( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_issues( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + self.items.clone().ok_or_else(|| anyhow!("no items")) + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } + fn get_notifications( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_notifications( + &self, + ) -> anyhow::Result { + unimplemented!() + } + fn read_notification(&self, _: u64) -> anyhow::Result<()> { + unimplemented!() + } + fn reset_unread_notifications( + &self, + ) -> anyhow::Result { + unimplemented!() + } + } + + fn sample_item() -> RecentlyViewedProject { + RecentlyViewedProject { + project: ProjectSummary { + id: 1, + project_key: "TEST".to_string(), + name: "Test Project".to_string(), + extra: BTreeMap::new(), + }, + updated: "2024-06-01T00:00:00Z".to_string(), + extra: BTreeMap::new(), + } + } + + #[test] + fn format_row_contains_fields() { + let text = format_row(&sample_item()); + assert!(text.contains("[TEST]")); + assert!(text.contains("Test Project")); + } + + #[test] + fn recently_viewed_projects_with_text_output_succeeds() { + let api = MockApi { + items: Some(vec![sample_item()]), + }; + assert!( + recently_viewed_projects_with( + &UserRecentlyViewedProjectsArgs::try_new(false, 20, 0, None).unwrap(), + &api + ) + .is_ok() + ); + } + + #[test] + fn recently_viewed_projects_with_json_output_succeeds() { + let api = MockApi { + items: Some(vec![sample_item()]), + }; + assert!( + recently_viewed_projects_with( + &UserRecentlyViewedProjectsArgs::try_new(true, 20, 0, None).unwrap(), + &api + ) + .is_ok() + ); + } + + #[test] + fn recently_viewed_projects_with_propagates_api_error() { + let api = MockApi { items: None }; + let err = recently_viewed_projects_with( + &UserRecentlyViewedProjectsArgs::try_new(false, 20, 0, None).unwrap(), + &api, + ) + .unwrap_err(); + assert!(err.to_string().contains("no items")); + } + + #[test] + fn try_new_rejects_count_over_100() { + assert!(UserRecentlyViewedProjectsArgs::try_new(false, 101, 0, None).is_err()); + } + + #[test] + fn try_new_rejects_count_zero() { + assert!(UserRecentlyViewedProjectsArgs::try_new(false, 0, 0, None).is_err()); + } +} diff --git a/src/cmd/user/recently_viewed_wikis.rs b/src/cmd/user/recently_viewed_wikis.rs new file mode 100644 index 0000000..f0b71c9 --- /dev/null +++ b/src/cmd/user/recently_viewed_wikis.rs @@ -0,0 +1,400 @@ +use anstream::println; +use anyhow::{Context, Result}; + +use crate::api::{BacklogApi, BacklogClient, user::RecentlyViewedWiki}; + +pub struct UserRecentlyViewedWikisArgs { + json: bool, + pub count: u32, + pub offset: u64, + pub order: Option, +} + +impl UserRecentlyViewedWikisArgs { + pub fn try_new( + json: bool, + count: u32, + offset: u64, + order: Option, + ) -> anyhow::Result { + if !(1..=100).contains(&count) { + anyhow::bail!("count must be between 1 and 100"); + } + Ok(Self { + json, + count, + offset, + order, + }) + } +} + +pub fn recently_viewed_wikis(args: &UserRecentlyViewedWikisArgs) -> Result<()> { + let client = BacklogClient::from_config()?; + recently_viewed_wikis_with(args, &client) +} + +pub fn recently_viewed_wikis_with( + args: &UserRecentlyViewedWikisArgs, + api: &dyn BacklogApi, +) -> Result<()> { + let mut params: Vec<(String, String)> = Vec::new(); + params.push(("count".to_string(), args.count.to_string())); + params.push(("offset".to_string(), args.offset.to_string())); + if let Some(ref order) = args.order { + params.push(("order".to_string(), order.clone())); + } + let items = api.get_recently_viewed_wikis(¶ms)?; + if args.json { + println!( + "{}", + serde_json::to_string_pretty(&items).context("Failed to serialize JSON")? + ); + } else { + for item in &items { + println!("{}", format_row(item)); + } + } + Ok(()) +} + +fn format_row(item: &RecentlyViewedWiki) -> String { + format!("[{}] {}", item.page.id, item.page.name) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::api::user::{RecentlyViewedProject, Star, StarCount, WikiSummary}; + use anyhow::anyhow; + use std::collections::BTreeMap; + + struct MockApi { + items: Option>, + } + + impl crate::api::BacklogApi for MockApi { + fn get_space(&self) -> anyhow::Result { + unimplemented!() + } + fn get_myself(&self) -> anyhow::Result { + unimplemented!() + } + fn get_users(&self) -> anyhow::Result> { + unimplemented!() + } + fn get_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } + fn get_space_activities( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_space_disk_usage(&self) -> anyhow::Result { + unimplemented!() + } + fn get_space_notification( + &self, + ) -> anyhow::Result { + unimplemented!() + } + fn get_projects(&self) -> anyhow::Result> { + unimplemented!() + } + fn get_project(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn get_project_activities( + &self, + _key: &str, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_disk_usage( + &self, + _key: &str, + ) -> anyhow::Result { + unimplemented!() + } + fn get_project_users( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_statuses( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_issue_types( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_categories( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_versions( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_issues( + &self, + _params: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_issues( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn get_issue(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn create_issue( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_issue( + &self, + _key: &str, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_issue(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn get_issue_comments( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn add_issue_comment( + &self, + _key: &str, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_issue_comment( + &self, + _key: &str, + _comment_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_issue_comment( + &self, + _key: &str, + _comment_id: u64, + ) -> anyhow::Result { + unimplemented!() + } + fn get_issue_attachments( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wikis( + &self, + _params: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wiki(&self, _wiki_id: u64) -> anyhow::Result { + unimplemented!() + } + fn create_wiki( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_wiki( + &self, + _wiki_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_wiki( + &self, + _wiki_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn get_wiki_history( + &self, + _wiki_id: u64, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wiki_attachments( + &self, + _wiki_id: u64, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_teams(&self, _: &[(String, String)]) -> anyhow::Result> { + unimplemented!() + } + fn get_team(&self, _team_id: u64) -> anyhow::Result { + unimplemented!() + } + fn get_user_activities( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_issues( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + self.items.clone().ok_or_else(|| anyhow!("no items")) + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } + fn get_notifications( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_notifications( + &self, + ) -> anyhow::Result { + unimplemented!() + } + fn read_notification(&self, _: u64) -> anyhow::Result<()> { + unimplemented!() + } + fn reset_unread_notifications( + &self, + ) -> anyhow::Result { + unimplemented!() + } + } + + fn sample_item() -> RecentlyViewedWiki { + RecentlyViewedWiki { + page: WikiSummary { + id: 42, + name: "Home".to_string(), + extra: BTreeMap::new(), + }, + updated: "2024-06-01T00:00:00Z".to_string(), + extra: BTreeMap::new(), + } + } + + #[test] + fn format_row_contains_fields() { + let text = format_row(&sample_item()); + assert!(text.contains("[42]")); + assert!(text.contains("Home")); + } + + #[test] + fn recently_viewed_wikis_with_text_output_succeeds() { + let api = MockApi { + items: Some(vec![sample_item()]), + }; + assert!( + recently_viewed_wikis_with( + &UserRecentlyViewedWikisArgs::try_new(false, 20, 0, None).unwrap(), + &api + ) + .is_ok() + ); + } + + #[test] + fn recently_viewed_wikis_with_json_output_succeeds() { + let api = MockApi { + items: Some(vec![sample_item()]), + }; + assert!( + recently_viewed_wikis_with( + &UserRecentlyViewedWikisArgs::try_new(true, 20, 0, None).unwrap(), + &api + ) + .is_ok() + ); + } + + #[test] + fn recently_viewed_wikis_with_propagates_api_error() { + let api = MockApi { items: None }; + let err = recently_viewed_wikis_with( + &UserRecentlyViewedWikisArgs::try_new(false, 20, 0, None).unwrap(), + &api, + ) + .unwrap_err(); + assert!(err.to_string().contains("no items")); + } + + #[test] + fn try_new_rejects_count_over_100() { + assert!(UserRecentlyViewedWikisArgs::try_new(false, 101, 0, None).is_err()); + } + + #[test] + fn try_new_rejects_count_zero() { + assert!(UserRecentlyViewedWikisArgs::try_new(false, 0, 0, None).is_err()); + } +} diff --git a/src/cmd/user/show.rs b/src/cmd/user/show.rs index ec3c03b..752d2b8 100644 --- a/src/cmd/user/show.rs +++ b/src/cmd/user/show.rs @@ -33,7 +33,7 @@ pub fn show_with(args: &UserShowArgs, api: &dyn BacklogApi) -> Result<()> { Ok(()) } -fn format_user_text(u: &User) -> String { +pub fn format_user_text(u: &User) -> String { let user_id = u.user_id.as_deref().unwrap_or("-"); let mail = u.mail_address.as_deref().unwrap_or("-"); let lang = u.lang.as_deref().unwrap_or("-"); @@ -73,6 +73,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { self.user.clone().ok_or_else(|| anyhow!("no user")) } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -261,6 +274,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/user/star.rs b/src/cmd/user/star.rs new file mode 100644 index 0000000..fd09097 --- /dev/null +++ b/src/cmd/user/star.rs @@ -0,0 +1,422 @@ +use anstream::println; +use anyhow::{Context, Result}; + +use crate::api::{BacklogApi, BacklogClient, user::Star}; + +pub struct UserStarListArgs { + user_id: u64, + json: bool, +} + +impl UserStarListArgs { + pub fn new(user_id: u64, json: bool) -> Self { + Self { user_id, json } + } +} + +pub fn star_list(args: &UserStarListArgs) -> Result<()> { + let client = BacklogClient::from_config()?; + star_list_with(args, &client) +} + +pub fn star_list_with(args: &UserStarListArgs, api: &dyn BacklogApi) -> Result<()> { + let stars = api.get_user_stars(args.user_id, &[])?; + if args.json { + println!( + "{}", + serde_json::to_string_pretty(&stars).context("Failed to serialize JSON")? + ); + } else { + for star in &stars { + println!("{}", format_star_row(star)); + } + } + Ok(()) +} + +fn format_star_row(star: &Star) -> String { + format!("[{}] {} — {}", star.id, star.title, star.url) +} + +pub struct UserStarCountArgs { + user_id: u64, + json: bool, +} + +impl UserStarCountArgs { + pub fn new(user_id: u64, json: bool) -> Self { + Self { user_id, json } + } +} + +pub fn star_count(args: &UserStarCountArgs) -> Result<()> { + let client = BacklogClient::from_config()?; + star_count_with(args, &client) +} + +pub fn star_count_with(args: &UserStarCountArgs, api: &dyn BacklogApi) -> Result<()> { + let count = api.count_user_stars(args.user_id)?; + if args.json { + println!( + "{}", + serde_json::to_string_pretty(&count).context("Failed to serialize JSON")? + ); + } else { + println!("{}", count.count); + } + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::api::user::{RecentlyViewedProject, RecentlyViewedWiki, StarCount, User}; + use anyhow::anyhow; + use std::collections::BTreeMap; + + struct MockApi { + stars: Option>, + count: Option, + } + + impl crate::api::BacklogApi for MockApi { + fn get_space(&self) -> anyhow::Result { + unimplemented!() + } + fn get_myself(&self) -> anyhow::Result { + unimplemented!() + } + fn get_users(&self) -> anyhow::Result> { + unimplemented!() + } + fn get_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user(&self, _user_id: u64, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } + fn get_space_activities( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_space_disk_usage(&self) -> anyhow::Result { + unimplemented!() + } + fn get_space_notification( + &self, + ) -> anyhow::Result { + unimplemented!() + } + fn get_projects(&self) -> anyhow::Result> { + unimplemented!() + } + fn get_project(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn get_project_activities( + &self, + _key: &str, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_disk_usage( + &self, + _key: &str, + ) -> anyhow::Result { + unimplemented!() + } + fn get_project_users( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_statuses( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_issue_types( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_categories( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_versions( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_issues( + &self, + _params: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_issues( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn get_issue(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn create_issue( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_issue( + &self, + _key: &str, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_issue(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn get_issue_comments( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn add_issue_comment( + &self, + _key: &str, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_issue_comment( + &self, + _key: &str, + _comment_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_issue_comment( + &self, + _key: &str, + _comment_id: u64, + ) -> anyhow::Result { + unimplemented!() + } + fn get_issue_attachments( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wikis( + &self, + _params: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wiki(&self, _wiki_id: u64) -> anyhow::Result { + unimplemented!() + } + fn create_wiki( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_wiki( + &self, + _wiki_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_wiki( + &self, + _wiki_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn get_wiki_history( + &self, + _wiki_id: u64, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wiki_attachments( + &self, + _wiki_id: u64, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_teams(&self, _: &[(String, String)]) -> anyhow::Result> { + unimplemented!() + } + fn get_team(&self, _team_id: u64) -> anyhow::Result { + unimplemented!() + } + fn get_user_activities( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_issues( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + self.stars.clone().ok_or_else(|| anyhow!("no stars")) + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + self.count.clone().ok_or_else(|| anyhow!("no count")) + } + fn get_notifications( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_notifications( + &self, + ) -> anyhow::Result { + unimplemented!() + } + fn read_notification(&self, _: u64) -> anyhow::Result<()> { + unimplemented!() + } + fn reset_unread_notifications( + &self, + ) -> anyhow::Result { + unimplemented!() + } + } + + fn sample_presenter() -> User { + User { + id: 1, + user_id: Some("john".to_string()), + name: "John".to_string(), + mail_address: None, + role_type: 1, + lang: None, + last_login_time: None, + extra: BTreeMap::new(), + } + } + + fn sample_star() -> Star { + Star { + id: 5, + comment: None, + url: "https://example.backlog.com/view/TEST-1".to_string(), + title: "Fix bug".to_string(), + presenter: sample_presenter(), + created: "2024-06-01T00:00:00Z".to_string(), + } + } + + #[test] + fn format_star_row_contains_fields() { + let text = format_star_row(&sample_star()); + assert!(text.contains("[5]")); + assert!(text.contains("Fix bug")); + assert!(text.contains("https://example.backlog.com/view/TEST-1")); + } + + #[test] + fn star_list_with_text_output_succeeds() { + let api = MockApi { + stars: Some(vec![sample_star()]), + count: None, + }; + assert!(star_list_with(&UserStarListArgs::new(1, false), &api).is_ok()); + } + + #[test] + fn star_list_with_json_output_succeeds() { + let api = MockApi { + stars: Some(vec![sample_star()]), + count: None, + }; + assert!(star_list_with(&UserStarListArgs::new(1, true), &api).is_ok()); + } + + #[test] + fn star_list_with_propagates_api_error() { + let api = MockApi { + stars: None, + count: None, + }; + let err = star_list_with(&UserStarListArgs::new(1, false), &api).unwrap_err(); + assert!(err.to_string().contains("no stars")); + } + + #[test] + fn star_count_with_text_output_succeeds() { + let api = MockApi { + stars: None, + count: Some(StarCount { count: 42 }), + }; + assert!(star_count_with(&UserStarCountArgs::new(1, false), &api).is_ok()); + } + + #[test] + fn star_count_with_json_output_succeeds() { + let api = MockApi { + stars: None, + count: Some(StarCount { count: 42 }), + }; + assert!(star_count_with(&UserStarCountArgs::new(1, true), &api).is_ok()); + } + + #[test] + fn star_count_with_propagates_api_error() { + let api = MockApi { + stars: None, + count: None, + }; + let err = star_count_with(&UserStarCountArgs::new(1, false), &api).unwrap_err(); + assert!(err.to_string().contains("no count")); + } +} diff --git a/src/cmd/user/update.rs b/src/cmd/user/update.rs new file mode 100644 index 0000000..fa11e58 --- /dev/null +++ b/src/cmd/user/update.rs @@ -0,0 +1,392 @@ +use anstream::println; +use anyhow::{Context, Result}; + +use crate::api::{BacklogApi, BacklogClient}; +use crate::cmd::user::show::format_user_text; + +pub struct UserUpdateArgs { + user_id: u64, + name: Option, + password: Option, + mail_address: Option, + role_type: Option, + json: bool, +} + +impl UserUpdateArgs { + pub fn try_new( + user_id: u64, + name: Option, + password: Option, + mail_address: Option, + role_type: Option, + json: bool, + ) -> anyhow::Result { + if name.is_none() && password.is_none() && mail_address.is_none() && role_type.is_none() { + anyhow::bail!( + "at least one of --name, --password, --mail-address, or --role-type must be specified" + ); + } + Ok(Self { + user_id, + name, + password, + mail_address, + role_type, + json, + }) + } +} + +pub fn update(args: &UserUpdateArgs) -> Result<()> { + let client = BacklogClient::from_config()?; + update_with(args, &client) +} + +pub fn update_with(args: &UserUpdateArgs, api: &dyn BacklogApi) -> Result<()> { + let mut params: Vec<(String, String)> = Vec::new(); + if let Some(ref name) = args.name { + params.push(("name".to_string(), name.clone())); + } + if let Some(ref password) = args.password { + params.push(("password".to_string(), password.clone())); + } + if let Some(ref mail) = args.mail_address { + params.push(("mailAddress".to_string(), mail.clone())); + } + if let Some(role) = args.role_type { + params.push(("roleType".to_string(), role.to_string())); + } + let user = api.update_user(args.user_id, ¶ms)?; + if args.json { + println!( + "{}", + serde_json::to_string_pretty(&user).context("Failed to serialize JSON")? + ); + } else { + println!("{}", format_user_text(&user)); + } + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::api::user::User; + use anyhow::anyhow; + use std::collections::BTreeMap; + + struct MockApi { + user: Option, + } + + impl crate::api::BacklogApi for MockApi { + fn get_space(&self) -> anyhow::Result { + unimplemented!() + } + fn get_myself(&self) -> anyhow::Result { + unimplemented!() + } + fn get_users(&self) -> anyhow::Result> { + unimplemented!() + } + fn get_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user(&self, _user_id: u64, _params: &[(String, String)]) -> anyhow::Result { + self.user.clone().ok_or_else(|| anyhow!("no user")) + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } + fn get_space_activities( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_space_disk_usage(&self) -> anyhow::Result { + unimplemented!() + } + fn get_space_notification( + &self, + ) -> anyhow::Result { + unimplemented!() + } + fn get_projects(&self) -> anyhow::Result> { + unimplemented!() + } + fn get_project(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn get_project_activities( + &self, + _key: &str, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_disk_usage( + &self, + _key: &str, + ) -> anyhow::Result { + unimplemented!() + } + fn get_project_users( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_statuses( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_issue_types( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_categories( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_project_versions( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_issues( + &self, + _params: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_issues( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn get_issue(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn create_issue( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_issue( + &self, + _key: &str, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_issue(&self, _key: &str) -> anyhow::Result { + unimplemented!() + } + fn get_issue_comments( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn add_issue_comment( + &self, + _key: &str, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_issue_comment( + &self, + _key: &str, + _comment_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_issue_comment( + &self, + _key: &str, + _comment_id: u64, + ) -> anyhow::Result { + unimplemented!() + } + fn get_issue_attachments( + &self, + _key: &str, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wikis( + &self, + _params: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wiki(&self, _wiki_id: u64) -> anyhow::Result { + unimplemented!() + } + fn create_wiki( + &self, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn update_wiki( + &self, + _wiki_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_wiki( + &self, + _wiki_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn get_wiki_history( + &self, + _wiki_id: u64, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_wiki_attachments( + &self, + _wiki_id: u64, + ) -> anyhow::Result> { + unimplemented!() + } + fn get_teams(&self, _: &[(String, String)]) -> anyhow::Result> { + unimplemented!() + } + fn get_team(&self, _team_id: u64) -> anyhow::Result { + unimplemented!() + } + fn get_user_activities( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_issues( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } + fn get_notifications( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_notifications( + &self, + ) -> anyhow::Result { + unimplemented!() + } + fn read_notification(&self, _: u64) -> anyhow::Result<()> { + unimplemented!() + } + fn reset_unread_notifications( + &self, + ) -> anyhow::Result { + unimplemented!() + } + } + + fn sample_user() -> User { + User { + id: 1, + user_id: Some("john".to_string()), + name: "John Doe".to_string(), + mail_address: Some("john@example.com".to_string()), + role_type: 1, + lang: None, + last_login_time: None, + extra: BTreeMap::new(), + } + } + + #[test] + fn try_new_rejects_no_fields() { + assert!(UserUpdateArgs::try_new(1, None, None, None, None, false).is_err()); + } + + #[test] + fn try_new_accepts_at_least_one_field() { + assert!( + UserUpdateArgs::try_new(1, Some("New Name".to_string()), None, None, None, false) + .is_ok() + ); + } + + #[test] + fn update_with_text_output_succeeds() { + let api = MockApi { + user: Some(sample_user()), + }; + let args = + UserUpdateArgs::try_new(1, Some("New Name".to_string()), None, None, None, false) + .unwrap(); + assert!(update_with(&args, &api).is_ok()); + } + + #[test] + fn update_with_json_output_succeeds() { + let api = MockApi { + user: Some(sample_user()), + }; + let args = UserUpdateArgs::try_new(1, Some("New Name".to_string()), None, None, None, true) + .unwrap(); + assert!(update_with(&args, &api).is_ok()); + } + + #[test] + fn update_with_propagates_api_error() { + let api = MockApi { user: None }; + let args = + UserUpdateArgs::try_new(1, Some("New Name".to_string()), None, None, None, false) + .unwrap(); + let err = update_with(&args, &api).unwrap_err(); + assert!(err.to_string().contains("no user")); + } +} diff --git a/src/cmd/wiki/attachment/list.rs b/src/cmd/wiki/attachment/list.rs index 2bd3e1a..672aa3a 100644 --- a/src/cmd/wiki/attachment/list.rs +++ b/src/cmd/wiki/attachment/list.rs @@ -68,6 +68,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -238,6 +251,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/wiki/create.rs b/src/cmd/wiki/create.rs index afc6688..421482b 100644 --- a/src/cmd/wiki/create.rs +++ b/src/cmd/wiki/create.rs @@ -81,6 +81,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -249,6 +262,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/wiki/delete.rs b/src/cmd/wiki/delete.rs index ac82b50..aa1d3c9 100644 --- a/src/cmd/wiki/delete.rs +++ b/src/cmd/wiki/delete.rs @@ -67,6 +67,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -235,6 +248,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/wiki/history.rs b/src/cmd/wiki/history.rs index 2693d5f..f8b73c3 100644 --- a/src/cmd/wiki/history.rs +++ b/src/cmd/wiki/history.rs @@ -68,6 +68,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -236,6 +249,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/wiki/list.rs b/src/cmd/wiki/list.rs index 9d6c058..4e2d383 100644 --- a/src/cmd/wiki/list.rs +++ b/src/cmd/wiki/list.rs @@ -121,6 +121,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -289,6 +302,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/wiki/show.rs b/src/cmd/wiki/show.rs index eac65c9..84a893a 100644 --- a/src/cmd/wiki/show.rs +++ b/src/cmd/wiki/show.rs @@ -71,6 +71,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -239,6 +252,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/cmd/wiki/update.rs b/src/cmd/wiki/update.rs index c582d14..23ebe87 100644 --- a/src/cmd/wiki/update.rs +++ b/src/cmd/wiki/update.rs @@ -89,6 +89,19 @@ mod tests { fn get_user(&self, _user_id: u64) -> anyhow::Result { unimplemented!() } + fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result { + unimplemented!() + } + fn update_user( + &self, + _user_id: u64, + _params: &[(String, String)], + ) -> anyhow::Result { + unimplemented!() + } + fn delete_user(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_space_activities( &self, _: &[(String, String)], @@ -257,6 +270,28 @@ mod tests { ) -> anyhow::Result> { unimplemented!() } + fn get_recently_viewed_projects( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_recently_viewed_wikis( + &self, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn get_user_stars( + &self, + _user_id: u64, + _: &[(String, String)], + ) -> anyhow::Result> { + unimplemented!() + } + fn count_user_stars(&self, _user_id: u64) -> anyhow::Result { + unimplemented!() + } fn get_notifications( &self, _: &[(String, String)], diff --git a/src/main.rs b/src/main.rs index 8bf22bc..2c2e61e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,11 @@ use cmd::project::version::ProjectVersionListArgs; use cmd::project::{ProjectActivitiesArgs, ProjectDiskUsageArgs, ProjectListArgs, ProjectShowArgs}; use cmd::space::{SpaceActivitiesArgs, SpaceDiskUsageArgs, SpaceNotificationArgs, SpaceShowArgs}; use cmd::team::{TeamListArgs, TeamShowArgs}; -use cmd::user::{UserActivitiesArgs, UserListArgs, UserRecentlyViewedArgs, UserShowArgs}; +use cmd::user::{ + UserActivitiesArgs, UserAddArgs, UserDeleteArgs, UserListArgs, UserRecentlyViewedArgs, + UserRecentlyViewedProjectsArgs, UserRecentlyViewedWikisArgs, UserShowArgs, UserStarCountArgs, + UserStarListArgs, UserUpdateArgs, +}; use cmd::wiki::attachment::WikiAttachmentListArgs; use cmd::wiki::{ WikiCreateArgs, WikiDeleteArgs, WikiHistoryArgs, WikiListArgs, WikiShowArgs, WikiUpdateArgs, @@ -604,6 +608,55 @@ enum UserCommands { #[arg(long)] json: bool, }, + /// Add a new user + Add { + /// User ID (login name) + #[arg(long)] + user_id: String, + /// Password + #[arg(long)] + password: String, + /// Display name + #[arg(long)] + name: String, + /// Mail address + #[arg(long)] + mail_address: String, + /// Role type (1=admin, 2=normal, 3=reporter, 4=viewer, 5=guest viewer) + #[arg(long)] + role_type: u8, + /// Output as JSON + #[arg(long)] + json: bool, + }, + /// Update a user + Update { + /// User numeric ID + id: u64, + /// New display name + #[arg(long)] + name: Option, + /// New password + #[arg(long)] + password: Option, + /// New mail address + #[arg(long)] + mail_address: Option, + /// New role type (1=admin, 2=normal, 3=reporter, 4=viewer, 5=guest viewer) + #[arg(long)] + role_type: Option, + /// Output as JSON + #[arg(long)] + json: bool, + }, + /// Delete a user + Delete { + /// User numeric ID + id: u64, + /// Output as JSON + #[arg(long)] + json: bool, + }, /// Show recent activities of a user Activities { /// User numeric ID @@ -642,6 +695,61 @@ enum UserCommands { #[arg(long)] json: bool, }, + /// Show recently viewed projects (for the authenticated user) + RecentlyViewedProjects { + /// Number of items to retrieve + #[arg(long, default_value = "20")] + count: u32, + /// Offset for pagination + #[arg(long, default_value = "0")] + offset: u64, + /// Sort order + #[arg(long)] + order: Option, + /// Output as JSON + #[arg(long)] + json: bool, + }, + /// Show recently viewed wikis (for the authenticated user) + RecentlyViewedWikis { + /// Number of items to retrieve + #[arg(long, default_value = "20")] + count: u32, + /// Offset for pagination + #[arg(long, default_value = "0")] + offset: u64, + /// Sort order + #[arg(long)] + order: Option, + /// Output as JSON + #[arg(long)] + json: bool, + }, + /// Manage user stars + Star { + #[command(subcommand)] + action: UserStarCommands, + }, +} + +#[derive(Subcommand)] +enum UserStarCommands { + /// List stars of a user + List { + /// User numeric ID + id: u64, + /// Output as JSON + #[arg(long)] + json: bool, + }, + /// Count stars of a user + Count { + /// User numeric ID + id: u64, + /// Output as JSON + #[arg(long)] + json: bool, + }, } #[derive(Subcommand)] @@ -1031,6 +1139,37 @@ fn run() -> Result<()> { Commands::User { action } => match action { UserCommands::List { json } => cmd::user::list(&UserListArgs::new(json)), UserCommands::Show { id, json } => cmd::user::show(&UserShowArgs::new(id, json)), + UserCommands::Add { + user_id, + password, + name, + mail_address, + role_type, + json, + } => cmd::user::add(&UserAddArgs::new( + user_id, + password, + name, + mail_address, + role_type, + json, + )), + UserCommands::Update { + id, + name, + password, + mail_address, + role_type, + json, + } => cmd::user::update(&UserUpdateArgs::try_new( + id, + name, + password, + mail_address, + role_type, + json, + )?), + UserCommands::Delete { id, json } => cmd::user::delete(&UserDeleteArgs::new(id, json)), UserCommands::Activities { id, activity_type_ids, @@ -1059,6 +1198,36 @@ fn run() -> Result<()> { offset, order.map(|o| o.as_str().to_string()), )?), + UserCommands::RecentlyViewedProjects { + count, + offset, + order, + json, + } => cmd::user::recently_viewed_projects(&UserRecentlyViewedProjectsArgs::try_new( + json, + count, + offset, + order.map(|o| o.as_str().to_string()), + )?), + UserCommands::RecentlyViewedWikis { + count, + offset, + order, + json, + } => cmd::user::recently_viewed_wikis(&UserRecentlyViewedWikisArgs::try_new( + json, + count, + offset, + order.map(|o| o.as_str().to_string()), + )?), + UserCommands::Star { action } => match action { + UserStarCommands::List { id, json } => { + cmd::user::star_list(&UserStarListArgs::new(id, json)) + } + UserStarCommands::Count { id, json } => { + cmd::user::star_count(&UserStarCountArgs::new(id, json)) + } + }, }, Commands::Team { action } => match action { TeamCommands::List {