remove label fields
parent
d4ef00260d
commit
c83b11d558
@ -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
|
||||
)
|
||||
@ -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 {
|
||||
}
|
||||
Loading…
Reference in New Issue