feat: get app (OS-23)

This commit is contained in:
Artemy 2022-07-26 20:39:37 +03:00
parent 699f84e440
commit 915d8a6321
3 changed files with 34 additions and 0 deletions

View file

@ -37,6 +37,30 @@ impl Core {
self.get_collection(&self.apps).await 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<ReviewData>) -> serde_json::Value { pub async fn write_review(&self, name: &String, info: &Json<ReviewData>) -> serde_json::Value {
let options = FindOneOptions::builder() let options = FindOneOptions::builder()
.projection(doc! {"_id" : 1}) .projection(doc! {"_id" : 1})

View file

@ -81,6 +81,7 @@ async fn main() -> std::io::Result<()> {
web::scope("/api") web::scope("/api")
.wrap(HttpAuthentication::bearer(jwt_validator)) .wrap(HttpAuthentication::bearer(jwt_validator))
.service(routes::apps) .service(routes::apps)
.service(routes::app)
.service(routes::update) .service(routes::update)
.service(routes::change_password) .service(routes::change_password)
.service(routes::write_review), .service(routes::write_review),

View file

@ -30,6 +30,12 @@ pub async fn reviews(
HttpResponse::Ok().json(app_data.core.get_reviews(&app_name_id).await) 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<crate::AppState>, name: web::Path<String>) -> impl Responder {
response(app_data.core.get_app(&name).await)
}
#[post("/change_password")] #[post("/change_password")]
#[has_any_permission("user", "admin")] #[has_any_permission("user", "admin")]
pub async fn change_password( pub async fn change_password(
@ -81,3 +87,6 @@ fn response(result: serde_json::Value) -> impl Responder {
HttpResponse::InternalServerError().json(result) HttpResponse::InternalServerError().json(result)
} }
} }
//req: HttpRequest
//secure = "username(req)==user.name"