Persist sort priority!

This commit is contained in:
Gregory Schier
2023-03-19 00:48:09 -07:00
parent 9ac5572094
commit b586318d4b
17 changed files with 457 additions and 243 deletions

View File

@@ -247,13 +247,14 @@ async fn create_workspace(
async fn create_request(
workspace_id: &str,
name: &str,
sort_priority: f64,
app_handle: AppHandle<Wry>,
db_instance: State<'_, Mutex<Pool<Sqlite>>>,
) -> Result<String, String> {
let pool = &*db_instance.lock().await;
let headers = Vec::new();
let created_request =
models::upsert_request(None, workspace_id, name, "GET", None, None, "", headers, pool)
models::upsert_request(None, workspace_id, name, "GET", None, None, "", headers, sort_priority, pool)
.await
.expect("Failed to create request");
@@ -291,6 +292,7 @@ async fn update_request(
request.body_type,
request.url.as_str(),
request.headers.0,
request.sort_priority,
pool,
)
.await

View File

@@ -29,6 +29,7 @@ pub struct HttpRequest {
pub model: String,
pub created_at: NaiveDateTime,
pub updated_at: NaiveDateTime,
pub sort_priority: f64,
pub workspace_id: String,
pub name: String,
pub url: String,
@@ -170,6 +171,7 @@ pub async fn upsert_request(
body_type: Option<String>,
url: &str,
headers: Vec<HttpRequestHeader>,
sort_priority: f64,
pool: &Pool<Sqlite>,
) -> Result<HttpRequest, sqlx::Error> {
let generated_id;
@@ -191,9 +193,10 @@ pub async fn upsert_request(
method,
body,
body_type,
headers
headers,
sort_priority
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT (id) DO UPDATE SET
updated_at = CURRENT_TIMESTAMP,
name = excluded.name,
@@ -201,7 +204,8 @@ pub async fn upsert_request(
headers = excluded.headers,
body = excluded.body,
body_type = excluded.body_type,
url = excluded.url
url = excluded.url,
sort_priority = excluded.sort_priority
"#,
id,
workspace_id,
@@ -211,6 +215,7 @@ pub async fn upsert_request(
body,
body_type,
headers_json,
sort_priority,
)
.execute(pool)
.await
@@ -236,6 +241,7 @@ pub async fn find_requests(
method,
body,
body_type,
sort_priority,
headers AS "headers!: sqlx::types::Json<Vec<HttpRequestHeader>>"
FROM http_requests
WHERE workspace_id = ?
@@ -261,6 +267,7 @@ pub async fn get_request(id: &str, pool: &Pool<Sqlite>) -> Result<HttpRequest, s
method,
body,
body_type,
sort_priority,
headers AS "headers!: sqlx::types::Json<Vec<HttpRequestHeader>>"
FROM http_requests
WHERE id = ?