parent
97fe0acdea
commit
26fdc13a77
@ -0,0 +1,15 @@
|
|||||||
|
package wanijo.wanijo2.domain.event
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.Min
|
||||||
|
import jakarta.validation.constraints.NotEmpty
|
||||||
|
import wanijo.wanijo2.domain.DocumentId
|
||||||
|
import wanijo.wanijo2.domain.TagId
|
||||||
|
|
||||||
|
data class AssignTaggingCommand(
|
||||||
|
@NotEmpty
|
||||||
|
@Min(1)
|
||||||
|
val tagId: TagId,
|
||||||
|
@NotEmpty
|
||||||
|
@Min(1)
|
||||||
|
val documentId: DocumentId
|
||||||
|
)
|
@ -0,0 +1,22 @@
|
|||||||
|
package wanijo.wanijo2.domain.handler
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
import wanijo.wanijo2.domain.DocumentTagging
|
||||||
|
import wanijo.wanijo2.domain.DocumentTaggingDao
|
||||||
|
import wanijo.wanijo2.domain.event.AssignTaggingCommand
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class AssignTaggingHandler(
|
||||||
|
val taggingDao: DocumentTaggingDao
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun exec(command: AssignTaggingCommand) {
|
||||||
|
taggingDao.save(
|
||||||
|
DocumentTagging.between(
|
||||||
|
command.documentId,
|
||||||
|
command.tagId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,32 +1,35 @@
|
|||||||
package wanijo.wanijo2.http.controller
|
package wanijo.wanijo2.http.controller
|
||||||
|
|
||||||
|
import jakarta.validation.Valid
|
||||||
import org.springframework.stereotype.Controller
|
import org.springframework.stereotype.Controller
|
||||||
import org.springframework.web.bind.annotation.PostMapping
|
import org.springframework.web.bind.annotation.PostMapping
|
||||||
import org.springframework.web.bind.annotation.RequestParam
|
import wanijo.wanijo2.domain.event.AssignTaggingCommand
|
||||||
import wanijo.wanijo2.domain.DocumentId
|
|
||||||
import wanijo.wanijo2.domain.TagId
|
|
||||||
import wanijo.wanijo2.domain.event.DeleteTaggingCommand
|
import wanijo.wanijo2.domain.event.DeleteTaggingCommand
|
||||||
|
import wanijo.wanijo2.domain.handler.AssignTaggingHandler
|
||||||
import wanijo.wanijo2.domain.handler.DeleteTaggingHandler
|
import wanijo.wanijo2.domain.handler.DeleteTaggingHandler
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
class TaggingController(
|
class TaggingController(
|
||||||
val deleteTaggingHandler: DeleteTaggingHandler
|
val deleteTaggingHandler: DeleteTaggingHandler,
|
||||||
|
val assignTaggingHandler: AssignTaggingHandler
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@PostMapping("/tagging/delete")
|
@PostMapping("/tagging/delete")
|
||||||
fun delete(
|
fun delete(
|
||||||
@RequestParam("docId")
|
@Valid
|
||||||
documentId: DocumentId,
|
command: DeleteTaggingCommand
|
||||||
@RequestParam("tagId")
|
|
||||||
tagId: TagId
|
|
||||||
): String {
|
): String {
|
||||||
deleteTaggingHandler.exec(
|
deleteTaggingHandler.exec(command)
|
||||||
DeleteTaggingCommand(
|
return "redirect:/document/${command.documentId}"
|
||||||
tagId = tagId,
|
}
|
||||||
documentId = documentId
|
|
||||||
)
|
@PostMapping("/tagging/assign")
|
||||||
)
|
fun assign(
|
||||||
return "redirect:/document/${documentId}"
|
@Valid
|
||||||
|
command: AssignTaggingCommand
|
||||||
|
): String {
|
||||||
|
assignTaggingHandler.exec(command)
|
||||||
|
return "redirect:/document/${command.documentId}"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue