Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ 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 {
fn get_space(&self) -> Result<Space>;
fn get_myself(&self) -> Result<User>;
fn get_users(&self) -> Result<Vec<User>>;
fn get_user(&self, user_id: u64) -> Result<User>;
fn add_user(&self, params: &[(String, String)]) -> Result<User>;
fn update_user(&self, user_id: u64, params: &[(String, String)]) -> Result<User>;
fn delete_user(&self, user_id: u64) -> Result<User>;
fn get_space_activities(&self, params: &[(String, String)]) -> Result<Vec<Activity>>;
fn get_space_disk_usage(&self) -> Result<DiskUsage>;
fn get_space_notification(&self) -> Result<SpaceNotification>;
Expand Down Expand Up @@ -86,6 +89,16 @@ pub trait BacklogApi {
&self,
params: &[(String, String)],
) -> Result<Vec<RecentlyViewedIssue>>;
fn get_recently_viewed_projects(
&self,
params: &[(String, String)],
) -> Result<Vec<RecentlyViewedProject>>;
fn get_recently_viewed_wikis(
&self,
params: &[(String, String)],
) -> Result<Vec<RecentlyViewedWiki>>;
fn get_user_stars(&self, user_id: u64, params: &[(String, String)]) -> Result<Vec<Star>>;
fn count_user_stars(&self, user_id: u64) -> Result<StarCount>;
fn get_notifications(&self, params: &[(String, String)]) -> Result<Vec<Notification>>;
fn count_notifications(&self) -> Result<NotificationCount>;
fn read_notification(&self, id: u64) -> Result<()>;
Expand All @@ -109,6 +122,18 @@ impl BacklogApi for BacklogClient {
self.get_user(user_id)
}

fn add_user(&self, params: &[(String, String)]) -> Result<User> {
self.add_user(params)
}

fn update_user(&self, user_id: u64, params: &[(String, String)]) -> Result<User> {
self.update_user(user_id, params)
}

fn delete_user(&self, user_id: u64) -> Result<User> {
self.delete_user(user_id)
}

fn get_space_activities(&self, params: &[(String, String)]) -> Result<Vec<Activity>> {
self.get_space_activities(params)
}
Expand Down Expand Up @@ -261,6 +286,28 @@ impl BacklogApi for BacklogClient {
self.get_recently_viewed_issues(params)
}

fn get_recently_viewed_projects(
&self,
params: &[(String, String)],
) -> Result<Vec<RecentlyViewedProject>> {
self.get_recently_viewed_projects(params)
}

fn get_recently_viewed_wikis(
&self,
params: &[(String, String)],
) -> Result<Vec<RecentlyViewedWiki>> {
self.get_recently_viewed_wikis(params)
}

fn get_user_stars(&self, user_id: u64, params: &[(String, String)]) -> Result<Vec<Star>> {
self.get_user_stars(user_id, params)
}

fn count_user_stars(&self, user_id: u64) -> Result<StarCount> {
self.count_user_stars(user_id)
}

fn get_notifications(&self, params: &[(String, String)]) -> Result<Vec<Notification>> {
self.get_notifications(params)
}
Expand Down
94 changes: 94 additions & 0 deletions src/api/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,59 @@ pub struct RecentlyViewedIssue {
pub extra: BTreeMap<String, serde_json::Value>,
}

#[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<String, serde_json::Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RecentlyViewedProject {
pub project: ProjectSummary,
pub updated: String,
#[serde(flatten)]
pub extra: BTreeMap<String, serde_json::Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WikiSummary {
pub id: u64,
pub name: String,
#[serde(flatten)]
pub extra: BTreeMap<String, serde_json::Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RecentlyViewedWiki {
pub page: WikiSummary,
pub updated: String,
#[serde(flatten)]
pub extra: BTreeMap<String, serde_json::Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Star {
pub id: u64,
pub comment: Option<String>,
pub url: String,
pub title: String,
pub presenter: User,
pub created: String,
Comment on lines +84 to +90
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StarCount {
pub count: u64,
}

impl BacklogClient {
pub fn get_myself(&self) -> Result<User> {
let value = self.get("/users/myself")?;
Expand All @@ -58,6 +111,21 @@ impl BacklogClient {
deserialize(value, "user response")
}

pub fn add_user(&self, params: &[(String, String)]) -> Result<User> {
let value = self.post_form("/users", params)?;
deserialize(value, "user response")
}

pub fn update_user(&self, user_id: u64, params: &[(String, String)]) -> Result<User> {
let value = self.patch_form(&format!("/users/{user_id}"), params)?;
deserialize(value, "user response")
}

pub fn delete_user(&self, user_id: u64) -> Result<User> {
let value = self.delete_req(&format!("/users/{user_id}"))?;
deserialize(value, "user response")
}
Comment on lines +114 to +127

pub fn get_user_activities(
&self,
user_id: u64,
Expand All @@ -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<Vec<RecentlyViewedProject>> {
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<Vec<RecentlyViewedWiki>> {
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<Vec<Star>> {
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<StarCount> {
let value = self.get(&format!("/users/{user_id}/stars/count"))?;
deserialize(value, "star count response")
}
}

#[cfg(test)]
Expand Down
35 changes: 35 additions & 0 deletions src/cmd/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,19 @@ mod tests {
fn get_user(&self, _user_id: u64) -> anyhow::Result<User> {
unimplemented!()
}
fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result<crate::api::user::User> {
unimplemented!()
}
fn update_user(
&self,
_user_id: u64,
_params: &[(String, String)],
) -> anyhow::Result<crate::api::user::User> {
unimplemented!()
}
fn delete_user(&self, _user_id: u64) -> anyhow::Result<crate::api::user::User> {
unimplemented!()
}

fn get_space_activities(
&self,
Expand Down Expand Up @@ -580,6 +593,28 @@ mod tests {
) -> anyhow::Result<Vec<crate::api::user::RecentlyViewedIssue>> {
unimplemented!()
}
fn get_recently_viewed_projects(
&self,
_: &[(String, String)],
) -> anyhow::Result<Vec<crate::api::user::RecentlyViewedProject>> {
unimplemented!()
}
fn get_recently_viewed_wikis(
&self,
_: &[(String, String)],
) -> anyhow::Result<Vec<crate::api::user::RecentlyViewedWiki>> {
unimplemented!()
}
fn get_user_stars(
&self,
_user_id: u64,
_: &[(String, String)],
) -> anyhow::Result<Vec<crate::api::user::Star>> {
unimplemented!()
}
fn count_user_stars(&self, _user_id: u64) -> anyhow::Result<crate::api::user::StarCount> {
unimplemented!()
}
fn get_notifications(
&self,
_: &[(String, String)],
Expand Down
35 changes: 35 additions & 0 deletions src/cmd/issue/attachment/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ mod tests {
fn get_user(&self, _user_id: u64) -> anyhow::Result<crate::api::user::User> {
unimplemented!()
}
fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result<crate::api::user::User> {
unimplemented!()
}
fn update_user(
&self,
_user_id: u64,
_params: &[(String, String)],
) -> anyhow::Result<crate::api::user::User> {
unimplemented!()
}
fn delete_user(&self, _user_id: u64) -> anyhow::Result<crate::api::user::User> {
unimplemented!()
}
fn get_space_activities(
&self,
_: &[(String, String)],
Expand Down Expand Up @@ -257,6 +270,28 @@ mod tests {
) -> anyhow::Result<Vec<crate::api::user::RecentlyViewedIssue>> {
unimplemented!()
}
fn get_recently_viewed_projects(
&self,
_: &[(String, String)],
) -> anyhow::Result<Vec<crate::api::user::RecentlyViewedProject>> {
unimplemented!()
}
fn get_recently_viewed_wikis(
&self,
_: &[(String, String)],
) -> anyhow::Result<Vec<crate::api::user::RecentlyViewedWiki>> {
unimplemented!()
}
fn get_user_stars(
&self,
_user_id: u64,
_: &[(String, String)],
) -> anyhow::Result<Vec<crate::api::user::Star>> {
unimplemented!()
}
fn count_user_stars(&self, _user_id: u64) -> anyhow::Result<crate::api::user::StarCount> {
unimplemented!()
}
fn get_notifications(
&self,
_: &[(String, String)],
Expand Down
35 changes: 35 additions & 0 deletions src/cmd/issue/comment/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ mod tests {
fn get_user(&self, _user_id: u64) -> anyhow::Result<crate::api::user::User> {
unimplemented!()
}
fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result<crate::api::user::User> {
unimplemented!()
}
fn update_user(
&self,
_user_id: u64,
_params: &[(String, String)],
) -> anyhow::Result<crate::api::user::User> {
unimplemented!()
}
fn delete_user(&self, _user_id: u64) -> anyhow::Result<crate::api::user::User> {
unimplemented!()
}
fn get_space_activities(
&self,
_: &[(String, String)],
Expand Down Expand Up @@ -228,6 +241,28 @@ mod tests {
) -> anyhow::Result<Vec<crate::api::user::RecentlyViewedIssue>> {
unimplemented!()
}
fn get_recently_viewed_projects(
&self,
_: &[(String, String)],
) -> anyhow::Result<Vec<crate::api::user::RecentlyViewedProject>> {
unimplemented!()
}
fn get_recently_viewed_wikis(
&self,
_: &[(String, String)],
) -> anyhow::Result<Vec<crate::api::user::RecentlyViewedWiki>> {
unimplemented!()
}
fn get_user_stars(
&self,
_user_id: u64,
_: &[(String, String)],
) -> anyhow::Result<Vec<crate::api::user::Star>> {
unimplemented!()
}
fn count_user_stars(&self, _user_id: u64) -> anyhow::Result<crate::api::user::StarCount> {
unimplemented!()
}
fn get_notifications(
&self,
_: &[(String, String)],
Expand Down
35 changes: 35 additions & 0 deletions src/cmd/issue/comment/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ mod tests {
fn get_user(&self, _user_id: u64) -> anyhow::Result<crate::api::user::User> {
unimplemented!()
}
fn add_user(&self, _params: &[(String, String)]) -> anyhow::Result<crate::api::user::User> {
unimplemented!()
}
fn update_user(
&self,
_user_id: u64,
_params: &[(String, String)],
) -> anyhow::Result<crate::api::user::User> {
unimplemented!()
}
fn delete_user(&self, _user_id: u64) -> anyhow::Result<crate::api::user::User> {
unimplemented!()
}
fn get_space_activities(
&self,
_: &[(String, String)],
Expand Down Expand Up @@ -230,6 +243,28 @@ mod tests {
) -> anyhow::Result<Vec<crate::api::user::RecentlyViewedIssue>> {
unimplemented!()
}
fn get_recently_viewed_projects(
&self,
_: &[(String, String)],
) -> anyhow::Result<Vec<crate::api::user::RecentlyViewedProject>> {
unimplemented!()
}
fn get_recently_viewed_wikis(
&self,
_: &[(String, String)],
) -> anyhow::Result<Vec<crate::api::user::RecentlyViewedWiki>> {
unimplemented!()
}
fn get_user_stars(
&self,
_user_id: u64,
_: &[(String, String)],
) -> anyhow::Result<Vec<crate::api::user::Star>> {
unimplemented!()
}
fn count_user_stars(&self, _user_id: u64) -> anyhow::Result<crate::api::user::StarCount> {
unimplemented!()
}
fn get_notifications(
&self,
_: &[(String, String)],
Expand Down
Loading
Loading