mirror of
https://github.com/OSMA-D/osma-server.git
synced 2024-12-24 19:53:46 +03:00
feat: get personal library
OS-30
This commit is contained in:
parent
c0cb672750
commit
32be9b54a4
3 changed files with 39 additions and 0 deletions
27
src/core.rs
27
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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -54,6 +54,15 @@ pub async fn app(app_data: web::Data<crate::AppState>, name: web::Path<String>)
|
|||
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<crate::AppState>,
|
||||
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(
|
||||
|
|
Loading…
Add table
Reference in a new issue