use serde_json::json;
use crate::{Rub, Rujira};
use super::{Method, Rq, REST_BASE};
pub fn create(bot: Rujira, fields: serde_json::Value, update_history: bool) -> Rq {
Rq::new(bot)
.uri(&format!("{}/issue", REST_BASE))
.method(Method::POST)
.add_payload("fields", fields)
.add_params(vec![("updateHistory", update_history.to_static())])
}
pub fn edit(
bot: Rujira,
id_or_key: &str,
update: Option<serde_json::Value>,
fields: Option<serde_json::Value>,
notify_users: Option<bool>,
) -> Rq {
Rq::new(bot)
.uri(&format!("{}/issue/{id_or_key}", REST_BASE))
.method(Method::PUT)
.add_payload("update", update.unwrap_or(json!({})))
.add_payload("fields", fields.unwrap_or(json!({})))
.add_params(vec![(
"notifyUsers",
notify_users.unwrap_or(true).to_static(),
)])
}
pub fn get(
bot: Rujira,
id_or_key: &str,
fields: Option<&str>,
expand: Option<&str>,
properties: Option<&str>,
update_history: Option<bool>,
) -> Rq {
Rq::new(bot)
.uri(&format!("{}/issue/{id_or_key}", REST_BASE))
.method(Method::GET)
.apply_if(fields, |r, v| r.add_params(vec![("fields", v)]))
.apply_if(expand, |r, v| r.add_params(vec![("expand", v)]))
.apply_if(properties, |r, v| r.add_params(vec![("properties", v)]))
.add_params(vec![(
"updateHistory",
update_history.unwrap_or(false).to_static(),
)])
}
pub fn delete(bot: Rujira, id_or_key: &str, delete_subtasks: Option<&str>) -> Rq {
Rq::new(bot)
.uri(&format!("{}/issue/{id_or_key}", REST_BASE))
.method(Method::DELETE)
.apply_if(delete_subtasks, |r, v| {
r.add_params(vec![("deleteSubtasks", v)])
})
}