Skip to content
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
49 changes: 49 additions & 0 deletions lib/src/api/bulk_pairings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use futures::stream::StreamExt;

use crate::client::LichessApi;
use crate::error::Result;
use crate::model::bulk_pairings::*;
use crate::model::games::GameJson;

impl LichessApi<reqwest::Client> {
pub async fn get_bulk_pairings(&self) -> Result<Vec<BulkPairing>> {
self.get_single_model(list::GetRequest::new()).await
}

pub async fn create_bulk_pairing(
&self,
form: create::CreateBulkPairingForm,
) -> Result<BulkPairing> {
self.get_single_model(create::PostRequest::new(form)).await
}

pub async fn get_bulk_pairing(
&self,
request: impl Into<show::GetRequest>,
) -> Result<BulkPairing> {
self.get_single_model(request.into()).await
}

pub async fn cancel_bulk_pairing(
&self,
request: impl Into<remove::DeleteRequest>,
) -> Result<bool> {
self.get_ok(request.into()).await
}

pub async fn export_bulk_pairing_games(
&self,
id: &str,
query: games::GetQuery,
) -> Result<impl StreamExt<Item = Result<GameJson>>> {
self.get_streamed_models(games::GetRequest::new(id, query))
.await
}

pub async fn start_bulk_pairing_clocks(
&self,
request: impl Into<start_clocks::PostRequest>,
) -> Result<bool> {
self.get_ok(request.into()).await
}
}
1 change: 1 addition & 0 deletions lib/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod analysis;
pub mod arena_tournaments;
pub mod board;
pub mod bot;
pub mod bulk_pairings;
pub mod challenges;
pub mod external_engine;
pub mod fide;
Expand Down
34 changes: 34 additions & 0 deletions lib/src/model/bulk_pairings/create.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::model::{Body, Days, Request, VariantKey};
use serde::Serialize;
use serde_with::skip_serializing_none;

#[skip_serializing_none]
#[derive(Default, Clone, Debug, Serialize)]
pub struct CreateBulkPairingForm {
pub players: String,
#[serde(rename = "clock.limit")]
pub clock_limit: Option<u32>,
#[serde(rename = "clock.increment")]
pub clock_increment: Option<u32>,
pub days: Option<Days>,
#[serde(rename = "pairAt")]
pub pair_at: Option<i64>,
#[serde(rename = "startClocksAt")]
pub start_clocks_at: Option<i64>,
pub rated: Option<bool>,
pub variant: Option<VariantKey>,
pub fen: Option<String>,
pub message: Option<String>,
pub rules: Option<String>,
}

#[derive(Default, Clone, Debug, Serialize)]
pub struct PostQuery;

pub type PostRequest = Request<PostQuery, CreateBulkPairingForm>;

impl PostRequest {
pub fn new(form: CreateBulkPairingForm) -> Self {
Self::post("/api/bulk-pairing", None, Body::Form(form), None)
}
}
26 changes: 26 additions & 0 deletions lib/src/model/bulk_pairings/games.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use crate::model::Request;
use serde::Serialize;
use serde_with::skip_serializing_none;

#[skip_serializing_none]
#[derive(Default, Clone, Debug, Serialize)]
pub struct GetQuery {
pub moves: Option<bool>,
#[serde(rename = "pgnInJson")]
pub pgn_in_json: Option<bool>,
pub tags: Option<bool>,
pub clocks: Option<bool>,
pub evals: Option<bool>,
pub accuracy: Option<bool>,
pub opening: Option<bool>,
pub division: Option<bool>,
pub literate: Option<bool>,
}

pub type GetRequest = Request<GetQuery>;

impl GetRequest {
pub fn new(id: &str, query: GetQuery) -> Self {
Self::get(format!("/api/bulk-pairing/{id}/games"), query, None)
}
}
13 changes: 13 additions & 0 deletions lib/src/model/bulk_pairings/list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::model::Request;
use serde::Serialize;

#[derive(Default, Clone, Debug, Serialize)]
pub struct GetQuery;

pub type GetRequest = Request<GetQuery>;

impl GetRequest {
pub fn new() -> Self {
Self::get("/api/bulk-pairing", None, None)
}
}
30 changes: 30 additions & 0 deletions lib/src/model/bulk_pairings/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
pub mod create;
pub mod games;
pub mod list;
pub mod remove;
pub mod show;
pub mod start_clocks;

use crate::model::{ArenaClock, VariantKey};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct BulkPairing {
pub id: String,
pub games: Vec<BulkPairingGame>,
pub variant: VariantKey,
pub clock: ArenaClock,
pub pair_at: i64,
pub paired_at: Option<i64>,
pub rated: bool,
pub start_clocks_at: i64,
pub scheduled_at: i64,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BulkPairingGame {
pub id: String,
pub black: String,
pub white: String,
}
19 changes: 19 additions & 0 deletions lib/src/model/bulk_pairings/remove.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use crate::model::Request;
use serde::Serialize;

#[derive(Default, Clone, Debug, Serialize)]
pub struct DeleteQuery;

pub type DeleteRequest = Request<DeleteQuery>;

impl DeleteRequest {
pub fn new(id: &str) -> Self {
Self::delete(format!("/api/bulk-pairing/{id}"), None, None, None)
}
}

impl<S: AsRef<str>> From<S> for DeleteRequest {
fn from(id: S) -> Self {
Self::new(id.as_ref())
}
}
19 changes: 19 additions & 0 deletions lib/src/model/bulk_pairings/show.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use crate::model::Request;
use serde::Serialize;

#[derive(Default, Clone, Debug, Serialize)]
pub struct GetQuery;

pub type GetRequest = Request<GetQuery>;

impl GetRequest {
pub fn new(id: &str) -> Self {
Self::get(format!("/api/bulk-pairing/{id}"), None, None)
}
}

impl<S: AsRef<str>> From<S> for GetRequest {
fn from(id: S) -> Self {
Self::new(id.as_ref())
}
}
24 changes: 24 additions & 0 deletions lib/src/model/bulk_pairings/start_clocks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use crate::model::Request;
use serde::Serialize;

#[derive(Default, Clone, Debug, Serialize)]
pub struct PostQuery;

pub type PostRequest = Request<PostQuery>;

impl PostRequest {
pub fn new(id: &str) -> Self {
Self::post(
format!("/api/bulk-pairing/{id}/start-clocks"),
None,
None,
None,
)
}
}

impl<S: AsRef<str>> From<S> for PostRequest {
fn from(id: S) -> Self {
Self::new(id.as_ref())
}
}
1 change: 1 addition & 0 deletions lib/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod analysis;
pub mod arena_tournaments;
pub mod board;
pub mod bot;
pub mod bulk_pairings;
pub mod challenges;
pub mod external_engine;
pub mod fide;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/model/simuls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub struct Simul {
pub is_created: bool,
pub is_finished: bool,
pub is_running: bool,
pub estimated_start_at: u64,
pub started_at: u64,
pub estimated_start_at: Option<u64>,
pub started_at: Option<u64>,
pub finished_at: Option<u64>,
#[serde(rename = "nbApplicants")]
pub applicants: u32,
Expand Down
15 changes: 15 additions & 0 deletions lib/tests/data/response/bulk_pairing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"id": "RVAcwgg7",
"games": [
{ "id": "NKop9IyD", "black": "lizen1", "white": "thibault" },
{ "id": "KT8374ut", "black": "lizen3", "white": "lizen2" },
{ "id": "wInQr8Sk", "black": "lizen5", "white": "lizen4" }
],
"variant": "standard",
"clock": { "increment": 0, "limit": 300 },
"pairAt": 1612289869919,
"pairedAt": null,
"rated": false,
"startClocksAt": 1612200422971,
"scheduledAt": 1612203514628
}
5 changes: 5 additions & 0 deletions lib/tests/offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ pub fn swiss_tournaments() {
test_response_model::<swiss_tournaments::SwissResult>("swiss_result");
}

#[test]
pub fn bulk_pairings() {
test_response_model::<bulk_pairings::BulkPairing>("bulk_pairing");
}

#[test]
pub fn studies() {
test_response_model::<studies::create::CreateStudyResponse>("study_create");
Expand Down
Loading