Skip to content

Commit

Permalink
Merge pull request #10 from leirn/#4---page-parameter
Browse files Browse the repository at this point in the history
Implement usage of page parameter
  • Loading branch information
leirn authored Jan 17, 2024
2 parents 864540d + 0e777ee commit 1bce697
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/app/navdata/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub async fn get_navaid_by_id(

pub async fn search_navaid(
search: Option<String>,
_page: Option<u32>,
page: Option<u32>,
country: Option<String>,
navaid_type: Option<String>,
app_state: web::Data<AppState>,
Expand Down Expand Up @@ -194,7 +194,10 @@ pub async fn search_navaid(
}
query.push_str(" (icao_code LIKE '%' || ? || '%' OR name LIKE '%' || ? || '%' OR associated_airport LIKE '%' || ? || '%')");
}
query.push_str(" LIMIT 100");
match page {
Some(page) => query.push_str(format!(" LIMIT {}, 100", page * 100).as_str()),
None => query.push_str(" LIMIT 100"),
};

// Build and fill the statement
let mut statement = con.prepare(query)?;
Expand Down Expand Up @@ -236,7 +239,7 @@ pub async fn search_navaid(

pub async fn search_airport(
search: Option<String>,
_page: Option<u32>,
page: Option<u32>,
country: Option<String>,
airport_type: Option<String>,
app_state: web::Data<AppState>,
Expand Down Expand Up @@ -272,7 +275,10 @@ pub async fn search_airport(
}
query.push_str(" (icao_code LIKE '%' || ? || '%' OR name LIKE '%' || ? || '%' OR municipality LIKE '%' || ? || '%' OR iata_code LIKE '%' || ? || '%')");
}
query.push_str(" LIMIT 100");
match page {
Some(page) => query.push_str(format!(" LIMIT {}, 100", page * 100).as_str()),
None => query.push_str(" LIMIT 100"),
};

// Build and fill the statement
let mut statement = con.prepare(query)?;
Expand Down

0 comments on commit 1bce697

Please sign in to comment.