diff --git a/todored/Cargo.toml b/todored/Cargo.toml index e76d818..a2df0e8 100644 --- a/todored/Cargo.toml +++ b/todored/Cargo.toml @@ -17,4 +17,3 @@ redis = { version = "0.23.1", features = ["r2d2", "ahash", "cluster", "tokio-com serde = { version = "1.0.178", features = ["derive"] } tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] } tower-http = { version = "0.4.3", features = ["cors"] } -uuid = { version = "1.4.1", features = ["v5", "serde"] } diff --git a/todored/src/op.rs b/todored/src/op.rs index ee56699..ffc3e06 100644 --- a/todored/src/op.rs +++ b/todored/src/op.rs @@ -1,5 +1,4 @@ use serde::{Deserialize, Serialize}; -use uuid::Uuid; use super::task::Task; @@ -9,7 +8,7 @@ pub enum ClientOperation { /// Set the board's title. Title(String), /// Create a new [`Task`], or update or delete the task with the given [`Uuid`]. - Task(Option, Option), + Task(Option, Option), } /// An operation sent from the server to the clients, and stored on the database. @@ -18,5 +17,32 @@ pub enum ServerOperation { /// Set the board's title. Title(String), /// Create, update, or delete the [`Task`] with the given [`Uuid`]. - Task(Uuid, Option), + Task(u64, Option), +} + +impl ClientOperation { + fn handle(self) { + todo!() + } +} + +impl ServerOperation { + fn store(&self, rconn: redis::aio::Connection, board: &str) -> Result<()> { + log::debug!("Storing ServerOperation in Redis: {:?}", &self); + + log::trace!("Serializing ServerOperation to JSON..."); + let data = serde_json::ser::to_string(self) + .expect_or_500_and_log("Failed to serialize ServerOperation"); + + log::trace!("Computing Redis key..."); + let stream_key = format!("board:{{{board}}}:stream"); + + log::trace!("Adding to the Redis stream {stream_key:?}..."); + let response = redis::cmd("XADD") + .arg(stream_key) + .arg() + + + Ok(()) + } }