bitque/jirs-client/src/api.rs

39 lines
1.1 KiB
Rust
Raw Normal View History

2020-03-31 23:49:46 +02:00
use seed::Method;
2020-03-31 22:05:18 +02:00
use jirs_data::UpdateIssuePayload;
2020-03-30 14:26:25 +02:00
use crate::shared::host_client;
use crate::Msg;
pub async fn fetch_current_project(host_url: String) -> Result<Msg, Msg> {
match host_client(host_url, "/project") {
Ok(client) => client.fetch_string(Msg::CurrentProjectResult).await,
Err(e) => Err(Msg::InternalFailure(e)),
}
}
pub async fn fetch_current_user(host_url: String) -> Result<Msg, Msg> {
match host_client(host_url, "/currentUser") {
Ok(client) => client.fetch_string(Msg::CurrentUserResult).await,
Err(e) => Err(Msg::InternalFailure(e)),
}
}
2020-03-31 22:05:18 +02:00
pub async fn update_issue(
host_url: String,
id: i32,
payload: UpdateIssuePayload,
) -> Result<Msg, Msg> {
2020-03-31 23:49:46 +02:00
match host_client(host_url, format!("/issues/{id}", id = id).as_str()) {
2020-03-31 22:05:18 +02:00
Ok(client) => {
client
2020-03-31 23:49:46 +02:00
.method(Method::Put)
.header("Content-Type", "application/json")
2020-03-31 22:05:18 +02:00
.body_json(&payload)
2020-04-02 16:14:07 +02:00
.fetch_string(Msg::IssueUpdateResult)
2020-03-31 22:05:18 +02:00
.await
}
Err(e) => return Ok(Msg::InternalFailure(e)),
}
}