Display flake details
This commit is contained in:
@@ -4,6 +4,7 @@ use anyhow::{
|
||||
use askama::Template;
|
||||
use axum::{
|
||||
extract::{
|
||||
Path,
|
||||
State,
|
||||
},
|
||||
http::{
|
||||
@@ -20,9 +21,11 @@ use axum::{
|
||||
};
|
||||
use flake_tracker::{
|
||||
storage::{
|
||||
FlakeRevision,
|
||||
FlakeUri,
|
||||
},
|
||||
templates::{
|
||||
FlakeInfoTemplate,
|
||||
FlakesTemplate,
|
||||
IndexTemplate,
|
||||
},
|
||||
@@ -93,6 +96,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
let mut app = Router::new()
|
||||
.route("/", get(route_index))
|
||||
.route("/flakes", get(route_flakes))
|
||||
.route("/f/{uri}", get(route_flake_info))
|
||||
.with_state(state);
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("[::]:3000")
|
||||
@@ -130,3 +134,27 @@ async fn route_flakes(
|
||||
flakes: flake_revisions,
|
||||
})?)
|
||||
}
|
||||
|
||||
async fn route_flake_info(
|
||||
State(state): State<AppState>,
|
||||
Path(uri): Path<String>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
let flake_revisions: Vec<FlakeRevision> = sqlx::query_as("
|
||||
SELECT
|
||||
revision_uri,
|
||||
revision,
|
||||
last_modified
|
||||
FROM flake_revisions
|
||||
WHERE uri = ?
|
||||
ORDER BY last_modified
|
||||
")
|
||||
.bind(&uri)
|
||||
.fetch_all(&state.db)
|
||||
.await
|
||||
.context("Failed to fetch data from database")?;
|
||||
|
||||
Ok(render_template(&FlakeInfoTemplate {
|
||||
uri: uri,
|
||||
flake_revisions: flake_revisions,
|
||||
})?)
|
||||
}
|
||||
|
Reference in New Issue
Block a user