diff --git a/src/core.rs b/src/core.rs index 4667405..c80e1ed 100644 --- a/src/core.rs +++ b/src/core.rs @@ -63,6 +63,33 @@ impl Core { } } + pub async fn get_personal_library(&self, name: &String) -> serde_json::Value { + let response = self + .personal_libraries + .find_one(doc! {"name":&name}, None) + .await; + match response { + Ok(response) => match response { + Some(result) => json!({ + "code":"ok_body", + "body": result.get_array("apps").unwrap() + }), + None => { + json! ({ + "code":"denied", + "msg":"This user does not exist" + }) + } + }, + Err(_) => { + json! ({ + "code":"err", + "msg":"Unknown error" + }) + } + } + } + pub async fn get_rating(&self, app_id: &String) -> serde_json::Value { let result = self .reviews diff --git a/src/main.rs b/src/main.rs index e635c50..067144e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,11 +80,14 @@ async fn main() -> std::io::Result<()> { .service( web::scope("/api") .wrap(HttpAuthentication::bearer(jwt_validator)) + //get .service(routes::apps) .service(routes::app) .service(routes::reviews) .service(routes::rating) .service(routes::versions) + .service(routes::personal_library) + //post .service(routes::update) .service(routes::change_password) .service(routes::write_review) diff --git a/src/routes.rs b/src/routes.rs index b81180a..7e75d1d 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -54,6 +54,15 @@ pub async fn app(app_data: web::Data, name: web::Path) response(app_data.core.get_app(&name).await) } +#[get("/personal_library")] +#[has_any_permission("user", "admin")] +pub async fn personal_library( + app_data: web::Data, + req: HttpRequest, +) -> impl Responder { + response(app_data.core.get_personal_library(&username(req)).await) +} + #[post("/change_password")] #[has_any_permission("user", "admin")] pub async fn change_password(