49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
use crate::nats_types::ValidateMapfixRequest;
|
|
|
|
#[allow(dead_code)]
|
|
#[derive(Debug)]
|
|
pub enum Error{
|
|
ApiActionMapfixValidate(tonic::Status),
|
|
}
|
|
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 validate_mapfix(&self,validate_info:ValidateMapfixRequest)->Result<(),Error>{
|
|
let mapfix_id=validate_info.MapfixID;
|
|
let validate_result=self.validate_inner(validate_info.into()).await;
|
|
|
|
// update the mapfix depending on the result
|
|
match &validate_result{
|
|
Ok(())=>{
|
|
// update the mapfix model status to validated
|
|
self.mapfixes.set_status_validated(rust_grpc::validator::MapfixId{
|
|
id:mapfix_id,
|
|
}).await.map_err(Error::ApiActionMapfixValidate)?;
|
|
},
|
|
Err(e)=>{
|
|
// log error
|
|
println!("[validate_mapfix] Error: {e}");
|
|
|
|
self.mapfixes.create_audit_error(
|
|
rust_grpc::validator::AuditErrorRequest{
|
|
id:mapfix_id,
|
|
error_message:e.to_string(),
|
|
}
|
|
).await.map_err(Error::ApiActionMapfixValidate)?;
|
|
|
|
// update the mapfix model status to accepted
|
|
self.mapfixes.set_status_not_validated(rust_grpc::validator::MapfixId{
|
|
id:mapfix_id,
|
|
}).await.map_err(Error::ApiActionMapfixValidate)?;
|
|
},
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}
|