-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rs
More file actions
68 lines (60 loc) · 1.87 KB
/
Copy pathapp.rs
File metadata and controls
68 lines (60 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
use crate::lattice::affine;
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
use serde::{Deserialize, Serialize};
#[derive(Deserialize)]
pub struct BuildRequest {
pub repo: String,
pub db: String,
}
#[derive(Deserialize)]
pub struct QueryRequest {
pub zoom: String,
pub db: String,
}
#[derive(Serialize)]
pub struct ApiResponse {
pub status: String,
pub message: String,
}
#[post("/build")]
async fn build_lattice(req: web::Json<BuildRequest>) -> impl Responder {
let lattice = crate::ingest::from_path(&req.repo);
let cond = lattice.condense();
HttpResponse::Ok().json(serde_json::json!({
"status": "success",
"repo": req.repo,
"nodes": lattice.len(),
"edges": lattice.edges().len(),
"components": cond.num_components,
"acyclic": cond.is_acyclic(),
}))
}
#[get("/zoom/{node_id}")]
async fn zoom_node(path: web::Path<String>, query: web::Query<QueryRequest>) -> impl Responder {
let node_id = path.into_inner();
println!("🔍 API: Zooming into node: {}", node_id);
affine::query_lattice(&node_id, &query.db);
HttpResponse::Ok().json(ApiResponse {
status: "success".to_string(),
message: format!("Zoomed into node {}", node_id),
})
}
#[get("/health")]
async fn health() -> impl Responder {
HttpResponse::Ok().body("Git-Reticulator API is healthy.")
}
pub async fn start_server(db_uri: String) -> std::io::Result<()> {
println!("🌐 Git-Reticulator API starting on http://localhost:8080");
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(db_uri.clone()))
.service(build_lattice)
.service(zoom_node)
.service(health)
})
.bind(("127.0.0.1", 8080))?
.run()
.await
}