| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- use serde::{Deserialize, Serialize};
- use sqlx::prelude::Type;
- use crate::request::WorkspaceRequest;
- #[derive(Debug, Clone, Serialize)]
- pub struct Workspace {
- pub id: i64,
- pub name: String,
- }
- #[derive(Debug, Clone)]
- pub struct WorkspaceEnvironment {
- pub id: i64,
- pub workspace_id: i64,
- pub name: String,
- }
- #[derive(Debug, Clone, 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)
- }
- pub fn id(&self) -> i64 {
- match self {
- WorkspaceEntry::Collection(c) => c.id,
- WorkspaceEntry::Request(r) => r.entry.id,
- }
- }
- pub fn parent_id(&self) -> Option<i64> {
- match self {
- WorkspaceEntry::Collection(c) => c.parent_id,
- WorkspaceEntry::Request(r) => r.entry.parent_id,
- }
- }
- }
- /// Database model representation
- #[derive(Debug, Clone, Serialize)]
- pub struct WorkspaceEntryBase {
- pub id: i64,
- pub workspace_id: i64,
- pub parent_id: Option<i64>,
- pub name: String,
- pub r#type: WorkspaceEntryType,
- }
- #[derive(Debug, Clone)]
- pub struct WorkspaceEnvVariable {
- pub id: i64,
- pub env_id: i64,
- pub workspace_id: i64,
- pub name: String,
- pub value: Option<String>,
- pub secret: bool,
- }
- #[derive(Debug, Clone, Serialize, 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, 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}"),
- }
- }
- }
|