mirror of
https://github.com/Steffo99/todocolors.git
synced 2024-11-22 08:14:18 +00:00
Use latest
to denote the latest struct version
This commit is contained in:
parent
fe0f54e358
commit
92e10304e2
3 changed files with 19 additions and 14 deletions
|
@ -5,8 +5,8 @@ use serde::{Deserialize, Serialize};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use crate::outcome::LoggableOutcome;
|
use crate::outcome::LoggableOutcome;
|
||||||
use crate::routes::board::stream::xread_to_vbc;
|
use crate::routes::board::stream::xread_to_vbc;
|
||||||
use crate::task::VersionedBoardChange::V2;
|
use crate::task::VersionedBoardChange;
|
||||||
use crate::task::v2::{BoardChange, BoardState, Task};
|
use crate::task::latest::{BoardChange, BoardState, Task};
|
||||||
|
|
||||||
/// A request sent from a client to the server to perform a [`BoardAction`] on a board.
|
/// A request sent from a client to the server to perform a [`BoardAction`] on a board.
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
@ -24,7 +24,7 @@ impl BoardRequest {
|
||||||
match self.action {
|
match self.action {
|
||||||
BoardAction::Title(title) => {
|
BoardAction::Title(title) => {
|
||||||
log::debug!("Setting board Title: {title:?}");
|
log::debug!("Setting board Title: {title:?}");
|
||||||
let operation = V2(BoardChange::Title(title));
|
let operation = VersionedBoardChange::new_latest(BoardChange::Title(title));
|
||||||
let _id = operation.store_in_redis_stream(rconn, &self.key).await;
|
let _id = operation.store_in_redis_stream(rconn, &self.key).await;
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
|
@ -32,25 +32,25 @@ impl BoardRequest {
|
||||||
log::debug!("Creating Task: {task:?}");
|
log::debug!("Creating Task: {task:?}");
|
||||||
let id = Uuid::new_v4();
|
let id = Uuid::new_v4();
|
||||||
log::trace!("Assigned id {id:?} to Task: {task:?}");
|
log::trace!("Assigned id {id:?} to Task: {task:?}");
|
||||||
let operation = V2(BoardChange::Task(id, Some(task)));
|
let operation = VersionedBoardChange::new_latest(BoardChange::Task(id, Some(task)));
|
||||||
let _id = operation.store_in_redis_stream(rconn, &self.key).await;
|
let _id = operation.store_in_redis_stream(rconn, &self.key).await;
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
BoardAction::Task(Some(id), Some(task)) => {
|
BoardAction::Task(Some(id), Some(task)) => {
|
||||||
log::debug!("Editing Task {id:?}: {task:?}");
|
log::debug!("Editing Task {id:?}: {task:?}");
|
||||||
let operation = V2(BoardChange::Task(id, Some(task)));
|
let operation = VersionedBoardChange::new_latest(BoardChange::Task(id, Some(task)));
|
||||||
let _id = operation.store_in_redis_stream(rconn, &self.key).await;
|
let _id = operation.store_in_redis_stream(rconn, &self.key).await;
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
BoardAction::Task(Some(id), None) => {
|
BoardAction::Task(Some(id), None) => {
|
||||||
log::debug!("Deleting Task {id:?}...");
|
log::debug!("Deleting Task {id:?}...");
|
||||||
let operation = V2(BoardChange::Task(id, None));
|
let operation = VersionedBoardChange::new_latest(BoardChange::Task(id, None));
|
||||||
let _id = operation.store_in_redis_stream(rconn, &self.key).await;
|
let _id = operation.store_in_redis_stream(rconn, &self.key).await;
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
BoardAction::Lock(lock) => {
|
BoardAction::Lock(lock) => {
|
||||||
log::debug!("Setting board lock to: {lock:?}");
|
log::debug!("Setting board lock to: {lock:?}");
|
||||||
let operation = V2(BoardChange::Lock(lock));
|
let operation = VersionedBoardChange::new_latest(BoardChange::Lock(lock));
|
||||||
let _id = operation.store_in_redis_stream(rconn, &self.key).await;
|
let _id = operation.store_in_redis_stream(rconn, &self.key).await;
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
|
@ -81,7 +81,7 @@ impl BoardRequest {
|
||||||
});
|
});
|
||||||
|
|
||||||
log::trace!("Storing new full board state in the Redis Stream...");
|
log::trace!("Storing new full board state in the Redis Stream...");
|
||||||
let id = V2(BoardChange::State(board))
|
let id = VersionedBoardChange::new_latest(BoardChange::State(board))
|
||||||
.store_in_redis_stream(rconn, &self.key).await
|
.store_in_redis_stream(rconn, &self.key).await
|
||||||
.log_err_to_error("Failed to store trimmed board")
|
.log_err_to_error("Failed to store trimmed board")
|
||||||
.map_err(|_| 1011u16)?;
|
.map_err(|_| 1011u16)?;
|
||||||
|
|
|
@ -3,8 +3,8 @@ use std::sync::Arc;
|
||||||
use deadqueue::unlimited::Queue;
|
use deadqueue::unlimited::Queue;
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use crate::task::VersionedBoardChange::V2;
|
use crate::task::latest::BoardChange;
|
||||||
use crate::task::v2::BoardChange;
|
use crate::task::VersionedBoardChange;
|
||||||
use super::{redis_xread, redis_xadd, ws_receive, ws_send};
|
use super::{redis_xread, redis_xadd, ws_receive, ws_send};
|
||||||
|
|
||||||
pub async fn handler(
|
pub async fn handler(
|
||||||
|
@ -65,7 +65,7 @@ pub async fn handler(
|
||||||
log::trace!("Client UUID is: {client_uuid:?}");
|
log::trace!("Client UUID is: {client_uuid:?}");
|
||||||
|
|
||||||
log::trace!("Notifying clients of the new connection...");
|
log::trace!("Notifying clients of the new connection...");
|
||||||
let _connect_id = V2(BoardChange::Connect(client_uuid)).store_in_redis_stream(&mut main_redis, &redis_key).await;
|
let _connect_id = VersionedBoardChange::new_latest(BoardChange::Connect(client_uuid)).store_in_redis_stream(&mut main_redis, &redis_key).await;
|
||||||
log::trace!("Notified clients of the new connection successfully!");
|
log::trace!("Notified clients of the new connection successfully!");
|
||||||
|
|
||||||
log::trace!("Creating synchronization structures...");
|
log::trace!("Creating synchronization structures...");
|
||||||
|
@ -121,7 +121,7 @@ pub async fn handler(
|
||||||
redis_xread_abort.abort();
|
redis_xread_abort.abort();
|
||||||
|
|
||||||
log::trace!("Notifying clients of the disconnection...");
|
log::trace!("Notifying clients of the disconnection...");
|
||||||
let _connect_id = V2(BoardChange::Disconnect(client_uuid)).store_in_redis_stream(&mut main_redis, &redis_key).await;
|
let _connect_id = VersionedBoardChange::new_latest(BoardChange::Disconnect(client_uuid)).store_in_redis_stream(&mut main_redis, &redis_key).await;
|
||||||
log::trace!("Notified clients of the disconnection successfully!");
|
log::trace!("Notified clients of the disconnection successfully!");
|
||||||
|
|
||||||
log::trace!("Waiting for the last messages to be sent...");
|
log::trace!("Waiting for the last messages to be sent...");
|
||||||
|
|
|
@ -5,6 +5,7 @@ use crate::outcome::LoggableOutcome;
|
||||||
|
|
||||||
pub mod v1;
|
pub mod v1;
|
||||||
pub mod v2;
|
pub mod v2;
|
||||||
|
pub use v2 as latest;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub enum VersionedBoardChange {
|
pub enum VersionedBoardChange {
|
||||||
|
@ -13,17 +14,21 @@ pub enum VersionedBoardChange {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VersionedBoardChange {
|
impl VersionedBoardChange {
|
||||||
pub fn to_latest_bc(self) -> v2::BoardChange {
|
pub fn to_latest_bc(self) -> latest::BoardChange {
|
||||||
match self {
|
match self {
|
||||||
VersionedBoardChange::V1(bc) => bc.into(),
|
VersionedBoardChange::V1(bc) => bc.into(),
|
||||||
VersionedBoardChange::V2(bc) => bc,
|
VersionedBoardChange::V2(bc) => bc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_latest_vbc(self) -> VersionedBoardChange {
|
pub fn to_latest(self) -> VersionedBoardChange {
|
||||||
Self::V2(self.to_latest_bc())
|
Self::V2(self.to_latest_bc())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_latest(bc: latest::BoardChange) -> VersionedBoardChange {
|
||||||
|
Self::V2(bc)
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) async fn store_in_redis_stream(&self, rconn: &mut redis::aio::Connection, key: &str) -> Result<String, ()> {
|
pub(crate) async fn store_in_redis_stream(&self, rconn: &mut redis::aio::Connection, key: &str) -> Result<String, ()> {
|
||||||
log::debug!("Storing VersionedBoardChange in Redis: {:?}", &self);
|
log::debug!("Storing VersionedBoardChange in Redis: {:?}", &self);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue