| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- use crate::{
- db::Update,
- request::{RequestPathUpdate, WorkspaceRequest},
- };
- use serde::{Deserialize, Serialize};
- use sqlx::prelude::Type;
- #[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 of either a collection or a request.
- #[derive(Debug, Serialize)]
- pub struct WorkspaceEntryBase {
- /// Entry ID.
- pub id: i64,
- /// Containing workspace ID.
- pub workspace_id: i64,
- /// If present, holds the parent collection ID of the entry.
- pub parent_id: Option<i64>,
- /// User friendly display name for the entry.
- pub name: String,
- /// Whether this type is a collection or a request.
- pub r#type: WorkspaceEntryType,
- /// If present, holds the [Authentication][crate::auth::Authentication] ID of the entry.
- pub auth: Option<i64>,
- /// If `true`, the entry will inherit the auth scheme of its parent entry.
- pub auth_inherit: bool,
- }
- #[derive(Debug, Serialize)]
- pub struct WorkspaceEnvironment {
- pub id: i64,
- pub name: String,
- pub workspace_id: i64,
- pub variables: Vec<WorkspaceEnvVariable>,
- }
- #[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<i64>,
- },
- Request {
- name: String,
- workspace_id: i64,
- parent_id: Option<i64>,
- method: String,
- url: String,
- },
- }
- #[derive(Debug, Deserialize)]
- pub enum WorkspaceEntryUpdate {
- Collection(WorkspaceEntryUpdateBase),
- Request {
- base: WorkspaceEntryUpdateBase,
- method: Option<String>,
- url: Option<String>,
- path_params: Option<Vec<RequestPathUpdate>>,
- },
- }
- #[derive(Debug, Deserialize, Default)]
- pub struct WorkspaceEntryUpdateBase {
- pub name: Option<String>,
- pub parent_id: Option<Update<i64>>,
- }
- #[derive(Debug, Clone, Copy, Type, Serialize)]
- #[sqlx(type_name = "INTEGER")]
- pub enum WorkspaceEntryType {
- Request,
- Collection,
- }
- impl From<i64> for WorkspaceEntryType {
- fn from(value: i64) -> Self {
- match value {
- 0 => Self::Request,
- 1 => Self::Collection,
- _ => panic!("unrecognized entry type: {value}"),
- }
- }
- }
|