|
|
@@ -2,19 +2,23 @@ use crate::{
|
|
|
auth::{Auth, Authentication},
|
|
|
error::AppError,
|
|
|
request::{
|
|
|
- EntryRequestBody, RequestBody, RequestHeader, RequestHeaderInsert, RequestHeaderUpdate,
|
|
|
- RequestParams, RequestPathParam, RequestQueryParam, WorkspaceRequest,
|
|
|
+ EntryRequestBody, PathParamRead, PathParamWrite, QueryParamRead, RequestBody,
|
|
|
+ RequestHeader, RequestHeaderInsert, RequestHeaderUpdate, RequestParams, RequestPathUpdate,
|
|
|
+ RequestQueryUpdate, WorkspaceRequest,
|
|
|
},
|
|
|
workspace::{
|
|
|
Workspace, WorkspaceEntry, WorkspaceEntryBase, WorkspaceEntryCreate, WorkspaceEntryType,
|
|
|
- WorkspaceEntryUpdate, WorkspaceEnvVariable, WorkspaceEnvironment,
|
|
|
+ WorkspaceEnvVariable, WorkspaceEnvironment,
|
|
|
},
|
|
|
AppResult,
|
|
|
};
|
|
|
use serde::Deserialize;
|
|
|
-use sqlx::{sqlite::SqlitePool, types::Json, QueryBuilder};
|
|
|
-use std::collections::HashMap;
|
|
|
-use tauri_plugin_log::log;
|
|
|
+use sqlx::{
|
|
|
+ sqlite::{SqliteConnectOptions, SqlitePool},
|
|
|
+ types::Json,
|
|
|
+ ConnectOptions, QueryBuilder,
|
|
|
+};
|
|
|
+use std::{collections::HashMap, str::FromStr};
|
|
|
|
|
|
/// Used in update DTOs for **optional** properties. A value indicates a parameter needs to be updated to whatever is contained in it, a null indicates to set the field to null.
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
@@ -44,7 +48,11 @@ impl<T: Copy> Update<T> {
|
|
|
}
|
|
|
|
|
|
pub async fn init(url: &str) -> SqlitePool {
|
|
|
- let pool = SqlitePool::connect(url)
|
|
|
+ let mut opts = SqliteConnectOptions::from_str(url).unwrap();
|
|
|
+
|
|
|
+ opts = ConnectOptions::log_statements(opts, tauri_plugin_log::log::LevelFilter::Off);
|
|
|
+
|
|
|
+ let pool = SqlitePool::connect_with(opts)
|
|
|
.await
|
|
|
.expect("error while connecting to db");
|
|
|
|
|
|
@@ -184,7 +192,7 @@ pub async fn insert_request_body(
|
|
|
entry_id: i64,
|
|
|
body: RequestBody,
|
|
|
) -> AppResult<EntryRequestBody> {
|
|
|
- Ok(sqlx::query_as!(EntryRequestBody, r#"INSERT INTO request_bodies(request_id, content_type, body) VALUES (?, ?, ?) RETURNING id, content_type AS "content_type: _", body"#, entry_id, body.ty, body.content).fetch_one(&db).await?)
|
|
|
+ Ok(sqlx::query_as!(EntryRequestBody, r#"INSERT INTO request_bodies(request_id, ty, content) VALUES (?, ?, ?) RETURNING id, ty AS "ty: _", content"#, entry_id, body.ty, body.content).fetch_one(&db).await?)
|
|
|
}
|
|
|
|
|
|
pub async fn update_request_body(
|
|
|
@@ -195,7 +203,7 @@ pub async fn update_request_body(
|
|
|
match body {
|
|
|
Update::Value(body) => {
|
|
|
sqlx::query!(
|
|
|
- "UPDATE request_bodies SET content_type = ?, body = ? WHERE id = ?",
|
|
|
+ "UPDATE request_bodies SET ty = ?, content = ? WHERE id = ?",
|
|
|
body.ty,
|
|
|
body.content,
|
|
|
id,
|
|
|
@@ -212,188 +220,263 @@ pub async fn update_request_body(
|
|
|
Ok(())
|
|
|
}
|
|
|
|
|
|
-pub async fn update_workspace_entry(
|
|
|
- db: SqlitePool,
|
|
|
- entry_id: i64,
|
|
|
- update: WorkspaceEntryUpdate,
|
|
|
+pub async fn update_request_method(db: SqlitePool, request_id: i64, method: &str) -> AppResult<()> {
|
|
|
+ sqlx::query!(
|
|
|
+ "UPDATE request_params SET method = ? WHERE request_id = ?",
|
|
|
+ method,
|
|
|
+ request_id
|
|
|
+ )
|
|
|
+ .execute(&db)
|
|
|
+ .await?;
|
|
|
+
|
|
|
+ Ok(())
|
|
|
+}
|
|
|
+
|
|
|
+pub async fn get_query_param(db: &SqlitePool, qp_id: i64) -> AppResult<QueryParamRead> {
|
|
|
+ Ok(sqlx::query_as!(
|
|
|
+ QueryParamRead,
|
|
|
+ "SELECT id, position, key, value FROM request_query_params WHERE id = ?",
|
|
|
+ qp_id
|
|
|
+ )
|
|
|
+ .fetch_one(db)
|
|
|
+ .await?)
|
|
|
+}
|
|
|
+
|
|
|
+pub async fn update_query_param_values(
|
|
|
+ db: &SqlitePool,
|
|
|
+ id: i64,
|
|
|
+ key: &str,
|
|
|
+ value: &str,
|
|
|
) -> AppResult<()> {
|
|
|
- match update {
|
|
|
- WorkspaceEntryUpdate::Collection(update) => {
|
|
|
- let mut sql = sqlx::query_builder::QueryBuilder::new("UPDATE workspace_entries SET ");
|
|
|
+ sqlx::query!(
|
|
|
+ "UPDATE request_query_params SET key = ?, value = ? WHERE id = ?",
|
|
|
+ key,
|
|
|
+ value,
|
|
|
+ id
|
|
|
+ )
|
|
|
+ .execute(db)
|
|
|
+ .await?;
|
|
|
|
|
|
- if let Some(parent) = update.parent_id {
|
|
|
- check_parent(&db, parent.value()).await?;
|
|
|
- }
|
|
|
+ Ok(())
|
|
|
+}
|
|
|
|
|
|
- match (update.name, update.parent_id) {
|
|
|
- (None, None) => {
|
|
|
- return Err(AppError::InvalidUpdate(
|
|
|
- "cannot update entry: no updates present".to_string(),
|
|
|
- ))
|
|
|
- }
|
|
|
- (None, Some(parent_id)) => match parent_id {
|
|
|
- Update::Value(v) => {
|
|
|
- sql.push("parent_id = ").push_bind(v);
|
|
|
- }
|
|
|
- Update::Null => {
|
|
|
- sql.push("parent_id = NULL ");
|
|
|
- }
|
|
|
- },
|
|
|
- (Some(name), None) => {
|
|
|
- sql.push("name = ").push_bind(name);
|
|
|
- }
|
|
|
- (Some(name), Some(parent_id)) => {
|
|
|
- match parent_id {
|
|
|
- Update::Value(v) => {
|
|
|
- sql.push("parent_id = ").push_bind(v);
|
|
|
- }
|
|
|
- Update::Null => {
|
|
|
- sql.push("parent_id = NULL ");
|
|
|
- }
|
|
|
- };
|
|
|
- sql.push(", name = ").push_bind(name);
|
|
|
- }
|
|
|
- }
|
|
|
+pub async fn update_query_param_enabled(
|
|
|
+ db: &SqlitePool,
|
|
|
+ qp_id: i64,
|
|
|
+ position: Option<i64>,
|
|
|
+) -> AppResult<QueryParamRead> {
|
|
|
+ Ok(sqlx::query_as!(
|
|
|
+ QueryParamRead,
|
|
|
+ "UPDATE request_query_params SET position = ? WHERE id = ? RETURNING id, position, key, value",
|
|
|
+ position,
|
|
|
+ qp_id
|
|
|
+ )
|
|
|
+ .fetch_one(db)
|
|
|
+ .await?)
|
|
|
+}
|
|
|
|
|
|
- sql.push("WHERE id = ")
|
|
|
- .push_bind(entry_id)
|
|
|
- .build()
|
|
|
- .execute(&db)
|
|
|
- .await?;
|
|
|
+pub async fn update_query_param_position(
|
|
|
+ db: &SqlitePool,
|
|
|
+ req_id: i64,
|
|
|
+ // Offset by amount
|
|
|
+ offset: i64,
|
|
|
+ // Start from position
|
|
|
+ position: i64,
|
|
|
+) -> AppResult<()> {
|
|
|
+ sqlx::query!(
|
|
|
+ "UPDATE request_query_params SET position = position + ? WHERE request_id = ? AND position > ?",
|
|
|
+ offset,
|
|
|
+ req_id,
|
|
|
+ position,
|
|
|
+ )
|
|
|
+ .execute(db)
|
|
|
+ .await?;
|
|
|
|
|
|
- Ok(())
|
|
|
- }
|
|
|
- WorkspaceEntryUpdate::Request {
|
|
|
- base,
|
|
|
- method,
|
|
|
- url,
|
|
|
- path_params,
|
|
|
- query_params,
|
|
|
- } => {
|
|
|
- let mut tx = db.begin().await?;
|
|
|
+ Ok(())
|
|
|
+}
|
|
|
|
|
|
- 'entry: {
|
|
|
- if let Some(parent) = base.parent_id {
|
|
|
- check_parent(&db, parent.value()).await?;
|
|
|
- }
|
|
|
+/// Return only the active request params.
|
|
|
+pub async fn get_request_url_params(
|
|
|
+ db: &SqlitePool,
|
|
|
+ request_id: i64,
|
|
|
+) -> AppResult<(Vec<PathParamRead>, Vec<QueryParamRead>)> {
|
|
|
+ let mut path = vec![];
|
|
|
+ let mut query = vec![];
|
|
|
|
|
|
- let mut sql =
|
|
|
- sqlx::query_builder::QueryBuilder::new("UPDATE workspace_entries SET ");
|
|
|
-
|
|
|
- match (base.name, base.parent_id) {
|
|
|
- (None, None) => break 'entry,
|
|
|
- (None, Some(parent_id)) => match parent_id {
|
|
|
- Update::Value(v) => {
|
|
|
- sql.push("parent_id = ").push_bind(v);
|
|
|
- }
|
|
|
- Update::Null => {
|
|
|
- sql.push("parent_id = NULL ");
|
|
|
- }
|
|
|
- },
|
|
|
- (Some(name), None) => {
|
|
|
- sql.push("name = ").push_bind(name);
|
|
|
- }
|
|
|
- (Some(name), Some(parent_id)) => {
|
|
|
- match parent_id {
|
|
|
- Update::Value(v) => {
|
|
|
- sql.push("parent_id = ").push_bind(v);
|
|
|
- }
|
|
|
- Update::Null => {
|
|
|
- sql.push("parent_id = NULL ");
|
|
|
- }
|
|
|
- };
|
|
|
- sql.push(", name = ").push_bind(name);
|
|
|
- }
|
|
|
- }
|
|
|
+ let params = sqlx::query!(
|
|
|
+ r#"
|
|
|
+ SELECT id, position, name, value, 0 AS type
|
|
|
+ FROM request_path_params WHERE request_id = ?
|
|
|
+ UNION
|
|
|
+ SELECT id, position, key AS "name", value, 1 AS type
|
|
|
+ FROM request_query_params WHERE request_id = ?
|
|
|
+ "#,
|
|
|
+ request_id,
|
|
|
+ request_id
|
|
|
+ )
|
|
|
+ .fetch_all(db)
|
|
|
+ .await?;
|
|
|
|
|
|
- sql.push("WHERE id = ")
|
|
|
- .push_bind(entry_id)
|
|
|
- .build()
|
|
|
- .execute(&mut *tx)
|
|
|
- .await?;
|
|
|
- };
|
|
|
+ for param in params {
|
|
|
+ match param.r#type {
|
|
|
+ 0 => path.push(PathParamRead::new(
|
|
|
+ param.id,
|
|
|
+ // Path positions can never be null
|
|
|
+ param.position.unwrap(),
|
|
|
+ param.name,
|
|
|
+ param.value,
|
|
|
+ )),
|
|
|
+ 1 => query.push(QueryParamRead::new(
|
|
|
+ param.id,
|
|
|
+ param.position,
|
|
|
+ param.name,
|
|
|
+ param.value,
|
|
|
+ )),
|
|
|
+ _ => unreachable!(),
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- 'param: {
|
|
|
- let mut sql = sqlx::query_builder::QueryBuilder::new("UPDATE request_params ");
|
|
|
-
|
|
|
- match (method, url) {
|
|
|
- (None, None) => break 'param,
|
|
|
- (None, Some(url)) => {
|
|
|
- sql.push("SET url = ").push_bind(url);
|
|
|
- }
|
|
|
- (Some(method), None) => {
|
|
|
- sql.push("SET method = ").push_bind(method);
|
|
|
- }
|
|
|
- (Some(method), Some(url)) => {
|
|
|
- sql.push("SET method = ")
|
|
|
- .push_bind(method)
|
|
|
- .push(", url = ")
|
|
|
- .push_bind(url);
|
|
|
- }
|
|
|
- }
|
|
|
+ Ok((path, query))
|
|
|
+}
|
|
|
|
|
|
- sql.push("WHERE request_id = ")
|
|
|
- .push_bind(entry_id)
|
|
|
- .build()
|
|
|
- .execute(&mut *tx)
|
|
|
- .await?;
|
|
|
- };
|
|
|
+pub async fn update_request_url(
|
|
|
+ db: &SqlitePool,
|
|
|
+ request_id: i64,
|
|
|
+ url: &str,
|
|
|
+ path_params: Option<Vec<RequestPathUpdate<'_>>>,
|
|
|
+ query_params: Option<Vec<RequestQueryUpdate<'_>>>,
|
|
|
+) -> AppResult<()> {
|
|
|
+ let mut tx = db.begin().await?;
|
|
|
|
|
|
- if let Some(path_params) = path_params {
|
|
|
- if path_params.is_empty() {
|
|
|
- sqlx::query!(
|
|
|
- "DELETE FROM request_path_params WHERE request_id = ?",
|
|
|
- entry_id
|
|
|
- )
|
|
|
- .execute(&mut *tx)
|
|
|
- .await?;
|
|
|
- } else {
|
|
|
- let mut sql = QueryBuilder::new(
|
|
|
- "INSERT INTO request_path_params(position, request_id, name, value) ",
|
|
|
- );
|
|
|
-
|
|
|
- sql.push_values(path_params.iter(), |mut b, path| {
|
|
|
- b.push_bind(path.position as i64)
|
|
|
- .push_bind(entry_id)
|
|
|
- .push_bind(&path.name);
|
|
|
-
|
|
|
- if let Some(ref path) = path.value {
|
|
|
- b.push_bind(path);
|
|
|
- } else {
|
|
|
- b.push_bind("");
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- sql.push(
|
|
|
- r#"
|
|
|
- ON CONFLICT(position, request_id) DO UPDATE
|
|
|
- SET
|
|
|
- value = excluded.value,
|
|
|
- name = excluded.name;
|
|
|
-
|
|
|
- DELETE FROM request_path_params
|
|
|
- WHERE request_id = "#,
|
|
|
+ sqlx::query!(
|
|
|
+ "UPDATE request_params SET url = ? WHERE request_id = ?",
|
|
|
+ url,
|
|
|
+ request_id
|
|
|
+ )
|
|
|
+ .execute(&mut *tx)
|
|
|
+ .await?;
|
|
|
+
|
|
|
+ if let Some(path_params) = path_params {
|
|
|
+ // Empty path params means delete everything since they cannot be toggled
|
|
|
+ // and their position is ALWAYS unique
|
|
|
+ if path_params.is_empty() {
|
|
|
+ sqlx::query!(
|
|
|
+ "DELETE FROM request_path_params WHERE request_id = ?",
|
|
|
+ request_id
|
|
|
+ )
|
|
|
+ .execute(&mut *tx)
|
|
|
+ .await?;
|
|
|
+ } else {
|
|
|
+ let mut sql = QueryBuilder::new(
|
|
|
+ "INSERT INTO request_path_params(position, request_id, name, value) ",
|
|
|
+ );
|
|
|
+
|
|
|
+ sql.push_values(path_params.iter(), |mut b, path| {
|
|
|
+ b.push_bind(path.position as i64)
|
|
|
+ .push_bind(request_id)
|
|
|
+ .push_bind(path.name)
|
|
|
+ .push("COALESCE(")
|
|
|
+ .push_bind_unseparated(path.value)
|
|
|
+ .push_unseparated(
|
|
|
+ ", (SELECT value FROM request_path_params WHERE request_id = ",
|
|
|
)
|
|
|
- .push_bind(entry_id)
|
|
|
- .push(" AND position NOT IN (");
|
|
|
+ .push_bind_unseparated(request_id)
|
|
|
+ .push_unseparated("AND position = ")
|
|
|
+ .push_bind_unseparated(path.position as i64)
|
|
|
+ .push_unseparated("), '')");
|
|
|
+ });
|
|
|
|
|
|
- let mut sep = sql.separated(", ");
|
|
|
+ // Delete any conflicting positions
|
|
|
|
|
|
- for param in path_params.iter() {
|
|
|
- sep.push_bind(param.position as i64);
|
|
|
- }
|
|
|
+ sql.push(
|
|
|
+ r#"
|
|
|
+ ON CONFLICT(position, request_id) DO UPDATE
|
|
|
+ SET
|
|
|
+ value = excluded.value,
|
|
|
+ name = excluded.name;
|
|
|
|
|
|
- sep.push_unseparated(")");
|
|
|
+ DELETE FROM request_path_params
|
|
|
+ WHERE request_id = "#,
|
|
|
+ )
|
|
|
+ .push_bind(request_id)
|
|
|
+ .push(" AND position NOT IN (");
|
|
|
|
|
|
- sql.build().execute(&mut *tx).await?;
|
|
|
- }
|
|
|
+ let mut sep = sql.separated(", ");
|
|
|
+
|
|
|
+ for param in path_params.iter() {
|
|
|
+ sep.push_bind(param.position as i64);
|
|
|
}
|
|
|
|
|
|
- tx.commit().await?;
|
|
|
+ sep.push_unseparated(")");
|
|
|
|
|
|
- Ok(())
|
|
|
+ sql.build().execute(&mut *tx).await?;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if let Some(query_params) = query_params {
|
|
|
+ // Query param updates consider only the enabled QPs since toggling any
|
|
|
+ // disabled ones always adds them to the end of the list
|
|
|
+
|
|
|
+ if query_params.is_empty() {
|
|
|
+ sqlx::query!(
|
|
|
+ "DELETE FROM request_query_params WHERE request_id = ? AND position IS NOT NULL",
|
|
|
+ request_id
|
|
|
+ )
|
|
|
+ .execute(&mut *tx)
|
|
|
+ .await?;
|
|
|
+ } else {
|
|
|
+ let mut sql = QueryBuilder::new(
|
|
|
+ "INSERT INTO request_query_params(position, request_id, key, value) ",
|
|
|
+ );
|
|
|
+
|
|
|
+ sql.push_values(query_params.iter(), |mut b, qp| {
|
|
|
+ b.push_bind(qp.position as i64)
|
|
|
+ .push_bind(request_id)
|
|
|
+ .push_bind(qp.key)
|
|
|
+ .push_bind(qp.value);
|
|
|
+ });
|
|
|
+
|
|
|
+ // Query params are unique by position and req_id
|
|
|
+
|
|
|
+ sql.push(
|
|
|
+ r#"
|
|
|
+ ON CONFLICT(position, request_id) DO UPDATE
|
|
|
+ SET
|
|
|
+ value = excluded.value,
|
|
|
+ key = excluded.key;
|
|
|
+
|
|
|
+ DELETE FROM request_query_params
|
|
|
+ WHERE request_id = "#,
|
|
|
+ )
|
|
|
+ .push_bind(request_id)
|
|
|
+ .push(" AND position IS NOT NULL AND position NOT IN (");
|
|
|
+
|
|
|
+ let mut sep = sql.separated(", ");
|
|
|
+
|
|
|
+ for param in query_params.iter() {
|
|
|
+ sep.push_bind(param.position as i64);
|
|
|
+ }
|
|
|
+
|
|
|
+ sep.push_unseparated(")");
|
|
|
+
|
|
|
+ sql.build().execute(&mut *tx).await?;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ tx.commit().await?;
|
|
|
+
|
|
|
+ Ok(())
|
|
|
+}
|
|
|
+
|
|
|
+pub async fn update_entry_name(db: SqlitePool, entry_id: i64, name: &str) -> AppResult<()> {
|
|
|
+ sqlx::query!(
|
|
|
+ "UPDATE workspace_entries SET name = ? WHERE id = ?",
|
|
|
+ name,
|
|
|
+ entry_id
|
|
|
+ )
|
|
|
+ .execute(&db)
|
|
|
+ .await?;
|
|
|
+ Ok(())
|
|
|
}
|
|
|
|
|
|
pub async fn get_workspace_request(db: SqlitePool, id: i64) -> AppResult<WorkspaceRequest> {
|
|
|
@@ -412,8 +495,8 @@ pub async fn get_workspace_request(db: SqlitePool, id: i64) -> AppResult<Workspa
|
|
|
rp.request_id as id,
|
|
|
method as 'method!',
|
|
|
url as 'url!',
|
|
|
- content_type as "content_type: _",
|
|
|
- body AS "body: _",
|
|
|
+ rb.ty as "ty: _",
|
|
|
+ rb.content AS "content: _",
|
|
|
rb.id AS "body_id: _"
|
|
|
FROM request_params rp
|
|
|
LEFT JOIN request_bodies rb ON rp.request_id = rb.request_id
|
|
|
@@ -432,21 +515,7 @@ pub async fn get_workspace_request(db: SqlitePool, id: i64) -> AppResult<Workspa
|
|
|
.fetch_all(&db)
|
|
|
.await?;
|
|
|
|
|
|
- let path_params = sqlx::query_as!(
|
|
|
- RequestPathParam,
|
|
|
- "SELECT position, name, value FROM request_path_params WHERE request_id = ?",
|
|
|
- entry.id
|
|
|
- )
|
|
|
- .fetch_all(&db)
|
|
|
- .await?;
|
|
|
-
|
|
|
- let query_params = sqlx::query_as!(
|
|
|
- RequestQueryParam,
|
|
|
- "SELECT position, key, value, enabled FROM request_query_params WHERE request_id = ?",
|
|
|
- entry.id
|
|
|
- )
|
|
|
- .fetch_all(&db)
|
|
|
- .await?;
|
|
|
+ let (path_params, query_params) = get_request_url_params(&db, id).await?;
|
|
|
|
|
|
Ok(WorkspaceRequest::from_entry(
|
|
|
entry,
|
|
|
@@ -472,58 +541,9 @@ pub async fn get_workspace_entry(db: SqlitePool, id: i64) -> AppResult<Workspace
|
|
|
.await?;
|
|
|
|
|
|
match entry.r#type {
|
|
|
- WorkspaceEntryType::Request => {
|
|
|
- let params = sqlx::query_as!(
|
|
|
- RequestParams,
|
|
|
- r#"
|
|
|
- SELECT
|
|
|
- rp.request_id as id,
|
|
|
- method as 'method!',
|
|
|
- url as 'url!',
|
|
|
- content_type as "content_type: _",
|
|
|
- body as "body: _",
|
|
|
- rb.id as "body_id: _"
|
|
|
- FROM request_params rp
|
|
|
- LEFT JOIN request_bodies rb ON rp.request_id = rb.request_id
|
|
|
- WHERE rp.request_id = ?
|
|
|
- LIMIT 1
|
|
|
- "#,
|
|
|
- id
|
|
|
- )
|
|
|
- .fetch_one(&db)
|
|
|
- .await?;
|
|
|
-
|
|
|
- dbg!(¶ms);
|
|
|
-
|
|
|
- let headers = sqlx::query_as!(
|
|
|
- RequestHeader,
|
|
|
- "SELECT id, name, value FROM request_headers WHERE request_id = ?",
|
|
|
- entry.id
|
|
|
- )
|
|
|
- .fetch_all(&db)
|
|
|
- .await?;
|
|
|
-
|
|
|
- let path_params = sqlx::query_as!(
|
|
|
- RequestPathParam,
|
|
|
- "SELECT position, name, value FROM request_path_params WHERE request_id = ?",
|
|
|
- entry.id
|
|
|
- )
|
|
|
- .fetch_all(&db)
|
|
|
- .await?;
|
|
|
-
|
|
|
- let query_params = sqlx::query_as!(
|
|
|
- RequestQueryParam,
|
|
|
- "SELECT position, key, value, enabled FROM request_query_params WHERE request_id = ?",
|
|
|
- entry.id
|
|
|
- )
|
|
|
- .fetch_all(&db)
|
|
|
- .await?;
|
|
|
-
|
|
|
- let req =
|
|
|
- WorkspaceRequest::from_entry(entry, params, headers, path_params, query_params);
|
|
|
-
|
|
|
- Ok(WorkspaceEntry::new_req(req))
|
|
|
- }
|
|
|
+ WorkspaceEntryType::Request => Ok(WorkspaceEntry::new_req(
|
|
|
+ get_workspace_request(db, id).await?,
|
|
|
+ )),
|
|
|
WorkspaceEntryType::Collection => Ok(WorkspaceEntry::new_col(entry)),
|
|
|
}
|
|
|
}
|
|
|
@@ -730,9 +750,9 @@ pub async fn delete_env_var(db: SqlitePool, id: i64) -> AppResult<()> {
|
|
|
Ok(())
|
|
|
}
|
|
|
|
|
|
-pub async fn list_request_path_params(db: SqlitePool, id: i64) -> AppResult<Vec<RequestPathParam>> {
|
|
|
+pub async fn list_request_path_params(db: SqlitePool, id: i64) -> AppResult<Vec<PathParamWrite>> {
|
|
|
Ok(sqlx::query_as!(
|
|
|
- RequestPathParam,
|
|
|
+ PathParamWrite,
|
|
|
"SELECT position, name, value FROM request_path_params WHERE request_id = ?",
|
|
|
id
|
|
|
)
|