Skip to content

Commit

Permalink
Return releases orderd by created_at when q param is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
sestrella committed Apr 22, 2024
1 parent bb00fcc commit 35f926e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions backend-rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async fn get_flake(
State(state): State<Arc<AppState>>,
Query(params): Query<HashMap<String, String>>,
) -> Result<Json<Vec<Release>>, AppError> {
if let Some(q) = params.get("q") {
let releases = if let Some(q) = params.get("q") {
let response = &state
.opensearch
.search(SearchParts::Index(&["opensearch_index"]))
Expand Down Expand Up @@ -104,14 +104,19 @@ async fn get_flake(
hit["_score"].as_i64().unwrap(),
);
}
// TODO: This query is actually a join between different tables
let mut releases = sqlx::query_as::<_, Release>("SELECT * FROM release WHERE id IN (?)")
.bind(hits.keys().cloned().collect::<Vec<i64>>())
.fetch_all(&state.pool)
.await?;
releases.sort_by(|a, b| hits[&b.id].cmp(&hits[&a.id]));
return Ok(Json(releases));
}
todo!()
releases
} else {
sqlx::query_as::<_, Release>("SELECT * FROM release ORDER BY created_at LIMIT 100")
.fetch_all(&state.pool)
.await?
};
return Ok(Json(releases));
}

async fn post_publish() -> &'static str {
Expand Down

0 comments on commit 35f926e

Please sign in to comment.