diff --git a/src/handlers/competition/time.rs b/src/handlers/competition/time.rs index 03d976d3..dd1eaf57 100644 --- a/src/handlers/competition/time.rs +++ b/src/handlers/competition/time.rs @@ -23,7 +23,7 @@ pub async fn set_time_patch( ) -> Result { let txn = state.db().begin().await?; - if let Some(start_time) = req.start_time { + let start_time = if let Some(start_time) = req.start_time { let Some(time) = DateTime::from_timestamp(start_time, 0) else { error!("start_time seconds out of range!"); return Err(error::TIME_SECONDS_OUT_OF_RANGE); @@ -35,9 +35,13 @@ pub async fn set_time_patch( }; times::Entity::update(model).exec(&txn).await?; - } - if let Some(end_time) = req.end_time { + Some(time) + } else { + None + }; + + let end_time = if let Some(end_time) = req.end_time { let Some(time) = DateTime::from_timestamp(end_time, 0) else { error!("end_time seconds out of range!"); return Err(error::TIME_SECONDS_OUT_OF_RANGE); @@ -49,15 +53,19 @@ pub async fn set_time_patch( }; times::Entity::update(model).exec(&txn).await?; - } + + Some(time) + } else { + None + }; state .nats() .publish( topics::times(), serde_json::to_vec(&Event::UpdateTime { - start_time: req.start_time, - end_time: req.end_time, + start_time, + end_time, }) .unwrap() .into(), diff --git a/src/handlers/socket.rs b/src/handlers/socket.rs index 8af385dc..9171af00 100644 --- a/src/handlers/socket.rs +++ b/src/handlers/socket.rs @@ -71,8 +71,8 @@ pub enum Event { }, DisbandTeam, UpdateTime { - start_time: Option, - end_time: Option, + start_time: Option>, + end_time: Option>, }, SolutionSet { problem: Uuid, @@ -256,8 +256,8 @@ async fn send_times(state: &S, socket: &mut WebSocket) -> Result< socket .send(Message::Text( serde_json::to_string(&Event::UpdateTime { - start_time: Some(start_time.time.timestamp()), - end_time: Some(end_time.time.timestamp()), + start_time: Some(start_time.time), + end_time: Some(end_time.time), }) .unwrap(), )) diff --git a/tests/competition.rs b/tests/competition.rs index c68cb65c..c5d9f88b 100644 --- a/tests/competition.rs +++ b/tests/competition.rs @@ -160,8 +160,8 @@ mod time { json!({ "event": "UPDATE_TIME", "data": { - "start_time": 1234, - "end_time": 4321, + "start_time": "1970-01-01T00:20:34Z", + "end_time": "1970-01-01T01:12:01Z", } }) );