mirror of
https://github.com/Steffo99/distributed-arcade.git
synced 2024-11-21 15:44:26 +00:00
Use ZADD CH
to return different status codes based on the score change
This commit is contained in:
parent
ea90ad7b51
commit
b88f66e1e1
2 changed files with 22 additions and 2 deletions
|
@ -138,6 +138,22 @@ paths:
|
||||||
security:
|
security:
|
||||||
- XBoardToken: []
|
- XBoardToken: []
|
||||||
responses:
|
responses:
|
||||||
|
200:
|
||||||
|
description: "Score discarded as it was worse than the previous one"
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: number
|
||||||
|
description: "The previous score."
|
||||||
|
example: 2468.12
|
||||||
|
201:
|
||||||
|
description: "Score submitted and updated"
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: number
|
||||||
|
description: "The new score."
|
||||||
|
example: 1234.56
|
||||||
401:
|
401:
|
||||||
description: "Missing, invalid or malformed Authorization header"
|
description: "Missing, invalid or malformed Authorization header"
|
||||||
content:
|
content:
|
||||||
|
|
|
@ -93,7 +93,8 @@ pub(crate) async fn route_score_put(
|
||||||
log::trace!("Sorting order is: {order:?}");
|
log::trace!("Sorting order is: {order:?}");
|
||||||
|
|
||||||
log::trace!("Inserting score: {score:?}");
|
log::trace!("Inserting score: {score:?}");
|
||||||
redis::cmd("ZADD").arg(&scores_key).arg(order.zadd_mode()).arg(&score).arg(&player).query_async(&mut rconn).await
|
let changed = redis::cmd("ZADD").arg(&scores_key).arg(order.zadd_mode()).arg("CH").arg(&score).arg(&player)
|
||||||
|
.query_async::<redis::aio::Connection, i32>(&mut rconn).await
|
||||||
.map_err(|_| outcome::redis_cmd_failed())?;
|
.map_err(|_| outcome::redis_cmd_failed())?;
|
||||||
|
|
||||||
log::trace!("Getting the new score...");
|
log::trace!("Getting the new score...");
|
||||||
|
@ -102,7 +103,10 @@ pub(crate) async fn route_score_put(
|
||||||
log::trace!("Received score: {nscore:?}");
|
log::trace!("Received score: {nscore:?}");
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
StatusCode::OK,
|
match changed.gt(&0) {
|
||||||
|
true => StatusCode::CREATED,
|
||||||
|
false => StatusCode::OK,
|
||||||
|
},
|
||||||
outcome::req_success!(nscore)
|
outcome::req_success!(nscore)
|
||||||
))
|
))
|
||||||
}
|
}
|
Loading…
Reference in a new issue