From a5c2f5024f58f23398949f0069d2f2925232dbe9 Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Sat, 20 Dec 2025 01:25:09 +0100 Subject: [PATCH] date fields --- .../kotlin/wanijo/wanijo2/domain/document.kt | 25 +++++++++++--- .../domain/event/AddDateFieldCommand.kt | 27 +++++++++++++++ .../domain/event/AddLabelFieldCommand.kt | 10 +++++- .../domain/event/DeleteDateFieldCommand.kt | 12 +++++++ .../kotlin/wanijo/wanijo2/domain/fields.kt | 13 ++++---- .../domain/handler/AddDateFieldHandler.kt | 22 +++++++++++++ .../domain/handler/AddLabelFieldHandler.kt | 9 +---- .../domain/handler/DeleteDateFieldHandler.kt | 18 ++++++++++ src/main/kotlin/wanijo/wanijo2/domain/tag.kt | 7 ++-- ...eldController.kt => AddFieldController.kt} | 33 +++++++++++++++---- ...Controller.kt => DeleteFieldController.kt} | 20 +++++++++-- .../V202512200144__tagging_created_at.sql | 2 ++ .../resources/templates/addLabelField.html | 33 +++++++++++++++++-- src/main/resources/templates/show.html | 21 ++++++++---- 14 files changed, 212 insertions(+), 40 deletions(-) create mode 100644 src/main/kotlin/wanijo/wanijo2/domain/event/AddDateFieldCommand.kt create mode 100644 src/main/kotlin/wanijo/wanijo2/domain/event/DeleteDateFieldCommand.kt create mode 100644 src/main/kotlin/wanijo/wanijo2/domain/handler/AddDateFieldHandler.kt create mode 100644 src/main/kotlin/wanijo/wanijo2/domain/handler/DeleteDateFieldHandler.kt rename src/main/kotlin/wanijo/wanijo2/http/controller/{AddLabelFieldController.kt => AddFieldController.kt} (56%) rename src/main/kotlin/wanijo/wanijo2/http/controller/{DeleteLabelFieldController.kt => DeleteFieldController.kt} (53%) create mode 100644 src/main/resources/db/migration/V202512200144__tagging_created_at.sql diff --git a/src/main/kotlin/wanijo/wanijo2/domain/document.kt b/src/main/kotlin/wanijo/wanijo2/domain/document.kt index 36b834b..7b1f006 100644 --- a/src/main/kotlin/wanijo/wanijo2/domain/document.kt +++ b/src/main/kotlin/wanijo/wanijo2/domain/document.kt @@ -6,6 +6,8 @@ import org.springframework.data.jdbc.repository.query.Modifying import org.springframework.data.jdbc.repository.query.Query import org.springframework.data.relational.core.mapping.Table import org.springframework.data.repository.Repository +import java.time.LocalDateTime +import java.time.LocalDateTime.now import java.time.ZonedDateTime typealias DocumentId = Long @@ -18,25 +20,40 @@ data class Document( val id: DocumentId = 0, val name: DocumentName, val description: DocumentDescription = "", - val updatedAt: ZonedDateTime = ZonedDateTime.now(), - val createdAt: ZonedDateTime = ZonedDateTime.now(), + val updatedAt: LocalDateTime = now(), + val createdAt: LocalDateTime = now(), val labelFields: Set = emptySet(), val dateFields: Set = emptySet(), ) { fun labelFieldsSorted() = labelFields.sortedBy { it.order } + fun dateFieldsSorted() = + dateFields.sortedBy { it.order } + fun withLabel(field: LabelField) = copy( labelFields = labelFields + field, - updatedAt = ZonedDateTime.now() + updatedAt = now() + ) + + fun withDate(field: DateField) = + copy( + dateFields = dateFields + field, + updatedAt = now() ) fun withoutLabel(fieldId: FieldId) = copy( - updatedAt = ZonedDateTime.now(), + updatedAt = now(), labelFields = labelFields.filter { it.id != fieldId }.toSet() ) + + fun withoutDate(fieldId: FieldId) = + copy( + updatedAt = now(), + dateFields = dateFields.filter { it.id != fieldId }.toSet() + ) } @Table("T_DOCUMENT") diff --git a/src/main/kotlin/wanijo/wanijo2/domain/event/AddDateFieldCommand.kt b/src/main/kotlin/wanijo/wanijo2/domain/event/AddDateFieldCommand.kt new file mode 100644 index 0000000..87bddcf --- /dev/null +++ b/src/main/kotlin/wanijo/wanijo2/domain/event/AddDateFieldCommand.kt @@ -0,0 +1,27 @@ +package wanijo.wanijo2.domain.event + +import jakarta.validation.constraints.Min +import jakarta.validation.constraints.NotEmpty +import wanijo.wanijo2.domain.DateField +import wanijo.wanijo2.domain.DocumentId +import java.time.LocalDateTime +import java.time.ZoneId +import java.time.ZoneOffset +import java.time.ZonedDateTime + +data class AddDateFieldCommand( + @Min(1) + val documentId: DocumentId, + @NotEmpty + val dateName: String, + @NotEmpty + val dateValue: LocalDateTime, + val order: Int = 0, +) { + fun toField() = + DateField( + name = dateName, + value = dateValue, + order = order + ) +} diff --git a/src/main/kotlin/wanijo/wanijo2/domain/event/AddLabelFieldCommand.kt b/src/main/kotlin/wanijo/wanijo2/domain/event/AddLabelFieldCommand.kt index d6bb90e..54f09b4 100644 --- a/src/main/kotlin/wanijo/wanijo2/domain/event/AddLabelFieldCommand.kt +++ b/src/main/kotlin/wanijo/wanijo2/domain/event/AddLabelFieldCommand.kt @@ -3,6 +3,7 @@ package wanijo.wanijo2.domain.event import jakarta.validation.constraints.Min import jakarta.validation.constraints.NotEmpty import wanijo.wanijo2.domain.DocumentId +import wanijo.wanijo2.domain.LabelField data class AddLabelFieldCommand( @Min(1) @@ -12,4 +13,11 @@ data class AddLabelFieldCommand( @NotEmpty val labelValue: String, val order: Int = 0 -) +) { + fun toField() = + LabelField( + order = order, + name = labelName, + value = labelValue + ) +} diff --git a/src/main/kotlin/wanijo/wanijo2/domain/event/DeleteDateFieldCommand.kt b/src/main/kotlin/wanijo/wanijo2/domain/event/DeleteDateFieldCommand.kt new file mode 100644 index 0000000..1147b62 --- /dev/null +++ b/src/main/kotlin/wanijo/wanijo2/domain/event/DeleteDateFieldCommand.kt @@ -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 DeleteDateFieldCommand( + @Min(1) + val documentId: DocumentId, + @Min(1) + val dateFieldId: FieldId +) diff --git a/src/main/kotlin/wanijo/wanijo2/domain/fields.kt b/src/main/kotlin/wanijo/wanijo2/domain/fields.kt index 21a80c9..e8ddab6 100644 --- a/src/main/kotlin/wanijo/wanijo2/domain/fields.kt +++ b/src/main/kotlin/wanijo/wanijo2/domain/fields.kt @@ -2,7 +2,8 @@ package wanijo.wanijo2.domain import org.springframework.data.annotation.Id import org.springframework.data.relational.core.mapping.Table -import java.time.ZonedDateTime +import java.time.LocalDateTime +import java.time.LocalDateTime.now typealias FieldId = Long @@ -13,8 +14,8 @@ data class LabelField( val order: Int = 0, val name: String, val value: String = "", - val updatedAt: ZonedDateTime = ZonedDateTime.now(), - val createdAt: ZonedDateTime = ZonedDateTime.now(), + val updatedAt: LocalDateTime = now(), + val createdAt: LocalDateTime = now(), ) @Table("T_DATE_FIELD") @@ -23,7 +24,7 @@ data class DateField( val id: FieldId = 0, val order: Int = 0, val name: String, - val value: ZonedDateTime, - val updatedAt: ZonedDateTime = ZonedDateTime.now(), - val createdAt: ZonedDateTime = ZonedDateTime.now(), + val value: LocalDateTime, + val updatedAt: LocalDateTime = now(), + val createdAt: LocalDateTime = now(), ) diff --git a/src/main/kotlin/wanijo/wanijo2/domain/handler/AddDateFieldHandler.kt b/src/main/kotlin/wanijo/wanijo2/domain/handler/AddDateFieldHandler.kt new file mode 100644 index 0000000..50779ad --- /dev/null +++ b/src/main/kotlin/wanijo/wanijo2/domain/handler/AddDateFieldHandler.kt @@ -0,0 +1,22 @@ +package wanijo.wanijo2.domain.handler + +import org.springframework.stereotype.Service +import wanijo.wanijo2.domain.DateField +import wanijo.wanijo2.domain.DocumentDao +import wanijo.wanijo2.domain.LabelField +import wanijo.wanijo2.domain.event.AddDateFieldCommand +import wanijo.wanijo2.http.DocumentNotFound + +@Service +class AddDateFieldHandler( + val documentDao: DocumentDao +) { + + fun exec(command: AddDateFieldCommand) { + val doc = documentDao.findById(command.documentId) ?: throw DocumentNotFound() + documentDao.save( + doc.withDate(command.toField()) + ) + } + +} diff --git a/src/main/kotlin/wanijo/wanijo2/domain/handler/AddLabelFieldHandler.kt b/src/main/kotlin/wanijo/wanijo2/domain/handler/AddLabelFieldHandler.kt index 9c71250..39985ba 100644 --- a/src/main/kotlin/wanijo/wanijo2/domain/handler/AddLabelFieldHandler.kt +++ b/src/main/kotlin/wanijo/wanijo2/domain/handler/AddLabelFieldHandler.kt @@ -2,7 +2,6 @@ package wanijo.wanijo2.domain.handler import org.springframework.stereotype.Service import wanijo.wanijo2.domain.DocumentDao -import wanijo.wanijo2.domain.LabelField import wanijo.wanijo2.domain.event.AddLabelFieldCommand import wanijo.wanijo2.http.DocumentNotFound @@ -14,13 +13,7 @@ class AddLabelFieldHandler( fun exec(command: AddLabelFieldCommand) { val doc = documentDao.findById(command.documentId) ?: throw DocumentNotFound() documentDao.save( - doc.withLabel( - LabelField( - order = command.order, - name = command.labelName, - value = command.labelValue - ) - ) + doc.withLabel(command.toField()) ) } diff --git a/src/main/kotlin/wanijo/wanijo2/domain/handler/DeleteDateFieldHandler.kt b/src/main/kotlin/wanijo/wanijo2/domain/handler/DeleteDateFieldHandler.kt new file mode 100644 index 0000000..b23fded --- /dev/null +++ b/src/main/kotlin/wanijo/wanijo2/domain/handler/DeleteDateFieldHandler.kt @@ -0,0 +1,18 @@ +package wanijo.wanijo2.domain.handler + +import org.springframework.stereotype.Service +import wanijo.wanijo2.domain.DocumentDao +import wanijo.wanijo2.domain.event.DeleteDateFieldCommand +import wanijo.wanijo2.http.DocumentNotFound + +@Service +class DeleteDateFieldHandler( + val dao: DocumentDao +) { + + fun exec(command: DeleteDateFieldCommand) { + val doc = dao.findById(command.documentId) ?: throw DocumentNotFound() + dao.save(doc.withoutDate(command.dateFieldId)) + } + +} diff --git a/src/main/kotlin/wanijo/wanijo2/domain/tag.kt b/src/main/kotlin/wanijo/wanijo2/domain/tag.kt index 9983f90..9a6cd0a 100644 --- a/src/main/kotlin/wanijo/wanijo2/domain/tag.kt +++ b/src/main/kotlin/wanijo/wanijo2/domain/tag.kt @@ -6,6 +6,8 @@ import org.springframework.data.jdbc.repository.query.Modifying import org.springframework.data.jdbc.repository.query.Query import org.springframework.data.relational.core.mapping.Table import org.springframework.data.repository.Repository +import java.time.LocalDateTime +import java.time.LocalDateTime.now import java.time.ZonedDateTime typealias TagId = Long @@ -16,7 +18,7 @@ data class Tag( @Id val id: TagId = 0, val name: TagName, - val createdAt: ZonedDateTime = ZonedDateTime.now() + val createdAt: LocalDateTime = now() ) typealias DocumentTaggingId = Long @@ -26,7 +28,8 @@ data class DocumentTagging( @Id val id: DocumentTaggingId = 0, val tagId: AggregateReference, - val documentId: AggregateReference + val documentId: AggregateReference, + val createdAt: LocalDateTime = now() ) { companion object { fun between(doc: Document, tagId: TagId) = diff --git a/src/main/kotlin/wanijo/wanijo2/http/controller/AddLabelFieldController.kt b/src/main/kotlin/wanijo/wanijo2/http/controller/AddFieldController.kt similarity index 56% rename from src/main/kotlin/wanijo/wanijo2/http/controller/AddLabelFieldController.kt rename to src/main/kotlin/wanijo/wanijo2/http/controller/AddFieldController.kt index 96046f4..7bccf34 100644 --- a/src/main/kotlin/wanijo/wanijo2/http/controller/AddLabelFieldController.kt +++ b/src/main/kotlin/wanijo/wanijo2/http/controller/AddFieldController.kt @@ -7,36 +7,44 @@ 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 org.springframework.web.bind.annotation.RequestMapping import wanijo.wanijo2.domain.DocumentBriefDao import wanijo.wanijo2.domain.DocumentId +import wanijo.wanijo2.domain.event.AddDateFieldCommand import wanijo.wanijo2.domain.event.AddLabelFieldCommand +import wanijo.wanijo2.domain.handler.AddDateFieldHandler import wanijo.wanijo2.domain.handler.AddLabelFieldHandler +import java.time.LocalDateTime +import java.time.ZonedDateTime.now @Controller -@RequestMapping("/document/{id}/field/label/add") -class AddLabelFieldController( +class AddFieldController( val documentBriefDao: DocumentBriefDao, - val addLabelFieldHandler: AddLabelFieldHandler + val addLabelFieldHandler: AddLabelFieldHandler, + val addDateFieldHandler: AddDateFieldHandler ) { - @GetMapping + @GetMapping("/document/{id}/field/add") fun addLabel( @PathVariable id: DocumentId, model: Model ): String { - model["form"] = AddLabelFieldCommand( + model["labelForm"] = AddLabelFieldCommand( documentId = id, labelName = "", labelValue = "" ) + model["dateForm"] = AddDateFieldCommand( + documentId = id, + dateName = "", + dateValue = LocalDateTime.now() + ) model["document"] = documentBriefDao.findById(id) return "addLabelField" } - @PostMapping + @PostMapping("/document/{id}/field/label/add") fun addLabel( @PathVariable id: DocumentId, @@ -47,4 +55,15 @@ class AddLabelFieldController( return "redirect:/document/$id" } + @PostMapping("/document/{id}/field/date/add") + fun addDate( + @PathVariable + id: DocumentId, + @Valid + command: AddDateFieldCommand + ): String { + addDateFieldHandler.exec(command) + return "redirect:/document/$id" + } + } diff --git a/src/main/kotlin/wanijo/wanijo2/http/controller/DeleteLabelFieldController.kt b/src/main/kotlin/wanijo/wanijo2/http/controller/DeleteFieldController.kt similarity index 53% rename from src/main/kotlin/wanijo/wanijo2/http/controller/DeleteLabelFieldController.kt rename to src/main/kotlin/wanijo/wanijo2/http/controller/DeleteFieldController.kt index db5fd18..bdda7cb 100644 --- a/src/main/kotlin/wanijo/wanijo2/http/controller/DeleteLabelFieldController.kt +++ b/src/main/kotlin/wanijo/wanijo2/http/controller/DeleteFieldController.kt @@ -5,12 +5,15 @@ 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.DeleteDateFieldCommand import wanijo.wanijo2.domain.event.DeleteLabelFieldCommand +import wanijo.wanijo2.domain.handler.DeleteDateFieldHandler import wanijo.wanijo2.domain.handler.DeleteLabelFieldHandler @Controller -class DeleteLabelFieldController( - val handler: DeleteLabelFieldHandler +class DeleteFieldController( + val labelFieldhandler: DeleteLabelFieldHandler, + val dateFieldHandler: DeleteDateFieldHandler ) { @PostMapping("/document/{id}/field/label/delete") @@ -20,7 +23,18 @@ class DeleteLabelFieldController( @Valid command: DeleteLabelFieldCommand ): String { - handler.exec(command) + labelFieldhandler.exec(command) + return "redirect:/document/$id" + } + + @PostMapping("/document/{id}/field/date/delete") + fun removeDateField( + @PathVariable + id: DocumentId, + @Valid + command: DeleteDateFieldCommand + ): String { + dateFieldHandler.exec(command) return "redirect:/document/$id" } diff --git a/src/main/resources/db/migration/V202512200144__tagging_created_at.sql b/src/main/resources/db/migration/V202512200144__tagging_created_at.sql new file mode 100644 index 0000000..510f350 --- /dev/null +++ b/src/main/resources/db/migration/V202512200144__tagging_created_at.sql @@ -0,0 +1,2 @@ +ALTER TABLE t_document_tagging + ADD COLUMN created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(); diff --git a/src/main/resources/templates/addLabelField.html b/src/main/resources/templates/addLabelField.html index 4b830cb..47d10ca 100644 --- a/src/main/resources/templates/addLabelField.html +++ b/src/main/resources/templates/addLabelField.html @@ -16,7 +16,9 @@ hinzufügen -
+ @@ -25,8 +27,33 @@ - - + + + + +
+ +

+ datum zu + + hinzufügen +

+ +
+ + + + + + + + + + + +

+ label

@@ -79,8 +81,15 @@ datumsangaben
- -
+ +
+ + + + + + +