Skip to content

Commit

Permalink
fix: move number_of_packages to SbomHead
Browse files Browse the repository at this point in the history
Fixes #1006 by making the sbom #packages available in
/api/v1/vulnerability/{id} as well as /api/v1/sbom/{id}

Signed-off-by: Jim Crossley <[email protected]>
  • Loading branch information
jcrossley3 committed Nov 21, 2024
1 parent 81f0c12 commit 186d407
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions modules/fundamental/src/sbom/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ pub struct SbomHead {
pub authors: Vec<String>,

pub name: String,

/// The number of packages this SBOM has
pub number_of_packages: u64,
}

impl SbomHead {
pub async fn from_entity(
sbom: &sbom::Model,
sbom_node: Option<sbom_node::Model>,
_tx: &ConnectionOrTransaction<'_>,
tx: &ConnectionOrTransaction<'_>,
) -> Result<Self, Error> {
let number_of_packages = sbom.find_related(sbom_package::Entity).count(tx).await?;
Ok(Self {
id: sbom.sbom_id,
document_id: sbom.document_id.clone(),
Expand All @@ -49,6 +53,7 @@ impl SbomHead {
.map(|node| node.name.clone())
.unwrap_or("".to_string()),
data_licenses: sbom.data_licenses.clone(),
number_of_packages,
})
}
}
Expand All @@ -62,9 +67,6 @@ pub struct SbomSummary {
pub source_document: Option<SourceDocument>,

pub described_by: Vec<SbomPackage>,

/// The number of packages this SBOM has
pub number_of_packages: u64,
}

impl SbomSummary {
Expand All @@ -80,7 +82,6 @@ impl SbomSummary {
.items;

let source_document = sbom.find_related(source_document::Entity).one(tx).await?;
let number_of_packages = sbom.find_related(sbom_package::Entity).count(tx).await?;

Ok(match node {
Some(_) => Some(SbomSummary {
Expand All @@ -91,7 +92,6 @@ impl SbomSummary {
None
},
described_by,
number_of_packages,
}),
None => None,
})
Expand Down

0 comments on commit 186d407

Please sign in to comment.