mirror of
https://github.com/OSMA-D/osma-server.git
synced 2024-12-24 19:53:46 +03:00
feat: get app (OS-23)
This commit is contained in:
parent
699f84e440
commit
915d8a6321
3 changed files with 34 additions and 0 deletions
24
src/core.rs
24
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<ReviewData>) -> serde_json::Value {
|
||||
let options = FindOneOptions::builder()
|
||||
.projection(doc! {"_id" : 1})
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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<crate::AppState>, name: web::Path<String>) -> 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"
|
||||
|
|
Loading…
Add table
Reference in a new issue