Skip to content

Commit

Permalink
add sample entity
Browse files Browse the repository at this point in the history
  • Loading branch information
n1nj4t4nuk1 committed Nov 28, 2024
1 parent f81cb4b commit c6dcc3f
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libs/cti/src/cves/domain/entities/cve.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use super::{cve_description::CveDescription, cve_id::CveId, cve_publication_date::CvePublicationDate, cve_state::CveState};


pub struct Cve {
pub id: CveId,
pub state: CveState,
pub date_published: CvePublicationDate,

pub description: CveDescription,
}
37 changes: 37 additions & 0 deletions libs/cti/src/cves/domain/entities/cve_description.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::shared::domain::errors::DomainError;
use std::hash::{Hash, Hasher};

#[derive(Debug)]
pub struct CveDescription {
value: String,
}

impl CveDescription {
pub fn new(value: String) -> Result<Self, DomainError> {
Ok(Self { value })
}

pub fn value(&self) -> String {
self.value.clone()
}
}

impl Clone for CveDescription {
fn clone(&self) -> Self {
Self::new(self.value.clone()).unwrap()
}
}

impl PartialEq for CveDescription {
fn eq(&self, other: &Self) -> bool {
self.value() == other.value()
}
}

impl Eq for CveDescription {}

impl Hash for CveDescription {
fn hash<H: Hasher>(&self, state: &mut H) {
self.value.hash(state);
}
}
40 changes: 40 additions & 0 deletions libs/cti/src/cves/domain/entities/cve_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use crate::shared::domain::errors::DomainError;
use std::hash::{Hash, Hasher};

#[derive(Debug)]
pub struct CveId {
value: String,
}

impl CveId {
pub fn new(id: String) -> Result<Self, DomainError> {
if id.contains(" ") {
return Err(DomainError::ValueObjectError { value: "CVE id must not contain blank spaces".to_string() })
}
Ok(Self { value: id })
}

pub fn value(&self) -> String {
self.value.clone()
}
}

impl Clone for CveId {
fn clone(&self) -> Self {
Self::new(self.value.clone()).unwrap()
}
}

impl PartialEq for CveId {
fn eq(&self, other: &Self) -> bool {
self.value() == other.value()
}
}

impl Eq for CveId {}

impl Hash for CveId {
fn hash<H: Hasher>(&self, state: &mut H) {
self.value.hash(state);
}
}
37 changes: 37 additions & 0 deletions libs/cti/src/cves/domain/entities/cve_publication_date.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::shared::domain::errors::DomainError;
use std::hash::{Hash, Hasher};

#[derive(Debug)]
pub struct CvePublicationDate {
value: String,
}

impl CvePublicationDate {
pub fn new(value: String) -> Result<Self, DomainError> {
Ok(Self { value })
}

pub fn value(&self) -> String {
self.value.clone()
}
}

impl Clone for CvePublicationDate {
fn clone(&self) -> Self {
Self::new(self.value.clone()).unwrap()
}
}

impl PartialEq for CvePublicationDate {
fn eq(&self, other: &Self) -> bool {
self.value() == other.value()
}
}

impl Eq for CvePublicationDate {}

impl Hash for CvePublicationDate {
fn hash<H: Hasher>(&self, state: &mut H) {
self.value.hash(state);
}
}
37 changes: 37 additions & 0 deletions libs/cti/src/cves/domain/entities/cve_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::shared::domain::errors::DomainError;
use std::hash::{Hash, Hasher};

#[derive(Debug)]
pub struct CveState {
value: String,
}

impl CveState {
pub fn new(value: String) -> Result<Self, DomainError> {
Ok(Self { value })
}

pub fn value(&self) -> String {
self.value.clone()
}
}

impl Clone for CveState {
fn clone(&self) -> Self {
Self::new(self.value.clone()).unwrap()
}
}

impl PartialEq for CveState {
fn eq(&self, other: &Self) -> bool {
self.value() == other.value()
}
}

impl Eq for CveState {}

impl Hash for CveState {
fn hash<H: Hasher>(&self, state: &mut H) {
self.value.hash(state);
}
}
5 changes: 5 additions & 0 deletions libs/cti/src/cves/domain/entities/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub mod cve;
pub mod cve_description;
pub mod cve_id;
pub mod cve_state;
pub mod cve_publication_date;
1 change: 1 addition & 0 deletions libs/cti/src/cves/domain/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod entities;
1 change: 1 addition & 0 deletions libs/cti/src/cves/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod domain;
1 change: 1 addition & 0 deletions libs/cti/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod cves;

0 comments on commit c6dcc3f

Please sign in to comment.