diff --git a/http-server/src/db/collections/logs.rs b/http-server/src/db/collections/logs.rs index c5d491be..bbef70db 100644 --- a/http-server/src/db/collections/logs.rs +++ b/http-server/src/db/collections/logs.rs @@ -31,3 +31,9 @@ pub async fn find(state: web::Data>) -> Result> { } Ok(ret) } + +pub async fn insert(state: web::Data>, log: Log) -> Result<()> { + let log_collection: Collection = get_collection(state, COLLECTION_NAME).await?; + log_collection.insert_one(log, None).await?; + Ok(()) +} diff --git a/http-server/src/db/collections/notary.rs b/http-server/src/db/collections/notary.rs index d88b2857..e4d6d5ec 100644 --- a/http-server/src/db/collections/notary.rs +++ b/http-server/src/db/collections/notary.rs @@ -32,3 +32,9 @@ pub async fn find(state: web::Data>) -> Result> { } Ok(ret) } + +pub async fn insert(state: web::Data>, notary: Notary) -> Result<()> { + let notary_collection: Collection = get_collection(state, COLLECTION_NAME).await?; + notary_collection.insert_one(notary, None).await?; + Ok(()) +} diff --git a/http-server/src/db/collections/rkh.rs b/http-server/src/db/collections/rkh.rs index 14616228..361f45bc 100644 --- a/http-server/src/db/collections/rkh.rs +++ b/http-server/src/db/collections/rkh.rs @@ -30,3 +30,9 @@ pub async fn find(state: web::Data>) -> Result> } Ok(ret) } + +pub async fn insert(state: web::Data>, rkh: RootKeyHolder) -> Result<()> { + let rkh_collection: Collection = get_collection(state, COLLECTION_NAME).await?; + rkh_collection.insert_one(rkh, None).await?; + Ok(()) +} diff --git a/http-server/src/router/logs.rs b/http-server/src/router/logs.rs index f0b584fc..a8fb330a 100644 --- a/http-server/src/router/logs.rs +++ b/http-server/src/router/logs.rs @@ -1,17 +1,25 @@ use crate::db; -use actix_web::{get, http::header::ContentType, web, HttpResponse}; +use actix_web::{get, http::header::ContentType, web, HttpResponse, post}; use mongodb::Client; use std::sync::Mutex; #[get("/logs")] pub async fn get(db_connection: web::Data>) -> HttpResponse { - let items = match db::collections::logs::find(db_connection).await { - Ok(items) => items, - Err(_) => { - return HttpResponse::InternalServerError().finish(); - } - }; - return HttpResponse::Ok() - .content_type(ContentType::json()) - .body(serde_json::to_string(&items).unwrap()); + match db::collections::logs::find(db_connection).await { + Ok(i) => HttpResponse::Ok() + .content_type(ContentType::json()) + .body(serde_json::to_string(&i).unwrap()), + Err(_) => HttpResponse::InternalServerError().finish(), + } +} + +#[post("/logs")] +pub async fn post( + db_connection: web::Data>, + rkh: web::Json, +) -> HttpResponse { + match db::collections::logs::insert(db_connection, rkh.into_inner()).await { + Ok(_) => HttpResponse::Ok().finish(), + Err(_) => HttpResponse::InternalServerError().finish(), + } } diff --git a/http-server/src/router/notary.rs b/http-server/src/router/notary.rs index 9d4c5481..c618eb21 100644 --- a/http-server/src/router/notary.rs +++ b/http-server/src/router/notary.rs @@ -1,17 +1,25 @@ use crate::db; -use actix_web::{get, http::header::ContentType, web, HttpResponse}; +use actix_web::{get, http::header::ContentType, web, HttpResponse, post}; use mongodb::Client; use std::sync::Mutex; #[get("/notary")] pub async fn get(db_connection: web::Data>) -> HttpResponse { - let items = match db::collections::notary::find(db_connection).await { - Ok(items) => items, - Err(_) => { - return HttpResponse::InternalServerError().finish(); - } - }; - return HttpResponse::Ok() - .content_type(ContentType::json()) - .body(serde_json::to_string(&items).unwrap()); + match db::collections::notary::find(db_connection).await { + Ok(i) => HttpResponse::Ok() + .content_type(ContentType::json()) + .body(serde_json::to_string(&i).unwrap()), + Err(_) => HttpResponse::InternalServerError().finish(), + } +} + +#[post("/notary")] +pub async fn post( + db_connection: web::Data>, + rkh: web::Json, +) -> HttpResponse { + match db::collections::notary::insert(db_connection, rkh.into_inner()).await { + Ok(_) => HttpResponse::Ok().finish(), + Err(_) => HttpResponse::InternalServerError().finish(), + } } diff --git a/http-server/src/router/rkh.rs b/http-server/src/router/rkh.rs index 2e96e272..1559a960 100644 --- a/http-server/src/router/rkh.rs +++ b/http-server/src/router/rkh.rs @@ -1,17 +1,25 @@ use crate::db; -use actix_web::{get, http::header::ContentType, web, HttpResponse}; +use actix_web::{get, http::header::ContentType, web, HttpResponse, post}; use mongodb::Client; use std::sync::Mutex; #[get("/rkh")] pub async fn get(db_connection: web::Data>) -> HttpResponse { - let items = match db::collections::rkh::find(db_connection).await { - Ok(items) => items, - Err(_) => { - return HttpResponse::InternalServerError().finish(); - } - }; - return HttpResponse::Ok() - .content_type(ContentType::json()) - .body(serde_json::to_string(&items).unwrap()); + match db::collections::rkh::find(db_connection).await { + Ok(i) => HttpResponse::Ok() + .content_type(ContentType::json()) + .body(serde_json::to_string(&i).unwrap()), + Err(_) => HttpResponse::InternalServerError().finish(), + } +} + +#[post("/rkh")] +pub async fn post( + db_connection: web::Data>, + rkh: web::Json, +) -> HttpResponse { + match db::collections::rkh::insert(db_connection, rkh.into_inner()).await { + Ok(_) => HttpResponse::Ok().finish(), + Err(_) => HttpResponse::InternalServerError().finish(), + } }