|
|
@@ -0,0 +1,20 @@
|
|
|
+use actix_web::{HttpResponse, HttpRequest, web, get};
|
|
|
+use sqlx::PgPool;
|
|
|
+use uuid::Uuid;
|
|
|
+use crate::{
|
|
|
+ app_error::AppError,
|
|
|
+ auth::user_auth,
|
|
|
+ models::device::Device
|
|
|
+};
|
|
|
+
|
|
|
+#[get("/home/{homes_id}/device")]
|
|
|
+pub async fn route(
|
|
|
+ db: web::Data<PgPool>,
|
|
|
+ params: web::Path<String>,
|
|
|
+ req: HttpRequest
|
|
|
+) -> Result<HttpResponse, AppError> {
|
|
|
+ let user = user_auth(&db, &req).await?;
|
|
|
+ let home_id = Uuid::parse_str(¶ms)?;
|
|
|
+ let devices = Device::find_many(&db, user.id, home_id).await?;
|
|
|
+ Ok(HttpResponse::Ok().json(devices))
|
|
|
+}
|