-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add post endpoint to insert documents
- Loading branch information
Showing
6 changed files
with
72 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Mutex<Client>>) -> 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<Mutex<Client>>, | ||
rkh: web::Json<db::collections::logs::Log>, | ||
) -> HttpResponse { | ||
match db::collections::logs::insert(db_connection, rkh.into_inner()).await { | ||
Ok(_) => HttpResponse::Ok().finish(), | ||
Err(_) => HttpResponse::InternalServerError().finish(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Mutex<Client>>) -> 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<Mutex<Client>>, | ||
rkh: web::Json<db::collections::notary::Notary>, | ||
) -> HttpResponse { | ||
match db::collections::notary::insert(db_connection, rkh.into_inner()).await { | ||
Ok(_) => HttpResponse::Ok().finish(), | ||
Err(_) => HttpResponse::InternalServerError().finish(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Mutex<Client>>) -> 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<Mutex<Client>>, | ||
rkh: web::Json<db::collections::rkh::RootKeyHolder>, | ||
) -> HttpResponse { | ||
match db::collections::rkh::insert(db_connection, rkh.into_inner()).await { | ||
Ok(_) => HttpResponse::Ok().finish(), | ||
Err(_) => HttpResponse::InternalServerError().finish(), | ||
} | ||
} |