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"
|
$ref: "#/components/responses/RedisConnFailed"
|
||||||
|
|
||||||
/score/:
|
/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:
|
put:
|
||||||
summary: "Submit a score to a board"
|
summary: "Submit a score to a board"
|
||||||
tags: ["Score"]
|
tags: ["Score"]
|
||||||
|
parameters:
|
||||||
|
- $ref: "#/components/parameters/board"
|
||||||
|
- $ref: "#/components/parameters/player"
|
||||||
requestBody:
|
requestBody:
|
||||||
required: true
|
required: true
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
type: object
|
type: number
|
||||||
properties:
|
description: "The score to submit to the board."
|
||||||
board:
|
example: 1234.56
|
||||||
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"
|
|
||||||
security:
|
security:
|
||||||
- XBoardToken: []
|
- XBoardToken: []
|
||||||
responses:
|
responses:
|
||||||
|
@ -146,6 +158,20 @@ components:
|
||||||
in: header
|
in: header
|
||||||
name: "Authorization"
|
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:
|
responses:
|
||||||
RedisCmdFailed:
|
RedisCmdFailed:
|
||||||
description: "Could not execute Redis command"
|
description: "Could not execute Redis command"
|
||||||
|
|
|
@ -13,22 +13,11 @@ use crate::utils::kebab::Skewer;
|
||||||
use crate::utils::sorting::SortingOrder;
|
use crate::utils::sorting::SortingOrder;
|
||||||
|
|
||||||
|
|
||||||
/// Expected input data for `GET /score/`.
|
/// Query parameters for `/score/` routes.
|
||||||
pub(crate) struct RouteScoreGetInput {
|
pub(crate) struct RouteScoreQuery {
|
||||||
/// The board to access.
|
/// The board to access.
|
||||||
pub board: String,
|
pub board: String,
|
||||||
/// The name of the player to see the score of.
|
/// The name of the player to access 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.
|
|
||||||
pub player: String,
|
pub player: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +25,7 @@ pub(crate) struct RouteScorePutInput {
|
||||||
/// Handler for `GET /score/`.
|
/// Handler for `GET /score/`.
|
||||||
pub(crate) async fn route_score_get(
|
pub(crate) async fn route_score_get(
|
||||||
// Request query
|
// Request query
|
||||||
Query(RouteScoreGetInput {board, player}): Query<RouteScoreGetInput>,
|
Query(RouteScoreQuery {board, player}): Query<RouteScoreQuery>,
|
||||||
// Redis client
|
// Redis client
|
||||||
Extension(rclient): Extension<redis::Client>,
|
Extension(rclient): Extension<redis::Client>,
|
||||||
) -> outcome::RequestResult {
|
) -> outcome::RequestResult {
|
||||||
|
@ -64,8 +53,10 @@ pub(crate) async fn route_score_get(
|
||||||
pub(crate) async fn route_score_put(
|
pub(crate) async fn route_score_put(
|
||||||
// Request headers
|
// Request headers
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
|
// Request query
|
||||||
|
Query(RouteScoreQuery {board, player}): Query<RouteScoreQuery>,
|
||||||
// Request body
|
// Request body
|
||||||
Json(RouteScorePutInput {board, score, player}): Json<RouteScorePutInput>,
|
Json(score): Json<f64>,
|
||||||
// Redis client
|
// Redis client
|
||||||
Extension(rclient): Extension<redis::Client>,
|
Extension(rclient): Extension<redis::Client>,
|
||||||
) -> outcome::RequestResult {
|
) -> outcome::RequestResult {
|
||||||
|
|
Loading…
Reference in a new issue