initial websocket implementation

This commit is contained in:
Ninjdai 2025-08-01 01:27:25 +02:00
parent 4aa5cf463f
commit 3e1c744db1
7 changed files with 244 additions and 4 deletions

28
src/utils/events.rs Normal file
View 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),
}
})
}
}

View file

@ -1,2 +1,4 @@
pub mod open_library;
pub mod serde;
pub mod events;