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.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 com.linecorp.armeria.server.annotation.{Get, Post, Param}
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
object TaskController:
|
object TaskController:
|
||||||
|
|
||||||
private val titleForm = mapping[String]("title" -> text)
|
private val titleField = Mapping("title", text)
|
||||||
|
|
||||||
@Get("/health")
|
@Get("/health")
|
||||||
def health = Action: request =>
|
def health = Action: _ =>
|
||||||
Ok("""{"status":"ok"}""").as("application/json")
|
Ok("""{"status":"ok"}""").as(MediaType.JSON)
|
||||||
|
|
||||||
@Get("/")
|
@Get("/")
|
||||||
def index = Action: request =>
|
def index = Action: _ =>
|
||||||
Ok(renderPage()).as("text/html; charset=utf-8")
|
Ok(renderPage()).as(MediaType.HTML_UTF_8)
|
||||||
|
|
||||||
@Post("/tasks")
|
@Post("/tasks")
|
||||||
def create = Action: implicit request =>
|
def create = Action: request =>
|
||||||
titleForm.bindFromRequest().fold(
|
val bound = titleField.bindFromRequest()(using request)
|
||||||
_ => Redirect("/"),
|
if bound.hasErrors then Redirect("/")
|
||||||
title =>
|
else
|
||||||
if title.trim.nonEmpty then TaskStore.add(title)
|
val title = bound.typedValueOpt.get
|
||||||
Redirect("/")
|
if title.trim.nonEmpty then TaskStore.add(title)
|
||||||
)
|
Redirect("/")
|
||||||
|
|
||||||
@Post("/tasks/:id/toggle")
|
@Post("/tasks/:id/toggle")
|
||||||
def toggle(@Param id: String) = Action: request =>
|
def toggle(@Param id: String) = Action: _ =>
|
||||||
try TaskStore.toggle(UUID.fromString(id))
|
try TaskStore.toggle(UUID.fromString(id))
|
||||||
catch case _: IllegalArgumentException => ()
|
catch case _: IllegalArgumentException => ()
|
||||||
Redirect("/")
|
Redirect("/")
|
||||||
|
|
||||||
@Post("/tasks/:id/delete")
|
@Post("/tasks/:id/delete")
|
||||||
def delete(@Param id: String) = Action: request =>
|
def delete(@Param id: String) = Action: _ =>
|
||||||
try TaskStore.delete(UUID.fromString(id))
|
try TaskStore.delete(UUID.fromString(id))
|
||||||
catch case _: IllegalArgumentException => ()
|
catch case _: IllegalArgumentException => ()
|
||||||
Redirect("/")
|
Redirect("/")
|
||||||
|
|||||||
Reference in New Issue
Block a user