mirror of
https://github.com/Steffo99/distributed-arcade.git
synced 2024-11-24 00:54:26 +00:00
Refactor /score/
to use query parameters
This commit is contained in:
parent
18dcc542ed
commit
8a2af8d6f2
2 changed files with 47 additions and 30 deletions
|
@ -101,28 +101,40 @@ paths:
|
|||
$ref: "#/components/responses/RedisConnFailed"
|
||||
|
||||
/score/:
|
||||
get:
|
||||
summary: "Get a score from a board"
|
||||
tags: ["Score"]
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/board"
|
||||
- $ref: "#/components/parameters/player"
|
||||
responses:
|
||||
200:
|
||||
description: "Score retrieved successfully"
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: number
|
||||
description: "The score of the specified player."
|
||||
example: 1234.56
|
||||
502:
|
||||
$ref: "#/components/responses/RedisCmdFailed"
|
||||
504:
|
||||
$ref: "#/components/responses/RedisConnFailed"
|
||||
|
||||
put:
|
||||
summary: "Submit a score to a board"
|
||||
tags: ["Score"]
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/board"
|
||||
- $ref: "#/components/parameters/player"
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
board:
|
||||
type: string
|
||||
description: "The board to submit the score to."
|
||||
example: "gravityfusion"
|
||||
score:
|
||||
type: number
|
||||
description: "The score to submit to the board."
|
||||
example: 1234.56
|
||||
player:
|
||||
type: string
|
||||
description: "The name of the player that the score should be submitted as."
|
||||
example: "Steffo"
|
||||
type: number
|
||||
description: "The score to submit to the board."
|
||||
example: 1234.56
|
||||
security:
|
||||
- XBoardToken: []
|
||||
responses:
|
||||
|
@ -146,6 +158,20 @@ components:
|
|||
in: header
|
||||
name: "Authorization"
|
||||
|
||||
parameters:
|
||||
board:
|
||||
name: "board"
|
||||
description: "The name of the board to operate on."
|
||||
in: query
|
||||
schema:
|
||||
type: string
|
||||
player:
|
||||
name: "player"
|
||||
description: "The name of the player to operate on."
|
||||
in: query
|
||||
schema:
|
||||
type: string
|
||||
|
||||
responses:
|
||||
RedisCmdFailed:
|
||||
description: "Could not execute Redis command"
|
||||
|
|
|
@ -13,22 +13,11 @@ use crate::utils::kebab::Skewer;
|
|||
use crate::utils::sorting::SortingOrder;
|
||||
|
||||
|
||||
/// Expected input data for `GET /score/`.
|
||||
pub(crate) struct RouteScoreGetInput {
|
||||
/// Query parameters for `/score/` routes.
|
||||
pub(crate) struct RouteScoreQuery {
|
||||
/// The board to access.
|
||||
pub board: String,
|
||||
/// The name of the player to see the score of.
|
||||
pub player: String,
|
||||
}
|
||||
|
||||
/// Expected input data for `PUT /score/`.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub(crate) struct RouteScorePutInput {
|
||||
/// The board to submit the score to.
|
||||
pub board: String,
|
||||
/// The score to submit.
|
||||
pub score: f64,
|
||||
/// The name of the player submitting the score.
|
||||
/// The name of the player to access the score of.
|
||||
pub player: String,
|
||||
}
|
||||
|
||||
|
@ -36,7 +25,7 @@ pub(crate) struct RouteScorePutInput {
|
|||
/// Handler for `GET /score/`.
|
||||
pub(crate) async fn route_score_get(
|
||||
// Request query
|
||||
Query(RouteScoreGetInput {board, player}): Query<RouteScoreGetInput>,
|
||||
Query(RouteScoreQuery {board, player}): Query<RouteScoreQuery>,
|
||||
// Redis client
|
||||
Extension(rclient): Extension<redis::Client>,
|
||||
) -> outcome::RequestResult {
|
||||
|
@ -64,8 +53,10 @@ pub(crate) async fn route_score_get(
|
|||
pub(crate) async fn route_score_put(
|
||||
// Request headers
|
||||
headers: HeaderMap,
|
||||
// Request query
|
||||
Query(RouteScoreQuery {board, player}): Query<RouteScoreQuery>,
|
||||
// Request body
|
||||
Json(RouteScorePutInput {board, score, player}): Json<RouteScorePutInput>,
|
||||
Json(score): Json<f64>,
|
||||
// Redis client
|
||||
Extension(rclient): Extension<redis::Client>,
|
||||
) -> outcome::RequestResult {
|
||||
|
|
Loading…
Reference in a new issue