|
@@ -0,0 +1,30 @@
|
|
|
|
|
+use actix_web::{HttpResponse, HttpRequest, web, delete};
|
|
|
|
|
+use sqlx::PgPool;
|
|
|
|
|
+use uuid::Uuid;
|
|
|
|
|
+use serde::Deserialize;
|
|
|
|
|
+use serde_json::json;
|
|
|
|
|
+use crate::{
|
|
|
|
|
+ app_error::AppError,
|
|
|
|
|
+ auth::user_auth,
|
|
|
|
|
+ models::device::Device
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+#[derive(Deserialize)]
|
|
|
|
|
+struct Path {
|
|
|
|
|
+ home_id: String,
|
|
|
|
|
+ device_id: String
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#[delete("/home/{home_id}/device/{device_id}")]
|
|
|
|
|
+pub async fn route(
|
|
|
|
|
+ db: web::Data<PgPool>,
|
|
|
|
|
+ path: web::Path<Path>,
|
|
|
|
|
+ req: HttpRequest
|
|
|
|
|
+) -> Result<HttpResponse, AppError> {
|
|
|
|
|
+ let user = user_auth(&db, &req).await?;
|
|
|
|
|
+ let params = path.into_inner();
|
|
|
|
|
+ let home_id = Uuid::parse_str(¶ms.home_id)?;
|
|
|
|
|
+ let device_id = Uuid::parse_str(¶ms.device_id)?;
|
|
|
|
|
+ Device::delete(&db, user.id, home_id, device_id).await?;
|
|
|
|
|
+ Ok(HttpResponse::Ok().json(json!({"success": true})))
|
|
|
|
|
+}
|