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

fix: Fix regression with pagination (DEV-4624) #320

Closed
wants to merge 1 commit into from
Closed
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
40 changes: 39 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ anyhow = "1"
async-trait = "0.1.86"
axum = "0.8.1" # web framework
axum-macros = "0.5.0"
axum-extra = { version = "0.10.0", features = ["query"] }
clap = { version = "4.5.30", features = ["derive"] } # command-line parser
config = "0.15.8" # Layered configuration with strong support for 12-factor applications
chrono = { version = "0.4.39", features = ["serde"] }
Expand Down
13 changes: 7 additions & 6 deletions src/api/handler/v1/projects/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use std::sync::Arc;

use axum::extract::{Path, Query, State};
use axum::extract::{Path, State};
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use axum::Json;
use axum_extra::extract::OptionalQuery;
use tracing::{instrument, trace};

use crate::api::handler::v1::projects::responses::{
ProjectMetadataDto, ProjectMetadataWithInfoDto,
};
use crate::app_state::AppState;
use crate::domain::metadata_repository::{OptionalFilter, OptionalPagination};
use crate::domain::metadata_repository::{Filter, Pagination};
use crate::domain::model::draft_model::Shortcode;
use crate::error::DspMetaError;

Expand Down Expand Up @@ -41,12 +42,12 @@ pub async fn get_by_shortcode(
#[axum_macros::debug_handler]
pub async fn get_by_page_and_filter(
State(state): State<Arc<AppState>>,
pagination: Query<OptionalPagination>,
filter: Query<OptionalFilter>,
pagination: OptionalQuery<Pagination>,
filter: OptionalQuery<Filter>,
) -> Result<Response, DspMetaError> {
trace!("entered get_all_project_metadata()");
let pagination = pagination.0.or_default();
let filter = filter.0.or_default();
let pagination = pagination.0.unwrap_or_default();
let filter = filter.0.unwrap_or_default();
let page = state.metadata_service.find(&filter, &pagination)?;
let mut response = Json(
page.data
Expand Down
24 changes: 0 additions & 24 deletions src/domain/metadata_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ impl Default for Pagination {
}
}

#[derive(Debug, Deserialize, Default, Clone)]
pub struct OptionalPagination {
#[serde(flatten)]
pub pagination: Option<Pagination>,
}

impl OptionalPagination {
pub fn or_default(&self) -> Pagination {
self.pagination.clone().unwrap_or_default()
}
}

#[derive(Deserialize, Default, Debug, Clone)]
pub struct Filter {
#[serde(rename = "q")]
Expand All @@ -47,18 +35,6 @@ pub struct Filter {
pub filter: Option<String>,
}

#[derive(Debug, Deserialize, Default, Clone)]
pub struct OptionalFilter {
#[serde(flatten)]
pub filter: Option<Filter>,
}

impl OptionalFilter {
pub fn or_default(&self) -> Filter {
self.filter.clone().unwrap_or_default()
}
}

pub struct Page<T> {
pub data: Vec<T>,
pub total: usize,
Expand Down
Loading