Skip to content

Commit

Permalink
Use new db::list_crates() in handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
onelson committed Jun 7, 2021
1 parent efe1cc4 commit 4f0420a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,13 @@ pub(crate) fn list_crates(
) -> crate::Result<Vec<(String, String, DateTime<Utc>)>> {
let mut stmt = conn.prepare(
r#"
SELECT cv.vers, c.name, cv.created
SELECT c.name, cv.vers, cv.created
FROM crate_versions as cv
JOIN crates c on cv.crate_id = c.id
WHERE cv.yanked = false
GROUP BY cv.crate_id
HAVING max(cv.vers)
ORDER BY c.name
"#,
)?;

Expand Down
13 changes: 7 additions & 6 deletions src/handlers/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) async fn styles(_req: HttpRequest) -> HttpResponse {
#[template(path = "landing.html")]
pub(crate) struct LandingTemplate<'a> {
title: &'a str,
packages: Vec<String>,
packages: Vec<(String, String, String)>,
}

#[derive(Template)]
Expand All @@ -45,13 +45,14 @@ pub(crate) struct CrateDetailTemplate {
pub(crate) async fn landing(settings: web::Data<Settings>) -> Result<LandingTemplate<'static>> {
// FIXME: read from database

let index = index.lock().unwrap();
let mut names = index.list_crates()?;
names.sort();

let mut db = settings.get_db()?;
let packages = crate::database::list_crates(&mut db)?
.into_iter()
.map(|(n, v, d)| (n, v, d.to_string()))
.collect();
Ok(LandingTemplate {
title: "Crate List",
packages: names,
packages,
})
}

Expand Down
2 changes: 1 addition & 1 deletion templates/landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<header><span class="text-2xl text-gray-900">Crates</span></header>
<ul>
{% for pkg in packages %}
<li><a class="underline" href="/crates/{{pkg}}">{{ pkg }}</a></li>
<li><a class="underline" href="/crates/{{pkg.0}}/{{pkg.1}}">{{ pkg.0 }} v{{pkg.1}}</a></li>
{% endfor %}
</ul>
{% endblock %}

0 comments on commit 4f0420a

Please sign in to comment.