Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rfc3339 instead of unix seconds on the socket #94

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/handlers/competition/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub async fn set_time_patch<S: StateTrait>(
) -> Result<StatusCode> {
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);
Expand All @@ -35,9 +35,13 @@ pub async fn set_time_patch<S: StateTrait>(
};

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);
Expand All @@ -49,15 +53,19 @@ pub async fn set_time_patch<S: StateTrait>(
};

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(),
Expand Down
8 changes: 4 additions & 4 deletions src/handlers/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ pub enum Event {
},
DisbandTeam,
UpdateTime {
start_time: Option<i64>,
end_time: Option<i64>,
start_time: Option<DateTime<Utc>>,
end_time: Option<DateTime<Utc>>,
},
SolutionSet {
problem: Uuid,
Expand Down Expand Up @@ -256,8 +256,8 @@ async fn send_times<S: StateTrait>(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(),
))
Expand Down
4 changes: 2 additions & 2 deletions tests/competition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
})
);
Expand Down
Loading