Add fmt options and move handlers
This commit is contained in:
parent
50bcac2a1b
commit
fdca5b7277
28 changed files with 85 additions and 70 deletions
emgauwa-core/src/handlers/v1/ws
32
emgauwa-core/src/handlers/v1/ws/mod.rs
Normal file
32
emgauwa-core/src/handlers/v1/ws/mod.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
use std::time::Instant;
|
||||
|
||||
use actix_web::{get, web, HttpRequest, HttpResponse};
|
||||
use actix_web_actors::ws;
|
||||
use emgauwa_lib::types::ConnectedControllersType;
|
||||
use sqlx::{Pool, Sqlite};
|
||||
|
||||
use crate::handlers::errors::ApiError;
|
||||
use crate::handlers::v1::ws::controllers::ControllerWs;
|
||||
|
||||
pub mod controllers;
|
||||
|
||||
#[get("/api/v1/ws/controllers")]
|
||||
pub async fn ws_controllers(
|
||||
pool: web::Data<Pool<Sqlite>>,
|
||||
connected_controllers: web::Data<ConnectedControllersType>,
|
||||
req: HttpRequest,
|
||||
stream: web::Payload,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let resp = ws::start(
|
||||
ControllerWs {
|
||||
pool: pool.get_ref().clone(),
|
||||
controller_uid: None,
|
||||
connected_controllers: connected_controllers.get_ref().clone(),
|
||||
hb: Instant::now(),
|
||||
},
|
||||
&req,
|
||||
stream,
|
||||
)
|
||||
.map_err(|_| ApiError::InternalError(String::from("error starting websocket")));
|
||||
resp
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue