diff --git a/src/core.rs b/src/core.rs index d0a0343..a0fa1a3 100644 --- a/src/core.rs +++ b/src/core.rs @@ -37,6 +37,30 @@ impl Core { self.get_collection(&self.apps).await } + pub async fn get_app(&self, name: &String) -> serde_json::Value { + let response = self.apps.find_one(doc! {"name_id":&name}, None).await; + match response { + Ok(response) => match response { + Some(result) => json!({ + "code":"ok_body", + "body": result + }), + None => { + json! ({ + "code":"denied", + "msg":"This app does not exist" + }) + } + }, + Err(_) => { + json! ({ + "code":"err", + "msg":"Unknown error" + }) + } + } + } + pub async fn write_review(&self, name: &String, info: &Json) -> serde_json::Value { let options = FindOneOptions::builder() .projection(doc! {"_id" : 1}) diff --git a/src/main.rs b/src/main.rs index 73fe45c..35527c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,6 +81,7 @@ async fn main() -> std::io::Result<()> { web::scope("/api") .wrap(HttpAuthentication::bearer(jwt_validator)) .service(routes::apps) + .service(routes::app) .service(routes::update) .service(routes::change_password) .service(routes::write_review), diff --git a/src/routes.rs b/src/routes.rs index fb2d0f7..a78b6bf 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -30,6 +30,12 @@ pub async fn reviews( HttpResponse::Ok().json(app_data.core.get_reviews(&app_name_id).await) } +#[get("/app/{name}")] +#[has_any_permission("user", "admin")] +pub async fn app(app_data: web::Data, name: web::Path) -> impl Responder { + response(app_data.core.get_app(&name).await) +} + #[post("/change_password")] #[has_any_permission("user", "admin")] pub async fn change_password( @@ -81,3 +87,6 @@ fn response(result: serde_json::Value) -> impl Responder { HttpResponse::InternalServerError().json(result) } } + +//req: HttpRequest +//secure = "username(req)==user.name"