feat(14): template in showdown-table, show choice

This commit is contained in:
efim
2023-07-01 14:20:52 +00:00
parent 69a464a767
commit 66013ae1c6
3 changed files with 22 additions and 6 deletions

View File

@@ -8,6 +8,9 @@ import org.thymeleaf.TemplateEngine
import org.thymeleaf.Thymeleaf
import scala.jdk.CollectionConverters._
import javax.swing.text.Position
import rockpaperscissors.Models.Positioning
import scala.util.Random
object Main {
@main def run(
@@ -62,11 +65,21 @@ object Main {
@cask.get("/select/:choice")
def acceptPlayerVote(choice: String) = {
val context = new Context()
val result = templateEngine.process("showdown", Set("showdown-table").asJava, context)
cask.Response(
result,
headers = Seq("Content-Type" -> "text/html;charset=UTF-8")
)
val badge = Models.choiceSelectionItems.find(_.c.name == choice)
val response = badge match {
case Some(playersChoiceBadge) =>
val badge = playersChoiceBadge.copy()
badge.p = Positioning.Relative
context.setVariable("playersChoiceData", badge)
val result = templateEngine.process("showdown", Set("showdown-table").asJava, context)
cask.Response(
result,
headers = Seq("Content-Type" -> "text/html;charset=UTF-8")
)
case None =>
cask.Response(s"Unknown choice: '${choice}'", 400)
}
response
}
@cask.staticResources("/public")