Skip to content

Commit

Permalink
Remove optional query params
Browse files Browse the repository at this point in the history
  • Loading branch information
Suficio committed Oct 24, 2024
1 parent 12351b8 commit df413c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/registry_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl RegistryApi {
}

/// Fetch crates from the registry's API
pub(crate) async fn get_crates(&self, query: Option<&str>) -> Result<Search> {
pub(crate) async fn search(&self, query_params: &str) -> Result<Search> {
#[derive(Deserialize, Debug)]
struct SearchError {
detail: String,
Expand All @@ -267,7 +267,7 @@ impl RegistryApi {
url.path_segments_mut()
.map_err(|()| anyhow!("Invalid API url"))?
.extend(&["api", "v1", "crates"]);
url.set_query(query);
url.set_query(Some(query_params));
url
};

Expand Down
8 changes: 4 additions & 4 deletions src/web/releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ struct SearchResult {
async fn get_search_results(
conn: &mut sqlx::PgConnection,
registry: &RegistryApi,
query_params: Option<&str>,
query_params: &str,
) -> Result<SearchResult, anyhow::Error> {
let crate::registry_api::Search {
crates,
meta,
executed_query,
} = registry.get_crates(query_params).await?;
} = registry.search(query_params).await?;

let names = Arc::new(
crates
Expand Down Expand Up @@ -601,15 +601,15 @@ pub(crate) async fn search_handler(
sort_by = v;
};

get_search_results(&mut conn, &registry, Some(query_params)).await?
get_search_results(&mut conn, &registry, query_params).await?
} else if !query.is_empty() {
let query_params: String = form_urlencoded::Serializer::new(String::new())
.append_pair("q", &query)
.append_pair("sort", &sort_by)
.append_pair("per_page", &RELEASES_IN_RELEASES.to_string())
.finish();

get_search_results(&mut conn, &registry, Some(&query_params)).await?
get_search_results(&mut conn, &registry, &query_params).await?
} else {
return Err(AxumNope::NoResults);
};
Expand Down

0 comments on commit df413c0

Please sign in to comment.