62 lines
1.4 KiB
Rust
62 lines
1.4 KiB
Rust
use askama::Template;
|
|
use axum::{extract::State, response::IntoResponse};
|
|
use futures::TryStreamExt;
|
|
use sqlx::SqlitePool;
|
|
|
|
use crate::{config::Config, somehow};
|
|
|
|
use super::{link::CommitLink, Base, Tab};
|
|
|
|
struct Ref {
|
|
name: String,
|
|
commit: CommitLink,
|
|
tracked: bool,
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "index.html")]
|
|
struct IndexTemplate {
|
|
base: Base,
|
|
tracked_refs: Vec<Ref>,
|
|
untracked_refs: Vec<Ref>,
|
|
}
|
|
|
|
pub async fn get(
|
|
State(config): State<&'static Config>,
|
|
State(db): State<SqlitePool>,
|
|
) -> somehow::Result<impl IntoResponse> {
|
|
let base = Base::new(config, Tab::Index);
|
|
|
|
let refs = sqlx::query!(
|
|
"\
|
|
SELECT name, hash, message, reachable, tracked \
|
|
FROM refs \
|
|
JOIN commits USING (hash) \
|
|
ORDER BY name ASC \
|
|
"
|
|
)
|
|
.fetch(&db)
|
|
.map_ok(|r| Ref {
|
|
name: r.name.clone(),
|
|
commit: CommitLink::new(&base, r.hash, &r.message, r.reachable),
|
|
tracked: r.tracked != 0,
|
|
})
|
|
.try_collect::<Vec<_>>()
|
|
.await?;
|
|
|
|
let mut tracked_refs = vec![];
|
|
let mut untracked_refs = vec![];
|
|
for reference in refs {
|
|
if reference.tracked {
|
|
tracked_refs.push(reference);
|
|
} else {
|
|
untracked_refs.push(reference);
|
|
}
|
|
}
|
|
|
|
Ok(IndexTemplate {
|
|
base: Base::new(config, Tab::Index),
|
|
tracked_refs,
|
|
untracked_refs,
|
|
})
|
|
}
|