diff --git a/src/bin/web.rs b/src/bin/web.rs index 76c03d2..6f2ed1a 100644 --- a/src/bin/web.rs +++ b/src/bin/web.rs @@ -24,7 +24,7 @@ use flake_tracker::{ Storage, }, templates::{ - FlakeInfoTemplate, + FlakeTemplate, FlakesTemplate, IndexTemplate, RevisionTemplate, @@ -91,7 +91,7 @@ async fn main() -> anyhow::Result<()> { let app = Router::new() .route("/", get(route_index)) .route("/flakes", get(route_flakes)) - .route("/f/{uri}", get(route_flake_info)) + .route("/f/{uri}", get(route_flake)) .route("/r/{revision_uri}", get(route_revision)) .with_state(state); @@ -118,13 +118,13 @@ async fn route_flakes( })?) } -async fn route_flake_info( +async fn route_flake( State(state): State, Path(uri): Path, ) -> Result { - Ok(render_template(&FlakeInfoTemplate { + Ok(render_template(&FlakeTemplate { uri: uri.clone(), - flake_revisions: state.storage.revisions_from_flake(&uri).await?, + revisions: state.storage.revisions_from_flake(&uri).await?, })?) } diff --git a/src/storage.rs b/src/storage.rs index 9fed326..c54d998 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -46,17 +46,23 @@ impl Storage { .context("Failed to fetch data from database") } - pub async fn revisions_from_flake(&self, uri: &str) -> Result> { + pub async fn revisions_from_flake(&self, uri: &str) -> Result> { sqlx::query_as(" SELECT revision_uri, - revision, last_modified FROM flake_revisions WHERE uri = ? + UNION + SELECT + revision_uri, + last_modified + FROM flake_revisions_inputs + WHERE uri = ? ORDER BY last_modified ") .bind(&uri) + .bind(&uri) .fetch_all(&self.db) .await .context("Failed to fetch data from database") @@ -93,13 +99,12 @@ pub struct FlakeRevisionRow { } #[derive(FromRow)] -pub struct FlakeRevision { +pub struct RevisionListModel { pub revision_uri: String, - pub revision: String, pub last_modified: i64, } -impl FlakeRevision { +impl RevisionListModel { pub fn link(&self ) -> String { format!("/r/{}", urlencode(&self.revision_uri)) } diff --git a/src/templates.rs b/src/templates.rs index 8b8dfd4..4df8ec7 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -3,9 +3,9 @@ use askama::{ }; use crate::{ storage::{ - FlakeRevision, FlakeUri, InputModel, + RevisionListModel, }, }; @@ -21,10 +21,10 @@ pub struct FlakesTemplate { } #[derive(Template)] -#[template(path = "flake-info.html")] -pub struct FlakeInfoTemplate { +#[template(path = "flake.html")] +pub struct FlakeTemplate { pub uri: String, - pub flake_revisions: Vec, + pub revisions: Vec, } #[derive(Template)] diff --git a/templates/flake-info.html b/templates/flake.html similarity index 51% rename from templates/flake-info.html rename to templates/flake.html index 9b261ed..5a9fb5d 100644 --- a/templates/flake-info.html +++ b/templates/flake.html @@ -10,8 +10,8 @@

Revisions

{% endblock %}