Skip to content

Commit

Permalink
rework filters and better support for pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Tropix126 committed Dec 25, 2023
1 parent 29ec78c commit 8fdb561
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 158 deletions.
76 changes: 38 additions & 38 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::filters::{
DivisionMatchesFilter, DivisionRankingsFilter, EventAwardsFilter, EventSkillsFilter,
EventTeamsFilter, SeasonEventsFilter, TeamAwardsFilter, TeamEventsFilter, TeamMatchesFilter,
TeamRankingsFilter, TeamSkillsFilter,
use crate::query::{
DivisionMatchesQuery, DivisionRankingsQuery, EventAwardsQuery, EventSkillsQuery,
EventTeamsQuery, SeasonEventsQuery, TeamAwardsQuery, TeamEventsQuery, TeamMatchesQuery,
TeamRankingsQuery, TeamSkillsQuery,
};

use super::{
filters::{EventsFilter, SeasonsFilter, TeamsFilter},
query::{EventsQuery, SeasonsQuery, TeamsQuery},
schema::*,
};
use reqwest::header::USER_AGENT;
Expand Down Expand Up @@ -81,13 +81,13 @@ impl RobotEvents {

/// Get a paginated list of [`Team`]s from RobotEvents.
///
/// Team listings can be filtered using a [`TeamsFilter`] search.
/// Team listings can be queryed using a [`TeamsQuery`] search.
pub async fn teams(
&self,
filter: TeamsFilter,
query: TeamsQuery,
) -> Result<PaginatedResponse<Team>, reqwest::Error> {
Ok(self
.request(format!("/teams{filter}"))
.request(format!("/teams{query}"))
.await?
.json()
.await?)
Expand All @@ -106,10 +106,10 @@ impl RobotEvents {
pub async fn team_events(
&self,
team_id: i32,
filter: TeamEventsFilter,
query: TeamEventsQuery,
) -> Result<PaginatedResponse<Event>, reqwest::Error> {
Ok(self
.request(format!("/teams/{team_id}/events{filter}"))
.request(format!("/teams/{team_id}/events{query}"))
.await?
.json()
.await?)
Expand All @@ -119,10 +119,10 @@ impl RobotEvents {
pub async fn team_matches(
&self,
team_id: i32,
filter: TeamMatchesFilter,
query: TeamMatchesQuery,
) -> Result<PaginatedResponse<Match>, reqwest::Error> {
Ok(self
.request(format!("/teams/{team_id}/matches{filter}"))
.request(format!("/teams/{team_id}/matches{query}"))
.await?
.json()
.await?)
Expand All @@ -132,10 +132,10 @@ impl RobotEvents {
pub async fn team_rankings(
&self,
team_id: i32,
filter: TeamRankingsFilter,
query: TeamRankingsQuery,
) -> Result<PaginatedResponse<Ranking>, reqwest::Error> {
Ok(self
.request(format!("/teams/{team_id}/rankings{filter}"))
.request(format!("/teams/{team_id}/rankings{query}"))
.await?
.json()
.await?)
Expand All @@ -145,10 +145,10 @@ impl RobotEvents {
pub async fn team_skills(
&self,
team_id: i32,
filter: TeamSkillsFilter,
query: TeamSkillsQuery,
) -> Result<PaginatedResponse<Skill>, reqwest::Error> {
Ok(self
.request(format!("/teams/{team_id}/skills{filter}"))
.request(format!("/teams/{team_id}/skills{query}"))
.await?
.json()
.await?)
Expand All @@ -158,10 +158,10 @@ impl RobotEvents {
pub async fn team_awards(
&self,
team_id: i32,
filter: TeamAwardsFilter,
query: TeamAwardsQuery,
) -> Result<PaginatedResponse<Award>, reqwest::Error> {
Ok(self
.request(format!("/teams/{team_id}/awards{filter}"))
.request(format!("/teams/{team_id}/awards{query}"))
.await?
.json()
.await?)
Expand All @@ -174,13 +174,13 @@ impl RobotEvents {

/// Get a paginated list of [`Season`]s from RobotEvents.
///
/// Season listings can be filtered using a [`SeasonFilter`] search.
/// Season listings can be queryed using a [`SeasonQuery`] search.
pub async fn seasons(
&self,
filter: SeasonsFilter,
query: SeasonsQuery,
) -> Result<PaginatedResponse<Season>, reqwest::Error> {
Ok(self
.request(format!("/seasons{filter}"))
.request(format!("/seasons{query}"))
.await?
.json()
.await?)
Expand All @@ -199,10 +199,10 @@ impl RobotEvents {
pub async fn season_events(
&self,
season_id: i32,
filter: SeasonEventsFilter,
query: SeasonEventsQuery,
) -> Result<PaginatedResponse<Season>, reqwest::Error> {
Ok(self
.request(format!("/seasons/{season_id}/events{filter}"))
.request(format!("/seasons/{season_id}/events{query}"))
.await?
.json()
.await?)
Expand Down Expand Up @@ -233,13 +233,13 @@ impl RobotEvents {

/// Get a paginated list of [`Event`]s from RobotEvents.
///
/// Event listings can be filtered using an [`EventFilter`] search.
/// Event listings can be queryed using an [`EventQuery`] search.
pub async fn events(
&self,
filter: EventsFilter,
query: EventsQuery,
) -> Result<PaginatedResponse<Event>, reqwest::Error> {
Ok(self
.request(format!("/events{filter}"))
.request(format!("/events{query}"))
.await?
.json()
.await?)
Expand All @@ -258,10 +258,10 @@ impl RobotEvents {
pub async fn event_teams(
&self,
event_id: i32,
filter: EventTeamsFilter,
query: EventTeamsQuery,
) -> Result<PaginatedResponse<Team>, reqwest::Error> {
Ok(self
.request(format!("/events/{event_id}/teams{filter}"))
.request(format!("/events/{event_id}/teams{query}"))
.await?
.json()
.await?)
Expand All @@ -271,10 +271,10 @@ impl RobotEvents {
pub async fn event_skills(
&self,
event_id: i32,
filter: EventSkillsFilter,
query: EventSkillsQuery,
) -> Result<PaginatedResponse<Skill>, reqwest::Error> {
Ok(self
.request(format!("/events/{event_id}/skills{filter}"))
.request(format!("/events/{event_id}/skills{query}"))
.await?
.json()
.await?)
Expand All @@ -284,10 +284,10 @@ impl RobotEvents {
pub async fn event_awards(
&self,
event_id: i32,
filter: EventAwardsFilter,
query: EventAwardsQuery,
) -> Result<PaginatedResponse<Award>, reqwest::Error> {
Ok(self
.request(format!("/events/{event_id}/awards{filter}"))
.request(format!("/events/{event_id}/awards{query}"))
.await?
.json()
.await?)
Expand All @@ -298,11 +298,11 @@ impl RobotEvents {
&self,
event_id: i32,
division_id: i32,
filter: DivisionMatchesFilter,
query: DivisionMatchesQuery,
) -> Result<PaginatedResponse<Match>, reqwest::Error> {
Ok(self
.request(format!(
"/events/{event_id}/divisions/{division_id}/matches{filter}"
"/events/{event_id}/divisions/{division_id}/matches{query}"
))
.await?
.json()
Expand All @@ -314,11 +314,11 @@ impl RobotEvents {
&self,
event_id: i32,
division_id: i32,
filter: DivisionRankingsFilter,
query: DivisionRankingsQuery,
) -> Result<PaginatedResponse<Ranking>, reqwest::Error> {
Ok(self
.request(format!(
"/events/{event_id}/divisions/{division_id}/finalistRankings{filter}"
"/events/{event_id}/divisions/{division_id}/finalistRankings{query}"
))
.await?
.json()
Expand All @@ -330,11 +330,11 @@ impl RobotEvents {
&self,
event_id: i32,
division_id: i32,
filter: DivisionRankingsFilter,
query: DivisionRankingsQuery,
) -> Result<PaginatedResponse<Ranking>, reqwest::Error> {
Ok(self
.request(format!(
"/events/{event_id}/divisions/{division_id}/finalist{filter}"
"/events/{event_id}/divisions/{division_id}/finalist{query}"
))
.await?
.json()
Expand Down
35 changes: 0 additions & 35 deletions src/filters/mod.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod client;
pub mod filters;
pub mod query;
pub mod schema;

pub use client::*;
Loading

0 comments on commit 8fdb561

Please sign in to comment.