remove label fields

master
Josha von Gizycki 2 weeks ago
parent d4ef00260d
commit c83b11d558

@ -28,6 +28,12 @@ data class Document(
labelFields = labelFields + field, labelFields = labelFields + field,
updatedAt = ZonedDateTime.now() updatedAt = ZonedDateTime.now()
) )
fun withoutLabel(fieldId: FieldId) =
copy(
updatedAt = ZonedDateTime.now(),
labelFields = labelFields.filter { it.id != fieldId }.toSet()
)
} }
@Table("T_DOCUMENT") @Table("T_DOCUMENT")

@ -0,0 +1,12 @@
package wanijo.wanijo2.domain.event
import jakarta.validation.constraints.Min
import wanijo.wanijo2.domain.DocumentId
import wanijo.wanijo2.domain.FieldId
data class DeleteLabelFieldCommand(
@Min(1)
val documentId: DocumentId,
@Min(1)
val labelFieldId: FieldId
)

@ -4,10 +4,12 @@ import org.springframework.data.annotation.Id
import org.springframework.data.relational.core.mapping.Table import org.springframework.data.relational.core.mapping.Table
import java.time.ZonedDateTime import java.time.ZonedDateTime
typealias FieldId = Long
@Table("T_LABEL_FIELD") @Table("T_LABEL_FIELD")
data class LabelField( data class LabelField(
@Id @Id
val id: Long = 0, val id: FieldId = 0,
val order: Int = 0, val order: Int = 0,
val name: String, val name: String,
val value: String = "", val value: String = "",
@ -18,7 +20,7 @@ data class LabelField(
@Table("T_DATE_FIELD") @Table("T_DATE_FIELD")
data class DateField( data class DateField(
@Id @Id
val id: Long = 0, val id: FieldId = 0,
val order: Int = 0, val order: Int = 0,
val name: String, val name: String,
val value: ZonedDateTime, val value: ZonedDateTime,

@ -0,0 +1,18 @@
package wanijo.wanijo2.domain.handler
import org.springframework.stereotype.Service
import wanijo.wanijo2.domain.DocumentDao
import wanijo.wanijo2.domain.event.DeleteLabelFieldCommand
import wanijo.wanijo2.http.DocumentNotFound
@Service
class DeleteLabelFieldHandler(
val dao: DocumentDao
) {
fun exec(command: DeleteLabelFieldCommand) {
val doc = dao.findById(command.documentId) ?: throw DocumentNotFound()
dao.save(doc.withoutLabel(command.labelFieldId))
}
}

@ -0,0 +1,27 @@
package wanijo.wanijo2.http.controller
import jakarta.validation.Valid
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import wanijo.wanijo2.domain.DocumentId
import wanijo.wanijo2.domain.event.DeleteLabelFieldCommand
import wanijo.wanijo2.domain.handler.DeleteLabelFieldHandler
@Controller
class DeleteLabelFieldController(
val handler: DeleteLabelFieldHandler
) {
@PostMapping("/document/{id}/field/label/delete")
fun removeLabelField(
@PathVariable
id: DocumentId,
@Valid
command: DeleteLabelFieldCommand
): String {
handler.exec(command)
return "redirect:/document/$id"
}
}

@ -1,7 +0,0 @@
package wanijo.wanijo2.http.controller
import org.springframework.stereotype.Controller
@Controller
class RemoveLabelFieldController {
}

@ -67,7 +67,8 @@
<dt> <dt>
<th:block th:text="${field.name}" /> <th:block th:text="${field.name}" />
<form class="form-inline" th:action="@{/document/{id}/field/label/delete(id=${document.id})}" method="post"> <form class="form-inline" th:action="@{/document/{id}/field/label/delete(id=${document.id})}" method="post">
<input type="hidden" name="labelId" th:value="${field.id}"> <input type="hidden" name="labelFieldId" th:value="${field.id}">
<input type="hidden" name="documentId" th:value="${document.id}">
<button type="submit" class="warning">weg</button> <button type="submit" class="warning">weg</button>
</form> </form>
</dt> </dt>

Loading…
Cancel
Save