mirror of
https://github.com/OSMA-D/osma-server.git
synced 2024-12-18 00:53:46 +03:00
feat: delete app from personal library method
OS-24
This commit is contained in:
parent
1cebe8122d
commit
045daf1dcf
4 changed files with 50 additions and 3 deletions
31
src/core.rs
31
src/core.rs
|
@ -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(
|
pub async fn add_app_to_personal_library(
|
||||||
&self,
|
&self,
|
||||||
name: &String,
|
name: &String,
|
||||||
|
|
|
@ -87,7 +87,8 @@ async fn main() -> std::io::Result<()> {
|
||||||
.service(routes::update)
|
.service(routes::update)
|
||||||
.service(routes::change_password)
|
.service(routes::change_password)
|
||||||
.service(routes::write_review)
|
.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(
|
.service(
|
||||||
web::scope("/auth")
|
web::scope("/auth")
|
||||||
|
|
|
@ -79,7 +79,7 @@ pub async fn update(
|
||||||
#[has_any_permission("user", "admin")]
|
#[has_any_permission("user", "admin")]
|
||||||
pub async fn add_app_to_personal_library(
|
pub async fn add_app_to_personal_library(
|
||||||
app_data: web::Data<crate::AppState>,
|
app_data: web::Data<crate::AppState>,
|
||||||
app_info: web::Json<AppToAdd>,
|
app_info: web::Json<AppInfo>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
) -> impl Responder {
|
) -> impl Responder {
|
||||||
response(
|
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")]
|
#[post("/write_review")]
|
||||||
#[has_any_permission("user", "admin")]
|
#[has_any_permission("user", "admin")]
|
||||||
pub async fn write_review(
|
pub async fn write_review(
|
||||||
|
|
|
@ -49,6 +49,6 @@ pub struct PasswordsInf {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct AppToAdd {
|
pub struct AppInfo {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue