Add body type to request and tab dropdown

This commit is contained in:
Gregory Schier
2023-03-14 11:18:56 -07:00
parent 619c8d9e72
commit efa5455a7b
12 changed files with 280 additions and 152 deletions

View File

@@ -0,0 +1 @@
ALTER TABLE http_requests ADD COLUMN body_type TEXT NULL;

View File

@@ -20,78 +20,6 @@
},
"query": "\n DELETE FROM http_responses\n WHERE request_id = ?\n "
},
"3d2a542964d946ff9854d053b1adf04985d97a6de27b713188505c1f99c77707": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "workspace_id",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "created_at",
"ordinal": 2,
"type_info": "Datetime"
},
{
"name": "updated_at",
"ordinal": 3,
"type_info": "Datetime"
},
{
"name": "deleted_at",
"ordinal": 4,
"type_info": "Datetime"
},
{
"name": "name",
"ordinal": 5,
"type_info": "Text"
},
{
"name": "url",
"ordinal": 6,
"type_info": "Text"
},
{
"name": "method",
"ordinal": 7,
"type_info": "Text"
},
{
"name": "body",
"ordinal": 8,
"type_info": "Text"
},
{
"name": "headers!: sqlx::types::Json<Vec<HttpRequestHeader>>",
"ordinal": 9,
"type_info": "Text"
}
],
"nullable": [
false,
false,
false,
false,
true,
false,
false,
false,
true,
false
],
"parameters": {
"Right": 1
}
},
"query": "\n SELECT id, workspace_id, created_at, updated_at, deleted_at, name, url, method, body,\n headers AS \"headers!: sqlx::types::Json<Vec<HttpRequestHeader>>\"\n FROM http_requests\n WHERE workspace_id = ?\n "
},
"448a1d1f1866ab42c0f81fcf8eb2930bf21dfdd43ca4831bc1a198cf45ac3732": {
"describe": {
"columns": [],
@@ -102,7 +30,7 @@
},
"query": "\n DELETE FROM http_requests\n WHERE id = ?\n "
},
"7ec60cbc3c9f26e8af86a21ef6b66e564f4fa518925c92308b04f882237a244e": {
"795391626a74376de88fb8ff015f99fb10d6d8a5c9a0623dc279e833e8e86a07": {
"describe": {
"columns": [
{
@@ -151,9 +79,14 @@
"type_info": "Text"
},
{
"name": "headers!: sqlx::types::Json<Vec<HttpRequestHeader>>",
"name": "body_type",
"ordinal": 9,
"type_info": "Text"
},
{
"name": "headers!: sqlx::types::Json<Vec<HttpRequestHeader>>",
"ordinal": 10,
"type_info": "Text"
}
],
"nullable": [
@@ -166,13 +99,14 @@
false,
false,
true,
true,
false
],
"parameters": {
"Right": 1
}
},
"query": "\n SELECT id, workspace_id, created_at, updated_at, deleted_at, name, url, method, body,\n headers AS \"headers!: sqlx::types::Json<Vec<HttpRequestHeader>>\"\n FROM http_requests\n WHERE id = ?\n ORDER BY created_at DESC\n "
"query": "\n SELECT\n id,\n workspace_id,\n created_at,\n updated_at,\n deleted_at,\n name,\n url,\n method,\n body,\n body_type,\n headers AS \"headers!: sqlx::types::Json<Vec<HttpRequestHeader>>\"\n FROM http_requests\n WHERE id = ?\n ORDER BY created_at DESC\n "
},
"7f623d0e8f1ddad33d356e2d159b776a2bef1a238cb9200d74eb0c5e3983df85": {
"describe": {
@@ -312,16 +246,6 @@
},
"query": "\n SELECT id, created_at, updated_at, deleted_at, name, description\n FROM workspaces\n "
},
"a097740ea4ab772ec6f9d8a5144d6871e0b172130d5abe4da61e663155d2bf25": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Right": 7
}
},
"query": "\n INSERT INTO http_requests (id, workspace_id, name, url, method, body, headers, updated_at)\n VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)\n ON CONFLICT (id) DO UPDATE SET\n updated_at = CURRENT_TIMESTAMP,\n name = excluded.name,\n method = excluded.method,\n headers = excluded.headers,\n body = excluded.body,\n url = excluded.url\n "
},
"a83698dcf9a815b881097133edb31a34ba25e7c6c114d463c495342a85371639": {
"describe": {
"columns": [],
@@ -332,6 +256,84 @@
},
"query": "\n UPDATE http_responses SET (elapsed, url, status, status_reason, body, error, headers, updated_at) =\n (?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP) WHERE id = ?;\n "
},
"d572673b8eadbd5238c7a972b581fa8788f92a44fcc8decd0f1333e662f3374b": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "workspace_id",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "created_at",
"ordinal": 2,
"type_info": "Datetime"
},
{
"name": "updated_at",
"ordinal": 3,
"type_info": "Datetime"
},
{
"name": "deleted_at",
"ordinal": 4,
"type_info": "Datetime"
},
{
"name": "name",
"ordinal": 5,
"type_info": "Text"
},
{
"name": "url",
"ordinal": 6,
"type_info": "Text"
},
{
"name": "method",
"ordinal": 7,
"type_info": "Text"
},
{
"name": "body",
"ordinal": 8,
"type_info": "Text"
},
{
"name": "body_type",
"ordinal": 9,
"type_info": "Text"
},
{
"name": "headers!: sqlx::types::Json<Vec<HttpRequestHeader>>",
"ordinal": 10,
"type_info": "Text"
}
],
"nullable": [
false,
false,
false,
false,
true,
false,
false,
false,
true,
true,
false
],
"parameters": {
"Right": 1
}
},
"query": "\n SELECT\n id,\n workspace_id,\n created_at,\n updated_at,\n deleted_at,\n name,\n url,\n method,\n body,\n body_type,\n headers AS \"headers!: sqlx::types::Json<Vec<HttpRequestHeader>>\"\n FROM http_requests\n WHERE workspace_id = ?\n "
},
"e767522f92c8c49cd2e563e58737a05092daf9b1dc763bacc82a5c14d696d78e": {
"describe": {
"columns": [],
@@ -342,6 +344,16 @@
},
"query": "\n INSERT INTO http_responses (id, request_id, workspace_id, elapsed, url, status, status_reason, body, headers)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);\n "
},
"f0bc12d939b0f26774a3e599be7518510d298f327cca8743231242dd6105768c": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Right": 8
}
},
"query": "\n INSERT INTO http_requests (\n id,\n workspace_id,\n name,\n url,\n method,\n body,\n body_type,\n headers,\n updated_at\n )\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)\n ON CONFLICT (id) DO UPDATE SET\n updated_at = CURRENT_TIMESTAMP,\n name = excluded.name,\n method = excluded.method,\n headers = excluded.headers,\n body = excluded.body,\n body_type = excluded.body_type,\n url = excluded.url\n "
},
"f116d8cf9aad828135bb8c3a4c8b8e6b857ae13303989e9133a33b2d1cf20e96": {
"describe": {
"columns": [],

View File

@@ -8,6 +8,8 @@ windows_subsystem = "windows"
extern crate objc;
use std::collections::HashMap;
use std::env;
use std::env::current_dir;
use std::fs::create_dir_all;
use http::header::{ACCEPT, HeaderName, USER_AGENT};
@@ -202,7 +204,7 @@ async fn create_request(
let pool = &*db_instance.lock().await;
let headers = Vec::new();
let created_request =
models::upsert_request(None, workspace_id, name, "GET", None, "", headers, pool)
models::upsert_request(None, workspace_id, name, "GET", None, None, "", headers, pool)
.await
.expect("Failed to create request");
@@ -237,6 +239,7 @@ async fn update_request(
request.name.as_str(),
request.method.as_str(),
body,
request.body_type,
request.url.as_str(),
request.headers.0,
pool,
@@ -359,7 +362,11 @@ fn main() {
Ok(())
})
.setup(|app| {
let dir = app.path_resolver().app_data_dir().unwrap();
let dir = match is_dev() {
true => current_dir().unwrap(),
false => app.path_resolver().app_data_dir().unwrap(),
};
create_dir_all(dir.clone()).expect("Problem creating App directory!");
let p = dir.join("db.sqlite");
let p_string = p.to_string_lossy().replace(' ', "%20");
@@ -431,3 +438,8 @@ fn main() {
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
fn is_dev() -> bool {
let env = option_env!("YAAK_ENV");
env.unwrap_or("production") == "development"
}

View File

@@ -34,6 +34,7 @@ pub struct HttpRequest {
pub url: String,
pub method: String,
pub body: Option<String>,
pub body_type: Option<String>,
pub headers: Json<Vec<HttpRequestHeader>>,
}
@@ -116,6 +117,7 @@ pub async fn upsert_request(
name: &str,
method: &str,
body: Option<&str>,
body_type: Option<String>,
url: &str,
headers: Vec<HttpRequestHeader>,
pool: &Pool<Sqlite>,
@@ -131,14 +133,25 @@ pub async fn upsert_request(
let headers_json = Json(headers);
sqlx::query!(
r#"
INSERT INTO http_requests (id, workspace_id, name, url, method, body, headers, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
INSERT INTO http_requests (
id,
workspace_id,
name,
url,
method,
body,
body_type,
headers,
updated_at
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
ON CONFLICT (id) DO UPDATE SET
updated_at = CURRENT_TIMESTAMP,
name = excluded.name,
method = excluded.method,
headers = excluded.headers,
body = excluded.body,
body_type = excluded.body_type,
url = excluded.url
"#,
id,
@@ -147,6 +160,7 @@ pub async fn upsert_request(
url,
method,
body,
body_type,
headers_json,
)
.execute(pool)
@@ -162,7 +176,17 @@ pub async fn find_requests(
sqlx::query_as!(
HttpRequest,
r#"
SELECT id, workspace_id, created_at, updated_at, deleted_at, name, url, method, body,
SELECT
id,
workspace_id,
created_at,
updated_at,
deleted_at,
name,
url,
method,
body,
body_type,
headers AS "headers!: sqlx::types::Json<Vec<HttpRequestHeader>>"
FROM http_requests
WHERE workspace_id = ?
@@ -177,7 +201,17 @@ pub async fn get_request(id: &str, pool: &Pool<Sqlite>) -> Result<HttpRequest, s
sqlx::query_as!(
HttpRequest,
r#"
SELECT id, workspace_id, created_at, updated_at, deleted_at, name, url, method, body,
SELECT
id,
workspace_id,
created_at,
updated_at,
deleted_at,
name,
url,
method,
body,
body_type,
headers AS "headers!: sqlx::types::Json<Vec<HttpRequestHeader>>"
FROM http_requests
WHERE id = ?