initial websocket implementation
This commit is contained in:
parent
4aa5cf463f
commit
3e1c744db1
7 changed files with 244 additions and 4 deletions
28
src/utils/events.rs
Normal file
28
src/utils/events.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use crate::entities::owner;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum Event {
|
||||
WebsocketBroadcast(WebsocketMessage)
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum WebsocketMessage {
|
||||
NewOwner(Arc<owner::Model>)
|
||||
}
|
||||
|
||||
impl WebsocketMessage {
|
||||
pub fn to_json(self) -> Value {
|
||||
json!({
|
||||
"type": match self {
|
||||
Self::NewOwner(_) => "new_owner",
|
||||
},
|
||||
"data": match self {
|
||||
Self::NewOwner(owner) => json!(owner),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1,2 +1,4 @@
|
|||
pub mod open_library;
|
||||
pub mod serde;
|
||||
pub mod events;
|
||||
|
||||
|
|
|
|||
Reference in a new issue