-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactored http calls to
request
fxn
- Loading branch information
1 parent
aacf7e6
commit a2c8133
Showing
12 changed files
with
281 additions
and
108 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 10 additions & 21 deletions
31
crates/frontend/src/components/default_config_form/utils.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,20 @@ | ||
use super::types::DefaultConfigCreateReq; | ||
use crate::utils::get_host; | ||
use reqwest::StatusCode; | ||
use crate::utils::{get_host, request}; | ||
|
||
pub async fn create_default_config( | ||
key: String, | ||
tenant: String, | ||
payload: DefaultConfigCreateReq, | ||
) -> Result<String, String> { | ||
let client = reqwest::Client::new(); | ||
) -> Result<serde_json::Value, String> { | ||
let host = get_host(); | ||
let url = format!("{host}/default-config/{key}"); | ||
|
||
let response = client | ||
.put(url) | ||
.header("x-tenant", tenant) | ||
.json(&payload) | ||
.send() | ||
.await | ||
.map_err(|e| e.to_string())?; | ||
match response.status() { | ||
StatusCode::OK | StatusCode::CREATED => { | ||
response.text().await.map_err(|e| e.to_string()) | ||
} | ||
StatusCode::BAD_REQUEST => Err(response | ||
.text() | ||
.await | ||
.unwrap_or("Validation of configuration value failed, but the error could not be understood by the system. Contact an admin for help if this persists".to_string())), | ||
_ => Err("Internal Server Error".to_string()), | ||
} | ||
request( | ||
url, | ||
reqwest::Method::PUT, | ||
Some(payload), | ||
&[("x-tenant", &tenant)], | ||
) | ||
.await | ||
.map_err(|err| err.to_string()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,22 @@ | ||
use super::types::DimensionCreateReq; | ||
use crate::utils::get_host; | ||
use reqwest::StatusCode; | ||
use crate::{ | ||
types::Dimension, | ||
utils::{get_host, request}, | ||
}; | ||
|
||
pub async fn create_dimension( | ||
tenant: String, | ||
payload: DimensionCreateReq, | ||
) -> Result<String, String> { | ||
let client = reqwest::Client::new(); | ||
) -> Result<Dimension, String> { | ||
let host = get_host(); | ||
let url = format!("{host}/dimension"); | ||
|
||
let response = client | ||
.put(url) | ||
.header("x-tenant", tenant) | ||
.json(&payload) | ||
.send() | ||
.await | ||
.map_err(|e| e.to_string())?; | ||
match response.status() { | ||
StatusCode::OK => response.text().await.map_err(|e| e.to_string()), | ||
StatusCode::CREATED => response.text().await.map_err(|e| e.to_string()), | ||
StatusCode::BAD_REQUEST => Err("Schema Validation Failed".to_string()), | ||
_ => Err("Internal Server Error".to_string()), | ||
} | ||
request( | ||
url, | ||
reqwest::Method::PUT, | ||
Some(payload), | ||
&[("x-tenant", &tenant)], | ||
) | ||
.await | ||
.map_err(|err| err.to_string()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.