Skip to content
Snippets Groups Projects
Verified Commit 83763a5e authored by Korben Tompkin's avatar Korben Tompkin :mortar_board:
Browse files

feat(server): init working

parent fad12d49
No related branches found
No related tags found
1 merge request!3feat(server): Server implementation
......@@ -3,4 +3,7 @@
static/syn*
static/venv
venv
\ No newline at end of file
venv
*.json
*.log
This diff is collapsed.
......@@ -7,4 +7,5 @@ edition = "2021"
axum = "0.8.1"
serde = "1.0.217"
serde_json = "1.0.138"
sqlx = { version = "0.8.3", features = ["runtime-tokio"] }
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
......@@ -9,6 +9,11 @@ use serde_json::{json, Value};
use std::{collections::HashMap, fs};
use tokio;
#[derive(Serialize, Deserialize)]
struct ED {
db: HashMap<String, String>,
}
#[tokio::main]
async fn main() {
let app = Router::new()
......@@ -22,18 +27,23 @@ async fn main() {
}
async fn init(Json(payload): Json<Value>) -> Result<(), StatusCode> {
match payload.as_str() {
Some(db) => {
if let Ok(_) = fs::write("./db/database.json", db) {
Ok(())
} else {
Err(StatusCode::INTERNAL_SERVER_ERROR)
}
match fs::write("./db.json", payload.to_string()) {
Ok(_) => Ok(()),
Err(x) => {
println!("{:#?}", x);
Err(StatusCode::INTERNAL_SERVER_ERROR)
}
None => Err(StatusCode::INTERNAL_SERVER_ERROR),
}
}
async fn search(Path(query): Path<String>) -> Result<Json<Value>, StatusCode> {
let data_string = match fs::read_to_string("./db.json") {
Ok(x) => x,
Err(_) => String::from(""),
};
let ed: ED = ED {
db: serde_json::from_str(&data_string).unwrap(),
};
println!("{:#?}", ed.db);
Ok(Json(json!({query: ""})))
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment