From 749271a0d5dba07a01c0e2c06d20337764f9b3c5 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Mon, 8 Jul 2024 01:51:58 +0000 Subject: [PATCH] added htmx request for albums --- artist-alerts/src/main.rs | 20 +++++++++++++++++++ .../templates/album_carousel_item.html | 11 ++++++++++ artist-alerts/templates/index.html | 5 ++++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 artist-alerts/templates/album_carousel_item.html diff --git a/artist-alerts/src/main.rs b/artist-alerts/src/main.rs index 53a6f48..8df8819 100644 --- a/artist-alerts/src/main.rs +++ b/artist-alerts/src/main.rs @@ -15,6 +15,14 @@ struct HelloTemplate { name: String } +#[derive(Template)] +#[template(path = "album_carousel_item.html")] +struct AlbumCarouselItem { + title: String, +} + + + #[tokio::main] async fn main() { tracing_subscriber::fmt::init(); @@ -25,6 +33,7 @@ async fn main() { let app = Router::new() .route("/", get(index)) .route("/users", post(create_user)) + .route("/album/highlights", get(highlight_albums)) .nest_service("/static", static_files_service) .layer(TraceLayer::new_for_http()) .with_state("Nick".to_string()) @@ -40,6 +49,17 @@ async fn index (axum::extract::State(name): axum::extract::State) -> Res } +async fn highlight_albums () -> String { + let mut output = String::new(); + for i in 1..=10 { + let item = AlbumCarouselItem { + title: format!("Album Item: {}", i.to_string()) + }; + output.push_str(&item.render().unwrap()); + } + output +} + async fn create_user( // this argument tells axum to parse the request body␍ // as JSON into a `CreateUser` type␍ diff --git a/artist-alerts/templates/album_carousel_item.html b/artist-alerts/templates/album_carousel_item.html new file mode 100644 index 0000000..a50d5d1 --- /dev/null +++ b/artist-alerts/templates/album_carousel_item.html @@ -0,0 +1,11 @@ +
+
+ + +
+
+

+ {{ title }} +

+
+
diff --git a/artist-alerts/templates/index.html b/artist-alerts/templates/index.html index 4e644ad..6abb52d 100644 --- a/artist-alerts/templates/index.html +++ b/artist-alerts/templates/index.html @@ -41,7 +41,10 @@
-
+