From b7d04da9e08dbd7740f9e0fe9c8a92e6dcce3032 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 6 Dec 2024 19:19:01 -0800 Subject: [PATCH] rust api: implement update_submission_model --- validation/api/src/lib.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/validation/api/src/lib.rs b/validation/api/src/lib.rs index 88e16e3..a9fb26e 100644 --- a/validation/api/src/lib.rs +++ b/validation/api/src/lib.rs @@ -48,6 +48,13 @@ pub struct ScriptPolicyResponse{ pub Policy:Policy } +#[allow(nonstandard_style)] +pub struct UpdateSubmissionModelRequest{ + pub ID:i64, + pub ModelID:u64, + pub ModelVersion:u64, +} + #[derive(Clone)] pub struct Context{ base_url:String, @@ -77,9 +84,8 @@ impl Context{ self.client.get(url) .send().await } - async fn patch(&self,url:impl reqwest::IntoUrl,body:impl Into)->Result{ + async fn patch(&self,url:impl reqwest::IntoUrl)->Result{ self.client.patch(url) - .body(body) .send().await } pub async fn get_script(&self,config:GetScriptRequest)->Result{ @@ -98,4 +104,19 @@ impl Context{ .error_for_status().map_err(GetError::Reqwest)? .json().await.map_err(GetError::Reqwest) } + pub async fn update_submission_model(&self,config:UpdateSubmissionModelRequest)->Result<(),GetError>{ + let url_raw=format!("{}/submissions/{}/model",self.base_url,config.ID); + let mut url=reqwest::Url::parse(url_raw.as_str()).map_err(GetError::ParseError)?; + + { + url.query_pairs_mut() + .append_pair("ModelID",config.ModelID.to_string().as_str()) + .append_pair("ModelVersion",config.ModelVersion.to_string().as_str()); + } + + self.patch(url).await.map_err(GetError::Reqwest)? + .error_for_status().map_err(GetError::Reqwest)?; + + Ok(()) + } }