58 lines
1.6 KiB
Rust
58 lines
1.6 KiB
Rust
use crate::check::CheckReportAndVersion;
|
|
use crate::nats_types::CheckMapfixRequest;
|
|
|
|
#[allow(dead_code)]
|
|
#[derive(Debug)]
|
|
pub enum Error{
|
|
Check(crate::check::Error),
|
|
ApiActionMapfixCheck(submissions_api::Error),
|
|
}
|
|
impl std::fmt::Display for Error{
|
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
|
write!(f,"{self:?}")
|
|
}
|
|
}
|
|
impl std::error::Error for Error{}
|
|
|
|
impl crate::message_handler::MessageHandler{
|
|
pub async fn check_mapfix(&self,check_info:CheckMapfixRequest)->Result<(),Error>{
|
|
let mapfix_id=check_info.MapfixID;
|
|
let check_result=self.check_inner(check_info.into()).await;
|
|
|
|
// update the mapfix depending on the result
|
|
match check_result{
|
|
Ok(CheckReportAndVersion{report,version})=>{
|
|
if report.pass(){
|
|
// update the mapfix model status to submitted
|
|
self.api.action_mapfix_submitted(
|
|
submissions_api::types::ActionMapfixSubmittedRequest{
|
|
MapfixID:mapfix_id,
|
|
ModelVersion:version,
|
|
}
|
|
).await.map_err(Error::ApiActionMapfixCheck)?;
|
|
}else{
|
|
// update the mapfix model status to request changes
|
|
self.api.action_mapfix_request_changes(
|
|
submissions_api::types::ActionMapfixRequestChangesRequest{
|
|
MapfixID:mapfix_id,
|
|
ErrorMessage:report.to_string(),
|
|
}
|
|
).await.map_err(Error::ApiActionMapfixCheck)?;
|
|
}
|
|
},
|
|
Err(e)=>{
|
|
// TODO: report the error
|
|
// update the mapfix model status to request changes
|
|
self.api.action_mapfix_request_changes(
|
|
submissions_api::types::ActionMapfixRequestChangesRequest{
|
|
MapfixID:mapfix_id,
|
|
ErrorMessage:e.to_string(),
|
|
}
|
|
).await.map_err(Error::ApiActionMapfixCheck)?;
|
|
},
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}
|