-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77d5334
commit 0641ac5
Showing
71 changed files
with
441 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pub mod cves; | ||
pub mod health; | ||
pub mod cves; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
use cqrs::domain::command::Command; | ||
|
||
|
||
pub struct CreateCveCommand { | ||
pub id: Option<String>, | ||
pub state: Option<String>, | ||
|
@@ -11,7 +10,12 @@ pub struct CreateCveCommand { | |
impl CreateCveCommand { | ||
pub const COMMAND_TYPE: &'static str = "[email protected]"; | ||
|
||
pub fn new(id: Option<String>, state: Option<String>, date_published: Option<String>, description: Option<String>) -> CreateCveCommand { | ||
pub fn new( | ||
id: Option<String>, | ||
state: Option<String>, | ||
date_published: Option<String>, | ||
description: Option<String>, | ||
) -> CreateCveCommand { | ||
CreateCveCommand { | ||
id, | ||
state, | ||
|
@@ -20,17 +24,27 @@ impl CreateCveCommand { | |
} | ||
} | ||
|
||
pub fn new_boxed(id: Option<String>, state: Option<String>, date_published: Option<String>, description: Option<String>) -> Box<dyn Command> { | ||
Box::new(CreateCveCommand::new(id, state, date_published, description)) | ||
pub fn new_boxed( | ||
id: Option<String>, | ||
state: Option<String>, | ||
date_published: Option<String>, | ||
description: Option<String>, | ||
) -> Box<dyn Command> { | ||
Box::new(CreateCveCommand::new( | ||
id, | ||
state, | ||
date_published, | ||
description, | ||
)) | ||
} | ||
} | ||
|
||
impl Command for CreateCveCommand { | ||
fn command_type(&self) -> String { | ||
CreateCveCommand::COMMAND_TYPE.to_string() | ||
} | ||
|
||
fn as_any(&self) -> &dyn std::any::Any { | ||
self | ||
} | ||
} | ||
} |
41 changes: 26 additions & 15 deletions
41
libs/cti/src/cves/application/create_one/create_cve_command_handler.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,68 @@ | ||
|
||
use async_trait::async_trait; | ||
use cqrs::domain::{command::Command, command_bus_response::CommandBusResponse, command_handler::CommandHandler}; | ||
use cqrs::domain::{ | ||
command::Command, command_bus_response::CommandBusResponse, command_handler::CommandHandler, | ||
}; | ||
use events::domain::event_bus::EventBus; | ||
|
||
use crate::cves::{application::cve_command_response::CveCommandResponse, domain::{entities::{cve_description::CveDescription, cve_id::CveId, cve_publication_date::CvePublicationDate, cve_state::CveState}, repositories::cve_repository::CveRepository}}; | ||
use crate::cves::{ | ||
application::cve_command_response::CveCommandResponse, | ||
domain::{ | ||
entities::{ | ||
cve_description::CveDescription, cve_id::CveId, | ||
cve_publication_date::CvePublicationDate, cve_state::CveState, | ||
}, | ||
repositories::cve_repository::CveRepository, | ||
}, | ||
}; | ||
|
||
use super::{create_cve_command::CreateCveCommand, cve_creator::CveCreator}; | ||
|
||
|
||
pub struct CreateCveCommandHandler<R: CveRepository, E: EventBus> { | ||
creator: CveCreator<R, E>, | ||
} | ||
|
||
impl<R: CveRepository, E: EventBus> CreateCveCommandHandler<R, E> { | ||
impl<R: CveRepository, E: EventBus> CreateCveCommandHandler<R, E> { | ||
pub fn new(creator: CveCreator<R, E>) -> CreateCveCommandHandler<R, E> { | ||
CreateCveCommandHandler { creator } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl <R: CveRepository, E: EventBus> CommandHandler for CreateCveCommandHandler<R, E> { | ||
impl<R: CveRepository, E: EventBus> CommandHandler for CreateCveCommandHandler<R, E> { | ||
async fn handle(&self, command: Box<dyn Command>) -> Box<dyn CommandBusResponse> { | ||
let command = command.as_any().downcast_ref::<CreateCveCommand>().unwrap(); | ||
|
||
let id = match CveId::from_optional(&command.id) { | ||
Ok(id) => id, | ||
Err(err) => return CveCommandResponse::boxed_err(err) | ||
Err(err) => return CveCommandResponse::boxed_err(err), | ||
}; | ||
|
||
let state = match CveState::from_optional(&command.state) { | ||
Ok(state) => state, | ||
Err(err) => return CveCommandResponse::boxed_err(err) | ||
Err(err) => return CveCommandResponse::boxed_err(err), | ||
}; | ||
|
||
let publication_date = match CvePublicationDate::from_optional(&command.date_published) { | ||
Ok(publication_date) => publication_date, | ||
Err(err) => return CveCommandResponse::boxed_err(err) | ||
Err(err) => return CveCommandResponse::boxed_err(err), | ||
}; | ||
|
||
let description = match CveDescription::new(&command.description) { | ||
Ok(description) => description, | ||
Err(err) => return CveCommandResponse::boxed_err(err) | ||
Err(err) => return CveCommandResponse::boxed_err(err), | ||
}; | ||
|
||
match self.creator.run(id, state, publication_date, description).await { | ||
match self | ||
.creator | ||
.run(id, state, publication_date, description) | ||
.await | ||
{ | ||
Ok(_) => CveCommandResponse::boxed_ok(), | ||
Err(err) => CveCommandResponse::boxed_err(err) | ||
Err(err) => CveCommandResponse::boxed_err(err), | ||
} | ||
} | ||
|
||
fn subscribet_to(&self) -> String { | ||
return CreateCveCommand::COMMAND_TYPE.to_string(); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
pub mod create_cve_command; | ||
pub mod create_cve_command_handler; | ||
pub mod cve_creator; | ||
pub mod cve_creator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.