Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

editoast: pluralize PaginationQueryParams #9930

Merged
merged 1 commit into from
Dec 3, 2024
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
6 changes: 3 additions & 3 deletions editoast/src/views/infra/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::models::infra::errors::Level;
use crate::models::prelude::*;
use crate::models::Infra;
use crate::views::infra::InfraIdParam;
use crate::views::pagination::PaginationQueryParam;
use crate::views::pagination::PaginationQueryParams;
use crate::views::pagination::PaginationStats;
use crate::views::AuthenticationExt;
use crate::views::AuthorizationError;
Expand Down Expand Up @@ -65,7 +65,7 @@ pub(in crate::views) struct InfraErrorResponse {
#[utoipa::path(
get, path = "",
tag = "infra",
params(InfraIdParam, PaginationQueryParam, ErrorListQueryParams),
params(InfraIdParam, PaginationQueryParams, ErrorListQueryParams),
responses(
(status = 200, body = inline(ErrorListResponse), description = "A paginated list of errors"),
),
Expand All @@ -74,7 +74,7 @@ async fn list_errors(
State(db_pool): State<DbConnectionPoolV2>,
Extension(auth): AuthenticationExt,
Path(InfraIdParam { infra_id }): Path<InfraIdParam>,
Query(pagination_params): Query<PaginationQueryParam>,
Query(pagination_params): Query<PaginationQueryParams>,
Query(ErrorListQueryParams {
level,
error_type,
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/views/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use crate::map;
use crate::models::prelude::*;
use crate::models::Infra;
use crate::views::pagination::PaginatedList as _;
use crate::views::pagination::PaginationQueryParam;
use crate::views::pagination::PaginationQueryParams;
use crate::views::AuthorizationError;
use crate::AppState;
use editoast_models::DbConnectionPoolV2;
Expand Down Expand Up @@ -195,15 +195,15 @@ struct InfraListResponse {
#[utoipa::path(
get, path = "",
tag = "infra",
params(PaginationQueryParam),
params(PaginationQueryParams),
responses(
(status = 200, description = "All infras, paginated", body = inline(InfraListResponse))
),
)]
async fn list(
app_state: State<AppState>,
Extension(auth): AuthenticationExt,
pagination_params: Query<PaginationQueryParam>,
pagination_params: Query<PaginationQueryParams>,
) -> Result<Json<InfraListResponse>> {
let authorized = auth
.check_roles([BuiltinRole::InfraRead].into())
Expand Down
14 changes: 7 additions & 7 deletions editoast/src/views/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub trait PaginatedList: ListAndCount + 'static {
/// before this function is called (e.g.: non-null page size).
/// 2. Panics if the limit or the offset of the `settings` are not set, so be
/// sure to call [SelectionSettings::from_pagination_settings] or [SelectionSettings::limit]
/// and [SelectionSettings::offset] beforehand. [PaginationQueryParam::into_selection_settings]
/// and [SelectionSettings::offset] beforehand. [PaginationQueryParams::into_selection_settings]
/// works as well.
async fn list_paginated(
conn: &mut DbConnection,
Expand All @@ -124,7 +124,7 @@ impl<T> PaginatedList for T where T: ListAndCount + 'static {}

#[derive(Debug, Clone, Copy, Deserialize, IntoParams)]
#[into_params(parameter_in = Query)]
pub struct PaginationQueryParam {
pub struct PaginationQueryParams {
#[serde(default = "default_page")]
#[param(minimum = 1, default = 1)]
pub page: u64,
Expand All @@ -136,14 +136,14 @@ const fn default_page() -> u64 {
1
}

impl PaginationQueryParam {
impl PaginationQueryParams {
/// Returns a pre-filled [SelectionSettings] from the pagination settings
/// that can then be used to list or count models
pub fn into_selection_settings<M: Model + 'static>(self) -> SelectionSettings<M> {
self.into()
}

pub fn validate(self, max_page_size: i64) -> Result<PaginationQueryParam> {
pub fn validate(self, max_page_size: i64) -> Result<PaginationQueryParams> {
let (page, page_size) = self.unpack();
if page_size > max_page_size || page_size < 1 || page < 1 {
return Err(PaginationError::InvalidPageSize {
Expand All @@ -155,7 +155,7 @@ impl PaginationQueryParam {
Ok(self)
}

pub fn warn_page_size(self, warn_page_size: i64) -> PaginationQueryParam {
pub fn warn_page_size(self, warn_page_size: i64) -> PaginationQueryParams {
let (_, page_size) = self.unpack();
if page_size > warn_page_size {
warn!(
Expand All @@ -172,8 +172,8 @@ impl PaginationQueryParam {
}
}

impl<M: Model + 'static> From<PaginationQueryParam> for SelectionSettings<M> {
fn from(PaginationQueryParam { page, page_size }: PaginationQueryParam) -> Self {
impl<M: Model + 'static> From<PaginationQueryParams> for SelectionSettings<M> {
fn from(PaginationQueryParams { page, page_size }: PaginationQueryParams) -> Self {
let page_size = page_size.unwrap_or(DEFAULT_PAGE_SIZE);
SelectionSettings::from_pagination_settings(page, page_size)
}
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/views/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::models::Document;
use crate::models::Model;
use crate::models::Project;
use crate::models::Retrieve;
use crate::views::pagination::PaginationQueryParam;
use crate::views::pagination::PaginationQueryParams;
use crate::views::AuthorizationError;

crate::routes! {
Expand Down Expand Up @@ -181,15 +181,15 @@ struct ProjectWithStudyCountList {
#[utoipa::path(
get, path = "",
tag = "projects",
params(PaginationQueryParam, OperationalStudiesOrderingParam),
params(PaginationQueryParams, OperationalStudiesOrderingParam),
responses(
(status = 200, body = inline(ProjectWithStudyCountList), description = "The list of projects"),
)
)]
async fn list(
State(db_pool): State<DbConnectionPoolV2>,
Extension(auth): AuthenticationExt,
Query(pagination_params): Query<PaginationQueryParam>,
Query(pagination_params): Query<PaginationQueryParams>,
Query(ordering_params): Query<OperationalStudiesOrderingParam>,
) -> Result<Json<ProjectWithStudyCountList>> {
let authorized = auth
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/views/rolling_stock/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::models::rolling_stock_livery::RollingStockLiveryModel;
use crate::models::Retrieve;
use crate::models::RollingStockModel;
use crate::views::pagination::PaginatedList;
use crate::views::pagination::PaginationQueryParam;
use crate::views::pagination::PaginationQueryParams;
use crate::views::pagination::PaginationStats;
use crate::List;
use crate::SelectionSettings;
Expand Down Expand Up @@ -98,15 +98,15 @@ struct LightRollingStockWithLiveriesCountList {
#[utoipa::path(
get, path = "",
tag = "rolling_stock",
params(PaginationQueryParam),
params(PaginationQueryParams),
responses(
(status = 200, body = inline(LightRollingStockWithLiveriesCountList)),
)
)]
async fn list(
State(db_pool): State<DbConnectionPoolV2>,
Extension(auth): AuthenticationExt,
Query(page_settings): Query<PaginationQueryParam>,
Query(page_settings): Query<PaginationQueryParams>,
) -> Result<Json<LightRollingStockWithLiveriesCountList>> {
let authorized = auth
.check_roles([BuiltinRole::RollingStockCollectionRead].into())
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/views/rolling_stock/towed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::error::Result;
use crate::models::prelude::*;
use crate::models::towed_rolling_stock::TowedRollingStockModel;
use crate::views::pagination::PaginatedList;
use crate::views::pagination::PaginationQueryParam;
use crate::views::pagination::PaginationQueryParams;
use crate::views::pagination::PaginationStats;
use crate::views::AuthenticationExt;
use crate::views::AuthorizationError;
Expand Down Expand Up @@ -166,15 +166,15 @@ struct TowedRollingStockCountList {
#[utoipa::path(
get, path = "",
tag = "rolling_stock",
params(PaginationQueryParam),
params(PaginationQueryParams),
responses(
(status = 200, body = inline(TowedRollingStockCountList)),
)
)]
async fn get_list(
State(db_pool): State<DbConnectionPoolV2>,
Extension(auth): AuthenticationExt,
Query(page_settings): Query<PaginationQueryParam>,
Query(page_settings): Query<PaginationQueryParams>,
) -> Result<Json<TowedRollingStockCountList>> {
let authorized = auth
.check_roles([BuiltinRole::RollingStockCollectionRead].into())
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/views/scenario.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::models::Study;
use crate::models::Tags;
use crate::views::operational_studies::OperationalStudiesOrderingParam;
use crate::views::pagination::PaginatedList as _;
use crate::views::pagination::PaginationQueryParam;
use crate::views::pagination::PaginationQueryParams;
use crate::views::pagination::PaginationStats;
use crate::views::projects::ProjectError;
use crate::views::projects::ProjectIdParam;
Expand Down Expand Up @@ -474,7 +474,7 @@ struct ListScenariosResponse {
#[utoipa::path(
get, path = "",
tag = "scenarios",
params(ProjectIdParam, StudyIdParam, PaginationQueryParam, OperationalStudiesOrderingParam),
params(ProjectIdParam, StudyIdParam, PaginationQueryParams, OperationalStudiesOrderingParam),
responses(
(status = 200, description = "A paginated list of scenarios", body = inline(ListScenariosResponse)),
(status = 404, description = "Project or study doesn't exist")
Expand All @@ -484,7 +484,7 @@ async fn list(
State(db_pool): State<DbConnectionPoolV2>,
Extension(auth): AuthenticationExt,
Path((project_id, study_id)): Path<(i64, i64)>,
Query(pagination_params): Query<PaginationQueryParam>,
Query(pagination_params): Query<PaginationQueryParams>,
Query(OperationalStudiesOrderingParam { ordering }): Query<OperationalStudiesOrderingParam>,
) -> Result<Json<ListScenariosResponse>> {
let authorized = auth
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/views/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ use std::collections::HashSet;
use utoipa::ToSchema;

use crate::error::Result;
use crate::views::pagination::PaginationQueryParam;
use crate::views::pagination::PaginationQueryParams;
use crate::views::AuthenticationExt;
use crate::views::AuthorizationError;
use editoast_models::DbConnectionPoolV2;
Expand Down Expand Up @@ -338,7 +338,7 @@ struct SearchDBResult {
#[utoipa::path(
post, path = "",
tag = "search",
params(PaginationQueryParam),
params(PaginationQueryParams),
request_body = SearchPayload,
responses(
(status = 200, body = Vec<SearchResultItem>, description = "The search results"),
Expand All @@ -347,7 +347,7 @@ struct SearchDBResult {
async fn search(
State(db_pool): State<DbConnectionPoolV2>,
Extension(auth): AuthenticationExt,
Query(query_params): Query<PaginationQueryParam>,
Query(query_params): Query<PaginationQueryParams>,
Json(SearchPayload { object, query, dry }): Json<SearchPayload>,
) -> Result<Json<serde_json::Value>> {
let roles: HashSet<BuiltinRole> = match object.as_str() {
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/views/study.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::models::Project;
use crate::models::Study;
use crate::models::Tags;
use crate::views::pagination::PaginatedList as _;
use crate::views::pagination::PaginationQueryParam;
use crate::views::pagination::PaginationQueryParams;
use crate::views::projects::ProjectError;
use crate::views::projects::ProjectIdParam;

Expand Down Expand Up @@ -396,7 +396,7 @@ struct StudyListResponse {
#[utoipa::path(
get, path = "",
tag = "studies",
params(ProjectIdParam, PaginationQueryParam, OperationalStudiesOrderingParam),
params(ProjectIdParam, PaginationQueryParams, OperationalStudiesOrderingParam),
responses(
(status = 200, body = inline(StudyListResponse), description = "The list of studies"),
)
Expand All @@ -405,7 +405,7 @@ async fn list(
State(db_pool): State<DbConnectionPoolV2>,
Extension(auth): AuthenticationExt,
Path(project_id): Path<i64>,
Query(pagination_params): Query<PaginationQueryParam>,
Query(pagination_params): Query<PaginationQueryParams>,
Query(ordering_params): Query<OperationalStudiesOrderingParam>,
) -> Result<Json<StudyListResponse>> {
let authorized = auth
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/views/work_schedules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::models::work_schedules::WorkSchedule;
use crate::models::work_schedules::WorkScheduleGroup;
use crate::models::work_schedules::WorkScheduleType;
use crate::views::operational_studies::Ordering;
use crate::views::pagination::PaginationQueryParam;
use crate::views::pagination::PaginationQueryParams;
use crate::views::pagination::PaginationStats;
use crate::views::path::projection::Intersection;
use crate::views::path::projection::PathProjection;
Expand Down Expand Up @@ -472,7 +472,7 @@ pub struct WorkScheduleOrderingParam {
#[utoipa::path(
get, path = "",
tag = "work_schedules",
params(PaginationQueryParam, WorkScheduleGroupIdParam, WorkScheduleOrderingParam),
params(PaginationQueryParams, WorkScheduleGroupIdParam, WorkScheduleOrderingParam),
responses(
(status = 200, description = "The work schedules in the group", body = inline(GroupContentResponse)),
(status = 404, description = "Work schedule group not found"),
Expand All @@ -482,7 +482,7 @@ async fn get_group(
State(db_pool): State<DbConnectionPoolV2>,
Extension(auth): AuthenticationExt,
Path(WorkScheduleGroupIdParam { id: group_id }): Path<WorkScheduleGroupIdParam>,
Query(pagination_params): Query<PaginationQueryParam>,
Query(pagination_params): Query<PaginationQueryParams>,
Query(ordering_params): Query<WorkScheduleOrderingParam>,
) -> Result<Json<GroupContentResponse>> {
let authorized = auth
Expand Down
Loading