Add workspaces

This commit is contained in:
Joshua Coles 2024-07-16 17:22:57 +01:00
parent a780af3f62
commit 4cbb60b5ac

View File

@ -73,6 +73,22 @@ impl TogglApi {
headers headers
} }
/// Get the workspaces that a user is a part of
async fn get_users_workspaces(
&self
) -> Result<Vec<types::Workspace>, TogglError> {
let url = format!("{base_url}/me/workspaces", base_url = BASE_URL);
let response = self.client.get(&url)
.headers(self.headers.clone())
.send().await?;
let data = response.text().await?;
let workspaces: Vec<types::Workspace> = serde_json::from_str(&data)?;
Ok(workspaces)
}
/// Fetches all time entries for this user from Toggl that have been modified since the given /// Fetches all time entries for this user from Toggl that have been modified since the given
/// date. /// date.
pub async fn get_time_entries_for_user_modified_since(&self, since: DateTime<Utc>) -> Result<Vec<types::TimeEntry>, TogglError> { pub async fn get_time_entries_for_user_modified_since(&self, since: DateTime<Utc>) -> Result<Vec<types::TimeEntry>, TogglError> {
@ -221,7 +237,8 @@ pub mod types {
#[serde(with = "duration_field")] #[serde(with = "duration_field")]
duration: Option<u32>, duration: Option<u32>,
at: DateTime<Utc>, #[serde(rename = "at")]
updated_at: DateTime<Utc>,
description: String, description: String,
@ -273,7 +290,8 @@ pub mod types {
status: ProjectStatus, status: ProjectStatus,
active: bool, active: bool,
at: DateTime<Utc>, #[serde(rename = "at")]
updated_at: DateTime<Utc>,
start_date: NaiveDate, start_date: NaiveDate,
created_at: DateTime<Utc>, created_at: DateTime<Utc>,
server_deleted_at: Option<DateTime<Utc>>, server_deleted_at: Option<DateTime<Utc>>,
@ -300,7 +318,8 @@ pub mod types {
pub id: i64, pub id: i64,
/// Represents the timestamp of the last update made to the client. /// Represents the timestamp of the last update made to the client.
pub at: DateTime<Utc>, #[serde(rename = "at")]
pub updated_at: DateTime<Utc>,
/// Indicates whether the client is archived or not. /// Indicates whether the client is archived or not.
pub archived: bool, pub archived: bool,
@ -328,7 +347,8 @@ pub mod types {
name: String, name: String,
workspace_id: u64, workspace_id: u64,
creator_id: u64, creator_id: u64,
at: DateTime<Utc>, #[serde(rename = "at")]
updated_at: DateTime<Utc>,
deleted_at: Option<DateTime<Utc>>, deleted_at: Option<DateTime<Utc>>,
permissions: Option<String>, permissions: Option<String>,
} }
@ -358,7 +378,8 @@ pub mod types {
pub seconds: u32, pub seconds: u32,
pub start: DateTime<Utc>, pub start: DateTime<Utc>,
pub stop: DateTime<Utc>, pub stop: DateTime<Utc>,
pub at: DateTime<Utc>, #[serde(rename = "at")]
pub updated_at: DateTime<Utc>,
} }
#[skip_serializing_none] #[skip_serializing_none]
@ -483,6 +504,13 @@ pub mod types {
ds.finish() ds.finish()
} }
} }
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Workspace {
pub id: u64,
pub organization_id: u64,
pub name: String,
}
} }
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]