validator: implement create operations
This commit is contained in:
42
validation/src/create_submission.rs
Normal file
42
validation/src/create_submission.rs
Normal file
@ -0,0 +1,42 @@
|
||||
use crate::nats_types::CreateSubmissionRequest;
|
||||
use crate::create::CreateRequest;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub enum Error{
|
||||
ApiActionSubmissionCreate(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 create_submission(&self,create_info:CreateSubmissionRequest)->Result<(),Error>{
|
||||
let create_result=self.create_inner(CreateRequest{
|
||||
ModelID:create_info.ModelID,
|
||||
}).await;
|
||||
|
||||
match create_result{
|
||||
Ok(create_request)=>{
|
||||
// call create on api
|
||||
self.api.create_submission(submissions_api::types::CreateSubmissionRequest{
|
||||
OperationID:create_info.OperationID,
|
||||
AssetOwner:create_request.AssetOwner,
|
||||
DisplayName:create_request.DisplayName.as_str(),
|
||||
Creator:create_request.Creator.as_str(),
|
||||
GameID:create_request.GameID,
|
||||
AssetID:create_info.ModelID,
|
||||
AssetVersion:create_request.AssetVersion,
|
||||
}).await.map_err(Error::ApiActionSubmissionCreate)?;
|
||||
},
|
||||
Err(e)=>{
|
||||
println!("oh no! {e}");
|
||||
},
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user