feat: delete app from personal library method

OS-24
This commit is contained in:
Artemy 2022-07-27 13:46:55 +03:00
parent 1cebe8122d
commit 045daf1dcf
4 changed files with 50 additions and 3 deletions

View file

@ -214,6 +214,37 @@ impl Core {
}
}
pub async fn delete_app_from_personal_library(
&self,
name: &String,
app: &String,
) -> serde_json::Value {
let response = self
.personal_libraries
.update_one(
doc! {"name": name},
doc! {"$pull": {
"apps":&app,
}},
None,
)
.await;
match response {
Ok(_) => {
json! ({
"code":"ok",
"msg":"App deleted from personal library"
})
}
Err(_) => {
json! ({
"code":"err",
"msg":"Unknown error"
})
}
}
}
pub async fn add_app_to_personal_library(
&self,
name: &String,

View file

@ -87,7 +87,8 @@ async fn main() -> std::io::Result<()> {
.service(routes::update)
.service(routes::change_password)
.service(routes::write_review)
.service(routes::add_app_to_personal_library),
.service(routes::add_app_to_personal_library)
.service(routes::delete_app_from_personal_library),
)
.service(
web::scope("/auth")

View file

@ -79,7 +79,7 @@ pub async fn update(
#[has_any_permission("user", "admin")]
pub async fn add_app_to_personal_library(
app_data: web::Data<crate::AppState>,
app_info: web::Json<AppToAdd>,
app_info: web::Json<AppInfo>,
req: HttpRequest,
) -> impl Responder {
response(
@ -90,6 +90,21 @@ pub async fn add_app_to_personal_library(
)
}
#[post("/delete_app_from_personal_library")]
#[has_any_permission("user", "admin")]
pub async fn delete_app_from_personal_library(
app_data: web::Data<crate::AppState>,
app_info: web::Json<AppInfo>,
req: HttpRequest,
) -> impl Responder {
response(
app_data
.core
.delete_app_from_personal_library(&username(req), &app_info.name)
.await,
)
}
#[post("/write_review")]
#[has_any_permission("user", "admin")]
pub async fn write_review(

View file

@ -49,6 +49,6 @@ pub struct PasswordsInf {
}
#[derive(Debug, Serialize, Deserialize)]
pub struct AppToAdd {
pub struct AppInfo {
pub name: String,
}