parent
d235451f07
commit
8e4b400193
@ -0,0 +1,25 @@
|
||||
package wanijo.wanijo2.domain.event
|
||||
|
||||
import jakarta.validation.constraints.Min
|
||||
import jakarta.validation.constraints.NotEmpty
|
||||
import wanijo.wanijo2.domain.Document
|
||||
import wanijo.wanijo2.domain.DocumentDescription
|
||||
import wanijo.wanijo2.domain.DocumentId
|
||||
import wanijo.wanijo2.domain.DocumentName
|
||||
|
||||
data class EditDocumentCommand(
|
||||
@Min(0)
|
||||
val id: DocumentId,
|
||||
@NotEmpty
|
||||
val name: DocumentName,
|
||||
val description: DocumentDescription
|
||||
) {
|
||||
companion object {
|
||||
fun fromDocument(doc: Document) =
|
||||
EditDocumentCommand(
|
||||
id = doc.id,
|
||||
name = doc.name,
|
||||
description = doc.description
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package wanijo.wanijo2.domain.handler
|
||||
|
||||
import org.springframework.stereotype.Service
|
||||
import wanijo.wanijo2.domain.DocumentDao
|
||||
import wanijo.wanijo2.domain.event.EditDocumentCommand
|
||||
|
||||
@Service
|
||||
class EditDocumentHandler(
|
||||
val documentDao: DocumentDao
|
||||
) {
|
||||
|
||||
fun exec(command: EditDocumentCommand) {
|
||||
documentDao.edit(
|
||||
id = command.id,
|
||||
name = command.name,
|
||||
description = command.description
|
||||
)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package wanijo.wanijo2.http.controller
|
||||
|
||||
import jakarta.validation.Valid
|
||||
import org.springframework.stereotype.Controller
|
||||
import org.springframework.ui.Model
|
||||
import org.springframework.ui.set
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import wanijo.wanijo2.domain.DocumentDao
|
||||
import wanijo.wanijo2.domain.DocumentId
|
||||
import wanijo.wanijo2.domain.event.EditDocumentCommand
|
||||
import wanijo.wanijo2.domain.handler.EditDocumentHandler
|
||||
|
||||
@Controller
|
||||
class EditController(
|
||||
val documentDao: DocumentDao,
|
||||
val editDocumentHandler: EditDocumentHandler
|
||||
) {
|
||||
|
||||
@GetMapping("/document/{id}/edit")
|
||||
fun edit(
|
||||
@PathVariable
|
||||
id: DocumentId,
|
||||
model: Model
|
||||
): String {
|
||||
val doc = documentDao.findById(id)!!
|
||||
model["form"] = EditDocumentCommand.fromDocument(doc)
|
||||
|
||||
return "edit"
|
||||
}
|
||||
|
||||
@PostMapping("/document/edit")
|
||||
fun edit(
|
||||
@Valid
|
||||
command: EditDocumentCommand
|
||||
): String {
|
||||
editDocumentHandler.exec(command)
|
||||
|
||||
return "redirect:/document/${command.id}"
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<!doctype html>
|
||||
<html xmlns:th="http://www.thymeleaf.org"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{base}"
|
||||
lang="">
|
||||
<head>
|
||||
<title th:text="${form.name}"></title>
|
||||
</head>
|
||||
<body>
|
||||
<main id="content" layout:fragment="content">
|
||||
<form th:action="@{/document/edit}" th:object="${form}" method="post">
|
||||
<input type="hidden" th:field="*{id}">
|
||||
|
||||
<label for="name">name</label>
|
||||
<input id="name" type="text" th:field="*{name}" required>
|
||||
|
||||
<label for="description">beschreibung</label>
|
||||
<textarea id="description" th:field="*{description}"></textarea>
|
||||
|
||||
<button type="submit">
|
||||
bearbeiten
|
||||
</button>
|
||||
</form>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in new issue