From 186d4076c84eefa630f889de659f5b640fb51e0e Mon Sep 17 00:00:00 2001 From: Jim Crossley Date: Tue, 19 Nov 2024 22:12:51 -0500 Subject: [PATCH] fix: move number_of_packages to SbomHead 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 --- modules/fundamental/src/sbom/model/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/fundamental/src/sbom/model/mod.rs b/modules/fundamental/src/sbom/model/mod.rs index 5fe9f030f..1f4f95bb8 100644 --- a/modules/fundamental/src/sbom/model/mod.rs +++ b/modules/fundamental/src/sbom/model/mod.rs @@ -31,14 +31,18 @@ pub struct SbomHead { pub authors: Vec, 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, - _tx: &ConnectionOrTransaction<'_>, + tx: &ConnectionOrTransaction<'_>, ) -> Result { + 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(), @@ -49,6 +53,7 @@ impl SbomHead { .map(|node| node.name.clone()) .unwrap_or("".to_string()), data_licenses: sbom.data_licenses.clone(), + number_of_packages, }) } } @@ -62,9 +67,6 @@ pub struct SbomSummary { pub source_document: Option, pub described_by: Vec, - - /// The number of packages this SBOM has - pub number_of_packages: u64, } impl SbomSummary { @@ -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 { @@ -91,7 +92,6 @@ impl SbomSummary { None }, described_by, - number_of_packages, }), None => None, })