use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::{http::ApiClient, resources::WorkspaceResource};
#[derive(Debug, Serialize, Deserialize)]
pub struct WorkspaceMember {
pub id: String,
pub name: String,
pub group: String,
#[serde(rename = "joinedAt")]
pub joined_at: DateTime<Utc>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct WorkspaceApp {
pub id: String,
pub name: String,
pub desc: Option<String>,
pub ram: u32,
pub lang: String,
pub domain: Option<String>,
pub custom: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct WorkspaceInfo {
pub id: String,
pub name: String,
pub owner: String,
#[serde(default)]
pub members: Vec<WorkspaceMember>,
#[serde(default)]
pub applications: Vec<WorkspaceApp>,
#[serde(rename = "createdAt")]
pub created_at: DateTime<Utc>,
}
impl WorkspaceInfo {
pub fn into_resource(&self, api: ApiClient) -> WorkspaceResource {
WorkspaceResource::new(api, &self.id)
}
}
#[cfg(test)]
mod tests {
use chrono::Utc;
use super::WorkspaceInfo;
use crate::http::ApiClient;
#[test]
fn into_resource_binds_correct_id() {
unsafe { std::env::set_var("API_TOKEN", "test") };
let ws = WorkspaceInfo {
id: "ws-abc".to_string(),
name: "test".to_string(),
owner: "owner-id".to_string(),
members: vec![],
applications: vec![],
created_at: Utc::now(),
};
let resource = ws.into_resource(ApiClient::new());
assert_eq!(resource.id, "ws-abc");
}
}