use serde::{Deserialize, Serialize}; use sqlx::prelude::Type; use crate::{ db::Update, request::{ RequestBody, RequestHeaderUpdate, RequestPathParam, RequestPathUpdate, WorkspaceRequest, }, }; #[derive(Debug, Serialize)] pub struct Workspace { pub id: i64, pub name: String, } #[derive(Debug, Serialize)] #[serde(tag = "type", content = "data")] pub enum WorkspaceEntry { Collection(WorkspaceEntryBase), Request(WorkspaceRequest), } impl WorkspaceEntry { pub fn new_req(req: WorkspaceRequest) -> Self { Self::Request(req) } pub fn new_col(col: WorkspaceEntryBase) -> Self { Self::Collection(col) } } /// Database model representation #[derive(Debug, Serialize)] pub struct WorkspaceEntryBase { pub id: i64, pub workspace_id: i64, pub parent_id: Option, pub name: String, pub r#type: WorkspaceEntryType, } #[derive(Debug, Serialize)] pub struct WorkspaceEnvironment { pub id: i64, pub name: String, pub workspace_id: i64, pub variables: Vec, } #[derive(Debug, Serialize)] pub struct WorkspaceEnvVariable { pub id: i64, pub env_id: i64, pub workspace_id: i64, pub name: String, pub value: String, pub secret: bool, } #[derive(Debug, Deserialize)] pub enum WorkspaceEntryCreate { Collection { name: String, workspace_id: i64, parent_id: Option, }, Request { name: String, workspace_id: i64, parent_id: Option, method: String, url: String, }, } #[derive(Debug, Deserialize)] pub enum WorkspaceEntryUpdate { Collection(WorkspaceEntryUpdateBase), Request { base: WorkspaceEntryUpdateBase, method: Option, url: Option, body: Option>, headers: Option>, path_params: Option>, }, } #[derive(Debug, Deserialize, Default)] pub struct WorkspaceEntryUpdateBase { pub name: Option, pub parent_id: Option>, } #[derive(Debug, Clone, Copy, Type, Serialize)] #[sqlx(type_name = "INTEGER")] pub enum WorkspaceEntryType { Request, Collection, } impl From for WorkspaceEntryType { fn from(value: i64) -> Self { match value { 0 => Self::Request, 1 => Self::Collection, _ => panic!("unrecognized entry type: {value}"), } } }