fix: correct Thorium API usage
- Import Mapping.* instead of data.mapping.* (mapping/text live in companion object)
- Use Mapping("field", text) for single-field binding instead of mapping[String]
- Pass request explicitly: bindFromRequest()(using request)
- Replace .as(String) with .as(MediaType.JSON) / .as(MediaType.HTML_UTF_8)
- Remove 'implicit' from Action lambda (Scala 3 uses 'using' instead)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,37 +1,39 @@
|
||||
import com.greenfossil.thorium.{*, given}
|
||||
import com.greenfossil.data.mapping.{*, given}
|
||||
import com.greenfossil.data.mapping.Mapping
|
||||
import com.greenfossil.data.mapping.Mapping.*
|
||||
import com.linecorp.armeria.common.MediaType
|
||||
import com.linecorp.armeria.server.annotation.{Get, Post, Param}
|
||||
import java.util.UUID
|
||||
|
||||
object TaskController:
|
||||
|
||||
private val titleForm = mapping[String]("title" -> text)
|
||||
private val titleField = Mapping("title", text)
|
||||
|
||||
@Get("/health")
|
||||
def health = Action: request =>
|
||||
Ok("""{"status":"ok"}""").as("application/json")
|
||||
def health = Action: _ =>
|
||||
Ok("""{"status":"ok"}""").as(MediaType.JSON)
|
||||
|
||||
@Get("/")
|
||||
def index = Action: request =>
|
||||
Ok(renderPage()).as("text/html; charset=utf-8")
|
||||
def index = Action: _ =>
|
||||
Ok(renderPage()).as(MediaType.HTML_UTF_8)
|
||||
|
||||
@Post("/tasks")
|
||||
def create = Action: implicit request =>
|
||||
titleForm.bindFromRequest().fold(
|
||||
_ => Redirect("/"),
|
||||
title =>
|
||||
def create = Action: request =>
|
||||
val bound = titleField.bindFromRequest()(using request)
|
||||
if bound.hasErrors then Redirect("/")
|
||||
else
|
||||
val title = bound.typedValueOpt.get
|
||||
if title.trim.nonEmpty then TaskStore.add(title)
|
||||
Redirect("/")
|
||||
)
|
||||
|
||||
@Post("/tasks/:id/toggle")
|
||||
def toggle(@Param id: String) = Action: request =>
|
||||
def toggle(@Param id: String) = Action: _ =>
|
||||
try TaskStore.toggle(UUID.fromString(id))
|
||||
catch case _: IllegalArgumentException => ()
|
||||
Redirect("/")
|
||||
|
||||
@Post("/tasks/:id/delete")
|
||||
def delete(@Param id: String) = Action: request =>
|
||||
def delete(@Param id: String) = Action: _ =>
|
||||
try TaskStore.delete(UUID.fromString(id))
|
||||
catch case _: IllegalArgumentException => ()
|
||||
Redirect("/")
|
||||
|
||||
Reference in New Issue
Block a user