Skip to content

Commit f541338

Browse files
committed
fix(backend): align axum responses and report build
1 parent c7414eb commit f541338

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

apps/backend/src/app/scan.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub enum ScanError {
1212
ScanFailed(String),
1313
}
1414

15+
#[derive(Clone, Copy)]
1516
pub struct ScanService;
1617

1718
impl ScanService {
@@ -38,7 +39,7 @@ impl ScanService {
3839
.run(bundle_path)
3940
.map_err(|err| ScanError::ScanFailed(err.to_string()))?;
4041

41-
let report = build_report(&run, None);
42+
let report = build_report(run.results, run.total_duration_ms, run.cache_stats);
4243
Ok(ScanResponse {
4344
report,
4445
warnings: vec![format!(

apps/backend/src/domain/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use serde::{Deserialize, Serialize};
2+
use verifyos_cli::report::ReportData;
23

34
#[derive(Debug, Deserialize)]
45
#[serde(rename_all = "snake_case")]
@@ -14,6 +15,6 @@ pub struct ScanRequest {
1415

1516
#[derive(Debug, Serialize)]
1617
pub struct ScanResponse {
17-
pub report: serde_json::Value,
18+
pub report: ReportData,
1819
pub warnings: Vec<String>,
1920
}

apps/backend/src/infra/http/handlers.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::domain::{ScanProfileInput, ScanRequest};
33
use axum::extract::{Multipart, State};
44
use axum::http::StatusCode;
55
use axum::response::IntoResponse;
6+
use axum::Json;
67
use serde_json::json;
78
use std::io::Write;
89
use tempfile::NamedTempFile;
@@ -51,26 +52,25 @@ pub async fn scan_bundle(
5152
let Some(bundle) = temp_file else {
5253
return (
5354
StatusCode::BAD_REQUEST,
54-
json!({ "error": "missing bundle file field" }),
55+
Json(json!({ "error": "missing bundle file field" })),
5556
)
5657
.into_response();
5758
};
5859

5960
info!("running scan for uploaded bundle");
6061
match service.run_scan(request, bundle.path()) {
61-
Ok(result) => (
62-
StatusCode::OK,
63-
serde_json::to_value(result).unwrap_or_default(),
64-
)
65-
.into_response(),
66-
Err(err) => (StatusCode::BAD_REQUEST, error_body(err)).into_response(),
62+
Ok(result) => (StatusCode::OK, Json(result)).into_response(),
63+
Err(err) => (StatusCode::BAD_REQUEST, Json(error_body(err))).into_response(),
6764
}
6865
}
6966

7067
fn error_body(err: ScanError) -> serde_json::Value {
7168
json!({ "error": err.to_string() })
7269
}
7370

74-
fn to_error(err: impl std::fmt::Display) -> (StatusCode, serde_json::Value) {
75-
(StatusCode::BAD_REQUEST, json!({ "error": err.to_string() }))
71+
fn to_error(err: impl std::fmt::Display) -> (StatusCode, Json<serde_json::Value>) {
72+
(
73+
StatusCode::BAD_REQUEST,
74+
Json(json!({ "error": err.to_string() })),
75+
)
7676
}

0 commit comments

Comments
 (0)