This commit is contained in:
lukas-heilgenbrunner 2024-05-24 13:09:17 +02:00
commit e589e974db
6 changed files with 2278 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

2176
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

13
Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[package]
name = "graphdbhue3"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
neo4rs = "0.7.1"
tokio = "1.37.0"
rocket = "0.5.0"
rocket_okapi = { version = "0.8.0", features = ["swagger"] }
anyhow = "1.0.76"

21
src/backend/backend.rs Normal file
View File

@ -0,0 +1,21 @@
use neo4rs::Graph;
use rocket::{get, Route, State};
use rocket::response::status::NotFound;
use rocket_okapi::{openapi, openapi_get_routes};
use rocket::serde::json::Json;
pub fn build_api() -> Vec<Route> {
openapi_get_routes![
append
]
}
/// get general build-server stats
#[openapi(tag = "stats")]
#[get("/append")]
pub async fn append(graph: &State<Graph>) -> Result<String, NotFound<String>> {
let graph = graph as &Graph;
Ok("worked".to_string())
}

1
src/backend/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod backend;

66
src/main.rs Normal file
View File

@ -0,0 +1,66 @@
use neo4rs::{Graph, Node, query};
use rocket::Config;
use rocket_okapi::swagger_ui::{make_swagger_ui, SwaggerUIConfig};
use crate::backend::backend::build_api;
mod backend;
fn main() {
println!("Hello, world!");
let t = tokio::runtime::Runtime::new().unwrap();
let tt = Box::new("hello".to_string());
let iii = 1;
for i in 1..5 {
if tt == "hello" {
println!("{tt}");
} else {
println!("not");
}
}
println!("{tt}");
t.block_on(async move {
// concurrent queries
let uri: String = "127.0.0.1:7687".to_string();
let user = "neo4j";
let pass = "neo";
let graph = Graph::new(uri, user, pass).await.unwrap();
//println!("{uri}");
let config = Config {
address: "0.0.0.0".parse().unwrap(),
port: 8081,
..Default::default()
};
let rock = rocket::custom(config)
.manage(graph)
.mount("/api/", build_api())
.mount(
"/docs/",
make_swagger_ui(&SwaggerUIConfig {
url: "../api/openapi.json".to_owned(),
..Default::default()
}),
);
let rock = rock.launch().await;
match rock {
Ok(_) => println!("Rocket shut down gracefully."),
Err(err) => println!("Rocket had an error: {}", err),
};
});
}