diff --git a/crates/api/src/driver.rs b/crates/api/src/driver.rs new file mode 100644 index 0000000..8eb542c --- /dev/null +++ b/crates/api/src/driver.rs @@ -0,0 +1,31 @@ +use rocket::serde::json::Json; +use rocket::{get, routes, State}; + +use application::{self, models::Drivers}; +use infrastructure::ConnectionPool; +use shared::prelude::*; + +#[get("//drivers?")] +pub fn driver( + db: &State, + series: Series, + param: shared::parameters::GetDriversParameter, +) -> Result>>> { + let conn = &mut db.from_series(series).get().unwrap(); + + let query = application::driver::DriverQueryBuilder::filter(param.into()).build(); + + let res = query.query_and_count::(conn); + + let response = Response { + data: res.0, + pagination: res.1, + series, + }; + + Ok(Json(response)) +} + +pub fn handlers() -> Vec { + routes![driver] +} diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index 9765612..277ff79 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -1,12 +1,16 @@ #![allow(clippy::too_many_arguments)] -pub mod circuit; +mod circuit; +mod driver; pub mod handlers { use crate::*; use rocket::Route; pub fn handlers() -> Vec { - circuit::handlers().into_iter().collect() + circuit::handlers() + .into_iter() + .chain(driver::handlers()) + .collect() } } diff --git a/crates/application/src/circuit.rs b/crates/application/src/circuit.rs index 00ff086..058ba75 100644 --- a/crates/application/src/circuit.rs +++ b/crates/application/src/circuit.rs @@ -45,12 +45,16 @@ impl CircuitQueryBuilder { .results_table() .constructors_table() .drivers_table() + .and_status() + .and_circuits() .and_races() - .and_results() .and_drivers() .and_constructors() .and_grid() + .and_fastest() .and_result() + .and_round() + .and_year() .stmt .paginate(page) .per_page(limit) @@ -59,8 +63,9 @@ impl CircuitQueryBuilder { fn one_of(&self) -> bool { self.filter.driver_ref.is_some() || self.filter.constructor_ref.is_some() - || self.filter.circuit_ref.is_some() + || self.filter.status.is_some() || self.filter.grid.is_some() + || self.filter.fastest.is_some() || self.filter.result.is_some() || self.filter.year.is_some() || self.filter.round.is_some() @@ -72,11 +77,11 @@ impl SqlBuilder for CircuitQueryBuilder { &mut self.stmt } - fn check_and_races(&self) -> bool { + fn check_and_circuits(&self) -> bool { self.one_of() } - fn check_and_results(&self) -> bool { + fn check_and_races(&self) -> bool { self.one_of() } @@ -92,7 +97,7 @@ impl SqlBuilder for CircuitQueryBuilder { } fn check_and_status(&self) -> Option { - None + self.filter.status.as_ref().map(|s| Expr::value(**s)) } fn check_and_grid(&self) -> Option { @@ -102,4 +107,16 @@ impl SqlBuilder for CircuitQueryBuilder { fn check_and_result(&self) -> Option { self.filter.result.as_ref().map(|r| Expr::value(**r)) } + + fn check_and_round(&self) -> Option { + self.filter.round.as_ref().map(|r| Expr::value(**r)) + } + + fn check_and_year(&self) -> Option { + self.filter.year.as_ref().map(|y| Expr::value(**y)) + } + + fn check_and_fastest(&self) -> Option { + self.filter.fastest.as_ref().map(|f| Expr::value(**f)) + } } diff --git a/crates/application/src/driver.rs b/crates/application/src/driver.rs new file mode 100644 index 0000000..1f9bdab --- /dev/null +++ b/crates/application/src/driver.rs @@ -0,0 +1,272 @@ +use sea_query::{Expr, Func, IntoTableRef, Query, SelectStatement, SimpleExpr}; + +use shared::filters::GetDriversFilter; + +use crate::{ + iden::*, + pagination::{Paginate, Paginated}, + sql::*, +}; + +pub struct DriverQueryBuilder { + stmt: SelectStatement, + filter: GetDriversFilter, +} + +impl DriverQueryBuilder { + pub fn filter(filter: GetDriversFilter) -> Self { + let stmt = Query::select() + .distinct() + .from(Drivers::Table) + .columns( + [ + Drivers::DriverId, + Drivers::DriverRef, + Drivers::Number, + Drivers::Code, + Drivers::Forename, + Drivers::Surname, + Drivers::Dob, + Drivers::Nationality, + Drivers::Url, + ] + .into_iter() + .map(|c| (Drivers::Table, c)), + ) + .to_owned(); + + Self { stmt, filter } + } + + fn one_of(&self) -> bool { + self.filter.year.is_some() + || self.filter.constructor_ref.is_some() + || self.filter.status.is_some() + || self.filter.grid.is_some() + || self.filter.result.is_some() + || self.filter.circuit_ref.is_some() + || self.filter.fastest.is_some() + } + + pub fn build(mut self) -> Paginated { + let page: u64 = self.filter.page.unwrap_or_default().0; + let limit: u64 = self.filter.limit.unwrap_or_default().0; + + self.join( + |s| { + s.filter.year.is_some() + || s.filter.circuit_ref.is_some() + || s.filter.driver_standing.is_some() + }, + Races::Table, + ) + .join(Self::one_of, Results::Table) + .join(|s| s.filter.circuit_ref.is_some(), Circuits::Table) + .join(|s| s.filter.constructor_ref.is_some(), Constructors::Table) + .join( + |s| s.filter.driver_standing.is_some(), + DriverStandings::Table, + ) + .and_clause_one() + .and_clause_two() + .and_where(|s| { + s.filter + .year + .map(|year| Expr::col((Races::Table, Races::Year)).eq(Expr::value(*year))) + }) + .and_clause_three() + .stmt + .to_owned() + .paginate(page) + .per_page(limit) + } + + fn and_clause_one(&mut self) -> &mut Self { + if self.filter.driver_standing.is_none() { + return self; + } + + self.and_where(|s| { + if s.filter.year.is_some() || s.filter.constructor_ref.is_some() { + Some( + Expr::col((Drivers::Table, Drivers::DriverId)) + .equals((Results::Table, Results::DriverId)), + ) + } else { + None + } + }) + .and_where(|s| { + s.filter.year.map(|_| { + Expr::col((Results::Table, Results::RaceId)).equals((Races::Table, Races::RaceId)) + }) + }) + .and_where(|s| { + s.filter.constructor_ref.as_ref().map(|constructor_ref| { + Expr::col((Results::Table, Results::ConstructorId)) + .equals((Constructors::Table, Constructors::ConstructorId)) + .and( + Expr::col((Constructors::Table, Constructors::ConstructorRef)) + .eq(Expr::value(&**constructor_ref)), + ) + }) + }) + .and_where(|s| { + s.filter.driver_standing.as_ref().map(|driver_standings| { + Expr::col((DriverStandings::Table, DriverStandings::PositionText)) + .eq(Expr::value(**driver_standings)) + }) + }) + .and_where(|_| { + Some( + Expr::col((DriverStandings::Table, DriverStandings::RaceId)) + .equals((Races::Table, Races::RaceId)), + ) + }) + .and_where(|_| { + Some( + Expr::col((DriverStandings::Table, DriverStandings::DriverId)) + .equals((Drivers::Table, Drivers::DriverId)), + ) + }) + } + + fn and_clause_two(&mut self) -> &mut Self { + if self.filter.driver_standing.is_some() { + return self; + } + + self.and_where(|s| { + if s.one_of() { + Some( + Expr::col((Drivers::Table, Drivers::DriverId)) + .equals((Results::Table, Results::DriverId)), + ) + } else { + None + } + }) + .and_where(|s| { + if s.filter.year.is_some() || s.filter.circuit_ref.is_some() { + Some( + Expr::col((Results::Table, Results::RaceId)) + .equals((Races::Table, Races::RaceId)), + ) + } else { + None + } + }) + .and_where(|s| { + s.filter.circuit_ref.as_ref().map(|circuit_ref| { + Expr::col((Races::Table, Races::CircuitId)) + .equals((Circuits::Table, Circuits::CircuitId)) + .and( + Expr::col((Circuits::Table, Circuits::CircuitRef)) + .eq(Expr::value(&**circuit_ref)), + ) + }) + }) + .and_where(|s| { + s.filter.constructor_ref.as_ref().map(|constructor_ref| { + Expr::col((Results::Table, Results::ConstructorId)) + .equals((Constructors::Table, Constructors::ConstructorId)) + .and( + Expr::col((Constructors::Table, Constructors::ConstructorRef)) + .eq(Expr::value(&**constructor_ref)), + ) + }) + }) + .and_where(|s| { + s.filter.status.map(|status| { + Expr::col((Results::Table, Results::StatusId)).eq(Expr::value(*status)) + }) + }) + .and_where(|s| { + s.filter + .grid + .map(|grid| Expr::col((Results::Table, Results::Grid)).eq(Expr::value(*grid))) + }) + .and_where(|s| { + s.filter + .fastest + .map(|fastest| Expr::col((Results::Table, Results::Rank)).eq(Expr::value(*fastest))) + }) + .and_where(|s| { + s.filter.result.map(|result| { + Expr::col((Results::Table, Results::PositionText)).eq(Expr::value(*result)) + }) + }) + } + + fn and_clause_three(&mut self) -> &mut Self { + if let Some(round) = self.filter.round.map(|r| *r) { + return self.and_where(|_| { + Some(Expr::col((Races::Table, Races::Round)).eq(Expr::value(round))) + }); + } + + if self.filter.driver_standing.is_some() { + if let Some(year) = self.filter.year.map(|y| *y) { + return self.and_where(|_| { + Some( + Expr::col((Races::Table, Races::Round)).in_subquery( + Query::select() + .expr(Func::max(Expr::col(Races::Round))) + .from(Races::Table) + .and_where( + Expr::col((Races::Table, Races::Year)).eq(Expr::value(year)), + ) + .to_owned(), + ), + ) + }); + } else { + return self.and_where(|_| { + Some( + Expr::tuple( + [ + Expr::col((Races::Table, Races::Year)), + Expr::col((Races::Table, Races::Round)), + ] + .map(Into::into), + ) + .in_subquery( + Query::select() + .column(Races::Year) + .expr(Func::max(Expr::col(Races::Round))) + .from(Races::Table) + .group_by_col(Races::Year) + .to_owned(), + ), + ) + }); + } + } + + self + } + + fn join(&mut self, f: F, table: R) -> &mut Self + where + F: FnOnce(&Self) -> bool, + R: IntoTableRef, + { + if f(self) { + self.stmt + .join(sea_query::JoinType::Join, table, Expr::val(1).eq(1)); + } + + self + } + + fn and_where(&mut self, f: F) -> &mut Self + where + F: FnOnce(&Self) -> Option, + { + if let Some(expr) = f(self) { + self.stmt.and_where(expr); + } + + self + } +} diff --git a/crates/application/src/iden.rs b/crates/application/src/iden.rs index 63d27dc..bb61d9c 100644 --- a/crates/application/src/iden.rs +++ b/crates/application/src/iden.rs @@ -98,3 +98,20 @@ pub(crate) enum Constructors { Nationality, Url, } + +#[derive(Iden)] +pub(crate) enum DriverStandings { + #[iden = "driverStandings"] + Table, + #[iden = "driverStandingsId"] + Id, + #[iden = "raceId"] + RaceId, + #[iden = "driverId"] + DriverId, + Points, + Position, + #[iden = "positionText"] + PositionText, + Wins, +} diff --git a/crates/application/src/lib.rs b/crates/application/src/lib.rs index fc01c93..15a95c5 100644 --- a/crates/application/src/lib.rs +++ b/crates/application/src/lib.rs @@ -1,4 +1,5 @@ pub mod circuit; +pub mod driver; pub(crate) mod iden; pub mod models; mod pagination; diff --git a/crates/application/src/models.rs b/crates/application/src/models.rs index b7a60eb..53a42c8 100644 --- a/crates/application/src/models.rs +++ b/crates/application/src/models.rs @@ -20,3 +20,22 @@ pub struct Circuits { alt: Option, url: String, } + +#[derive(FromRow, Debug, Serialize)] +pub struct Drivers { + #[mysql(rename = "driverId")] + driver_id: i32, + #[mysql(rename = "driverRef")] + driver_ref: String, + #[serde(skip_serializing_if = "Option::is_none")] + number: Option, + #[serde(skip_serializing_if = "Option::is_none")] + code: Option, + forename: String, + surname: String, + #[serde(skip_serializing_if = "Option::is_none")] + dob: Option, + #[serde(skip_serializing_if = "Option::is_none")] + nationality: Option, + url: String, +} diff --git a/crates/application/src/pagination.rs b/crates/application/src/pagination.rs index 0b7b251..503f748 100644 --- a/crates/application/src/pagination.rs +++ b/crates/application/src/pagination.rs @@ -5,7 +5,7 @@ use sea_query::{ }; use infrastructure::Connection; -use shared::models::Pagination; +use shared::prelude::Pagination; const DEFAULT_PER_PAGE: u64 = 20; @@ -44,7 +44,7 @@ impl Paginated { where U: FromRow, { - let query = Query::select() + let query = dbg!(Query::select() .column(Asterisk) .expr_window_as( Expr::cust("COUNT(*)"), @@ -54,7 +54,7 @@ impl Paginated { .from_subquery(self.query, Alias::new("t")) .limit(self.per_page) .offset(self.offset) - .to_string(MysqlQueryBuilder); + .to_string(MysqlQueryBuilder)); let res: Vec> = conn.query(query).unwrap(); let total = res.first().map(|r| r.total).unwrap_or(0); diff --git a/crates/application/src/sql.rs b/crates/application/src/sql.rs index fb4088a..fdf5656 100644 --- a/crates/application/src/sql.rs +++ b/crates/application/src/sql.rs @@ -4,20 +4,23 @@ use crate::iden::*; pub(crate) trait SqlBuilder: Sized { fn stmt(&mut self) -> &mut sea_query::SelectStatement; - fn check_and_results(&self) -> bool; fn check_and_races(&self) -> bool; + fn check_and_circuits(&self) -> bool; fn check_and_drivers(&self) -> Option; fn check_and_constructors(&self) -> Option; fn check_and_status(&self) -> Option; fn check_and_grid(&self) -> Option; + fn check_and_fastest(&self) -> Option; fn check_and_result(&self) -> Option; + fn check_and_round(&self) -> Option; + fn check_and_year(&self) -> Option; fn check_races_table(&self) -> bool { - self.check_and_races() + self.check_and_circuits() } fn check_results_table(&self) -> bool { - self.check_and_results() + self.check_and_races() } fn check_drivers_table(&self) -> bool { @@ -44,12 +47,12 @@ pub(crate) trait SqlBuilder: Sized { constructors_table(self, Self::check_constructors_table) } - fn and_races(self) -> Self { - and_races(self, Self::check_and_races) + fn and_circuits(self) -> Self { + and_circuits(self, Self::check_and_circuits) } - fn and_results(self) -> Self { - and_results(self, Self::check_and_results) + fn and_races(self) -> Self { + and_races(self, Self::check_and_races) } fn and_drivers(self) -> Self { @@ -68,9 +71,21 @@ pub(crate) trait SqlBuilder: Sized { and_grid(self, Self::check_and_grid) } + fn and_fastest(self) -> Self { + and_fastest(self, Self::check_and_fastest) + } + fn and_result(self) -> Self { and_result(self, Self::check_and_result) } + + fn and_round(self) -> Self { + and_round(self, Self::check_and_round) + } + + fn and_year(self) -> Self { + and_year(self, Self::check_and_year) + } } pub(crate) fn races_table(mut builder: B, check: F) -> B @@ -131,7 +146,7 @@ where builder } -pub(crate) fn and_races(mut builder: B, check: F) -> B +pub(crate) fn and_circuits(mut builder: B, check: F) -> B where B: SqlBuilder, F: FnOnce(&B) -> bool, @@ -145,7 +160,7 @@ where builder } -pub(crate) fn and_results(mut builder: B, check: F) -> B +pub(crate) fn and_races(mut builder: B, check: F) -> B where B: SqlBuilder, F: FnOnce(&B) -> bool, @@ -222,6 +237,20 @@ where builder } +pub(crate) fn and_fastest(mut builder: B, check: F) -> B +where + B: SqlBuilder, + F: FnOnce(&B) -> Option, + V: Into, +{ + if let Some(v) = check(&builder) { + builder + .stmt() + .and_where(Expr::col((Results::Table, Results::Rank)).eq(v)); + } + builder +} + pub(crate) fn and_result(mut builder: B, check: F) -> B where B: SqlBuilder, @@ -235,3 +264,31 @@ where } builder } + +pub(crate) fn and_round(mut builder: B, check: F) -> B +where + B: SqlBuilder, + F: FnOnce(&B) -> Option, + V: Into, +{ + if let Some(v) = check(&builder) { + builder + .stmt() + .and_where(Expr::col((Races::Table, Races::Round)).eq(v)); + } + builder +} + +pub(crate) fn and_year(mut builder: B, check: F) -> B +where + B: SqlBuilder, + F: FnOnce(&B) -> Option, + V: Into, +{ + if let Some(v) = check(&builder) { + builder + .stmt() + .and_where(Expr::col((Races::Table, Races::Year)).eq(v)); + } + builder +} diff --git a/crates/shared/src/filters.rs b/crates/shared/src/filters.rs index b631ca7..cc2a995 100644 --- a/crates/shared/src/filters.rs +++ b/crates/shared/src/filters.rs @@ -12,91 +12,29 @@ pub struct GetCircuitsFilter { pub limit: Option, #[validation(skip)] pub page: Option, - pub circuit_ref: Option, pub driver_ref: Option, pub constructor_ref: Option, + pub status: Option, pub grid: Option, + pub fastest: Option, pub result: Option, pub year: Option, pub round: Option, } #[derive(Debug, Default, FilterValidation)] -pub struct DriverFilter { +pub struct GetDriversFilter { #[validation(skip)] pub limit: Option, #[validation(skip)] pub page: Option, - #[validation(unique)] - pub driver_number: Option, - #[validation(unique)] - pub driver_ref: Option, - pub constructor_ref: Option, - pub circuit_ref: Option, - pub grid: Option, - pub result: Option, - #[validation(skip)] - pub year: Option, - #[validation(skip)] - pub round: Option, -} - -#[derive(Debug, Default, FilterValidation)] -pub struct ConstructorFilter { - #[validation(skip)] - pub limit: Option, - #[validation(skip)] - pub page: Option, - #[validation(unique)] - pub driver_number: Option, - #[validation(unique)] - pub driver_ref: Option, + pub circuit_ref: Option, pub constructor_ref: Option, - pub circuit_ref: Option, + pub driver_standing: Option, + pub status: Option, pub grid: Option, + pub fastest: Option, pub result: Option, - #[validation(skip)] - pub year: Option, - #[validation(skip)] - pub round: Option, -} - -#[derive(Debug, Default, FilterValidation)] -pub struct DriverStandingFilter { - #[validation(skip)] - pub limit: Option, - #[validation(skip)] - pub page: Option, - pub driver_ref: Option, - pub result: Option, - #[validation(skip)] - pub year: Option, - #[validation(skip)] - pub round: Option, -} - -#[derive(Debug, Default, FilterValidation)] -pub struct ConstructorStandingFilter { - #[validation(skip)] - pub limit: Option, - #[validation(skip)] - pub page: Option, - pub constructor_ref: Option, - pub result: Option, - #[validation(skip)] pub year: Option, - #[validation(skip)] pub round: Option, } - -#[derive(Debug, Default, FilterValidation)] -pub struct SeasonFilter { - #[validation(skip)] - pub limit: Option, - #[validation(skip)] - pub page: Option, - pub circuit_ref: Option, - pub constructor_ref: Option, - pub driver_ref: Option, - pub grid: Option, -} diff --git a/crates/shared/src/lib.rs b/crates/shared/src/lib.rs index 0095c65..13dd0d6 100644 --- a/crates/shared/src/lib.rs +++ b/crates/shared/src/lib.rs @@ -1,13 +1,11 @@ pub mod error; pub mod filters; -pub mod models; pub mod parameters; pub mod responses; pub mod prelude { pub use crate::error::*; pub use crate::filters::*; - pub use crate::models::*; pub use crate::parameters::*; pub use crate::responses::*; } diff --git a/crates/shared/src/models.rs b/crates/shared/src/models.rs deleted file mode 100644 index d962bff..0000000 --- a/crates/shared/src/models.rs +++ /dev/null @@ -1,83 +0,0 @@ -use rocket::serde::Serialize; - -#[derive(Debug, Serialize, Default)] -#[serde(crate = "rocket::serde")] -pub struct Pagination { - pub limit: u64, - pub page: u64, - pub max_page: u64, - pub total: u64, -} - -#[derive(Debug, Default, Serialize, Clone, Copy)] -#[serde(crate = "rocket::serde")] -pub enum Series { - #[default] - #[serde(rename = "f1")] - F1, - #[serde(rename = "f2")] - F2, -} - -#[derive(Debug, Serialize)] -#[serde(crate = "rocket::serde")] -pub struct Driver { - pub driver_ref: String, - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(rename = "permanent_number")] - pub number: Option, - pub code: Option, - #[serde(rename = "given_name")] - pub forename: String, - #[serde(rename = "family_name")] - pub surname: String, - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(rename = "date_of_birth")] - pub dob: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub nationality: Option, - pub url: String, -} - -#[derive(Debug, Serialize)] -#[serde(crate = "rocket::serde")] -pub struct Constructor { - pub constructor_ref: String, - pub name: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub nationality: Option, - pub url: String, -} - -#[derive(Debug, Serialize)] -#[serde(crate = "rocket::serde")] -pub struct Season { - pub year: i32, - pub url: String, -} - -#[derive(Debug, Serialize)] -#[serde(crate = "rocket::serde")] -pub struct DriverStanding { - pub driver: Driver, - pub points: f32, - pub wins: i32, - #[serde(skip_serializing_if = "Option::is_none")] - pub position: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub position_text: Option, -} - -#[derive(Debug, Serialize)] -#[serde(crate = "rocket::serde")] -pub struct ConstructorStanding { - pub constructor: Constructor, - pub points: f32, - pub wins: i32, - #[serde(skip_serializing_if = "Option::is_none")] - pub position: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub position_text: Option, - pub season: i32, - pub round: i32, -} diff --git a/crates/shared/src/parameters.rs b/crates/shared/src/parameters.rs index 0aa5a71..7a28a6d 100644 --- a/crates/shared/src/parameters.rs +++ b/crates/shared/src/parameters.rs @@ -2,8 +2,16 @@ use rocket::form::FromForm; use rocket::request::FromParam; - -pub use super::models::Series; +use serde::Serialize; + +#[derive(Debug, Default, Serialize, Clone, Copy)] +pub enum Series { + #[default] + #[serde(rename = "f1")] + F1, + #[serde(rename = "f2")] + F2, +} impl<'r> FromParam<'r> for Series { type Error = (); @@ -46,17 +54,15 @@ macros::query_parameters! { #[Copy] Page(u64); #[Copy] Limit(u64); DriverRef(String) => str; - #[Copy] DriverNumber(i32); ConstructorRef(String) => str; - Name(String) => str; - Circuit(String) => str; + CircuitRef(String) => str; + #[Copy] DriverStanding(i32); #[Copy] Grid(i32); #[Copy] RaceResult(i32); - #[Copy] ChampionshipResult(i32); #[Copy] Year(i32); #[Copy] Round(i32); - #[Copy] DriverId(i32); - #[Copy] RaceId(i32); + #[Copy] Fastest(i32); + #[Copy] Status(i32); } impl Year { @@ -72,8 +78,9 @@ macros::struct_parameters!( GetCircuitsParameter { driver_ref: DriverRef, constructor_ref: ConstructorRef, - circuit_ref: Circuit, + status: Status, grid: Grid, + fastest: Fastest, result: RaceResult, year: Year, round: Round, @@ -83,50 +90,19 @@ macros::struct_parameters!( ); macros::struct_parameters!( - DriverParameter { - driver_ref: DriverRef, - driver_number: DriverNumber, - constructor_ref: ConstructorRef, - circuit_ref: Circuit, - grid: Grid, - result: RaceResult, - limit: Limit, - page: Page - } => crate::filters::DriverFilter; - - ConstructorParameter { - driver_ref: DriverRef, - driver_number: DriverNumber, + GetDriversParameter { + circuit_ref: CircuitRef, constructor_ref: ConstructorRef, - circuit_ref: Circuit, + driver_standing: DriverStanding, + status: Status, grid: Grid, + fastest: Fastest, result: RaceResult, + year: Year, + round: Round, limit: Limit, page: Page - } => crate::filters::ConstructorFilter; - - DriverStandingParameter { - driver_ref: DriverRef, - result: ChampionshipResult, - limit: Limit, - page: Page - } => crate::filters::DriverStandingFilter; - - ConstructorStandingParameter { - constructor_ref: ConstructorRef, - result: ChampionshipResult, - limit: Limit, - page: Page - } => crate::filters::ConstructorStandingFilter; - - SeasonParameter { - limit: Limit, - page: Page, - driver_ref: DriverRef, - constructor_ref: ConstructorRef, - circuit_ref: Circuit, - grid: Grid - } => crate::filters::SeasonFilter; + } => crate::filters::GetDriversFilter; ); impl Default for Page { diff --git a/crates/shared/src/responses.rs b/crates/shared/src/responses.rs index 4a46e82..ad713eb 100644 --- a/crates/shared/src/responses.rs +++ b/crates/shared/src/responses.rs @@ -1,6 +1,15 @@ use rocket::serde::Serialize; -use super::prelude::*; +use crate::parameters::Series; + +#[derive(Debug, Serialize, Default)] +#[serde(crate = "rocket::serde")] +pub struct Pagination { + pub limit: u64, + pub page: u64, + pub max_page: u64, + pub total: u64, +} #[derive(Debug, Serialize)] #[serde(crate = "rocket::serde")] diff --git a/docker-compose.yml b/docker-compose.yml index 8a203e0..376b492 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,4 @@ --- -version: "3" - services: rust_race_engine_mysql_server: image: ergast_db