Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Pass clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
AOx0 committed Sep 12, 2023
1 parent 70e95ae commit 0832497
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/bin/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ struct Content {

struct Section {
name: &'static str,
href: &'static str
href: &'static str,
}

#[derive(Template)]
#[template(path = "hello.html")]
struct Hello<'a> {
posts: &'a [Content],
sects: &'a [Section]
sects: &'a [Section],
}

async fn root() -> Hello<'static> {
Expand Down Expand Up @@ -72,12 +72,10 @@ async fn root() -> Hello<'static> {
method: "/date/upnow",
},
],
sects: &[
Section {
name: "Zonas calientes",
href: "#"
}
]
sects: &[Section {
name: "Zonas calientes",
href: "#",
}],
}
}

Expand Down Expand Up @@ -161,7 +159,7 @@ fn max_year() -> u16 {
2023
}

/// TODO: This seems expensive, benchmark and optimize
/// TODO: This seems expensive, benchmark and optimize
///
/// # Panics
///
Expand All @@ -182,8 +180,8 @@ async fn mapa_porcentajes(
.await
.unwrap()
} else {
sqlx::query_as(&format!("SELECT COUNT(1) FROM delitos WHERE delitos.id_categoria IN ({0}) AND fecha_hecho BETWEEN '{annio_inicio}-01-01' AND '{annio_final}-12-31';",
categorias
sqlx::query_as(&format!("SELECT COUNT(1) FROM delitos WHERE delitos.id_categoria IN ({0}) AND fecha_hecho BETWEEN '{annio_inicio}-01-01' AND '{annio_final}-12-31';",
categorias
.iter()
.map(|id| format!("{id}"))
.collect::<Vec<_>>()
Expand All @@ -193,15 +191,15 @@ async fn mapa_porcentajes(
.await
.unwrap()
};

let resultados: Vec<(i64,)> = if categorias.is_empty() {
sqlx::query_as(&format!("SELECT COUNT(1) FROM delitos WHERE fecha_hecho BETWEEN '{annio_inicio}-01-01' AND '{annio_final}-12-31' AND delitos.id_alcaldia_hecho IS NOT NULL GROUP BY delitos.id_alcaldia_hecho ORDER BY delitos.id_alcaldia_hecho;"))
.fetch_all(&state.db)
.await
.unwrap()
} else {
sqlx::query_as(&format!("SELECT COUNT(1) FROM delitos WHERE delitos.id_categoria IN ({0}) AND fecha_hecho BETWEEN '{annio_inicio}-01-01' AND '{annio_final}-12-31' AND delitos.id_alcaldia_hecho IS NOT NULL GROUP BY delitos.id_alcaldia_hecho ORDER BY delitos.id_alcaldia_hecho;",
categorias
sqlx::query_as(&format!("SELECT COUNT(1) FROM delitos WHERE delitos.id_categoria IN ({0}) AND fecha_hecho BETWEEN '{annio_inicio}-01-01' AND '{annio_final}-12-31' AND delitos.id_alcaldia_hecho IS NOT NULL GROUP BY delitos.id_alcaldia_hecho ORDER BY delitos.id_alcaldia_hecho;",
categorias
.iter()
.map(|id| format!("{id}"))
.collect::<Vec<_>>()
Expand All @@ -212,9 +210,6 @@ async fn mapa_porcentajes(
.unwrap()
};




MapaPorcetajes {
total: u64::try_from(total).unwrap(),
valores: resultados.into_iter().map(|(n,)| n as u64).collect(),
Expand Down

0 comments on commit 0832497

Please sign in to comment.