From 3e00aa5f3d1d4cb6ef8014d9a4fcf3a0e2827fd6 Mon Sep 17 00:00:00 2001 From: efim Date: Fri, 30 Jun 2023 03:44:41 +0000 Subject: [PATCH] feat(13): rest route get single testimonial card not ideal, that i need separate file, even though i can use the fragment from the main file. and having th:eac in same place as th:fragment means rendering that fragment and passing element over which i'm iterating doesn't help if collection is empty --- .../src/main/resources/templates/index.html | 1 + .../resources/templates/testimonialSection.html | 3 +++ .../src/main/scala/testimonialsgrid/Main.scala | 16 ++++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 13-testimonials-grid-section/src/main/resources/templates/testimonialSection.html diff --git a/13-testimonials-grid-section/src/main/resources/templates/index.html b/13-testimonials-grid-section/src/main/resources/templates/index.html index 3723d06..b0dc17c 100644 --- a/13-testimonials-grid-section/src/main/resources/templates/index.html +++ b/13-testimonials-grid-section/src/main/resources/templates/index.html @@ -34,6 +34,7 @@
+
diff --git a/13-testimonials-grid-section/src/main/scala/testimonialsgrid/Main.scala b/13-testimonials-grid-section/src/main/scala/testimonialsgrid/Main.scala index 37ed0fd..c6f6635 100644 --- a/13-testimonials-grid-section/src/main/scala/testimonialsgrid/Main.scala +++ b/13-testimonials-grid-section/src/main/scala/testimonialsgrid/Main.scala @@ -54,6 +54,22 @@ object Main { headers = Seq("Content-Type" -> "text/html;charset=UTF-8") ) } + @cask.get("/testimonial/:id") + def getTestimonial(id: Int) = { + val context = new Context() + val test = Testimonial.sameAsRequested.head + context.setVariable( + "selectedTestimonials", + List(test).asJava + ) + val result = templateEngine.process("testimonialSection", context) + println(s"will try with $test ; to get \n$result") + cask.Response( + result, + headers = Seq("Content-Type" -> "text/html;charset=UTF-8") + ) + } + @cask.staticFiles("/dist") def distFiles() = "dist" @cask.staticFiles("/public")