diff --git a/src/main/kotlin/wanijo/wanijo2/domain/event/AddLinkCommand.kt b/src/main/kotlin/wanijo/wanijo2/domain/event/AddLinkCommand.kt new file mode 100644 index 0000000..7d9fbe4 --- /dev/null +++ b/src/main/kotlin/wanijo/wanijo2/domain/event/AddLinkCommand.kt @@ -0,0 +1,13 @@ +package wanijo.wanijo2.domain.event + +import jakarta.validation.constraints.Min +import wanijo.wanijo2.domain.Direction +import wanijo.wanijo2.domain.DocumentId + +data class AddLinkCommand( + @Min(1) + val documentId: DocumentId, + @Min.List(Min(1)) + val otherDocuments: List, + val direction: Direction +) diff --git a/src/main/kotlin/wanijo/wanijo2/domain/link.kt b/src/main/kotlin/wanijo/wanijo2/domain/link.kt new file mode 100644 index 0000000..07f3f59 --- /dev/null +++ b/src/main/kotlin/wanijo/wanijo2/domain/link.kt @@ -0,0 +1,25 @@ +package wanijo.wanijo2.domain + +import org.springframework.data.annotation.Id +import org.springframework.data.jdbc.core.mapping.AggregateReference +import org.springframework.data.relational.core.mapping.Table +import org.springframework.data.repository.Repository +import java.time.Instant + +typealias LinkId = Long + +@Table("T_LINK") +data class Link( + @Id + val id: LinkId = 0, + val from: AggregateReference, + val to: AggregateReference, + val createdAt: Instant = Instant.now(), +) + +enum class Direction { + OUTGOING, + INCOMING +} + +interface LinkDao : Repository {} diff --git a/src/main/kotlin/wanijo/wanijo2/http/controller/AddFieldController.kt b/src/main/kotlin/wanijo/wanijo2/http/controller/AddFieldController.kt index 7bccf34..d394404 100644 --- a/src/main/kotlin/wanijo/wanijo2/http/controller/AddFieldController.kt +++ b/src/main/kotlin/wanijo/wanijo2/http/controller/AddFieldController.kt @@ -14,7 +14,6 @@ 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 class AddFieldController( diff --git a/src/main/kotlin/wanijo/wanijo2/http/controller/LinkController.kt b/src/main/kotlin/wanijo/wanijo2/http/controller/LinkController.kt new file mode 100644 index 0000000..dc09816 --- /dev/null +++ b/src/main/kotlin/wanijo/wanijo2/http/controller/LinkController.kt @@ -0,0 +1,48 @@ +package wanijo.wanijo2.http.controller + +import org.springframework.data.domain.Sort +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 wanijo.wanijo2.domain.Direction +import wanijo.wanijo2.domain.DocumentBriefDao +import wanijo.wanijo2.domain.DocumentId +import wanijo.wanijo2.domain.event.AddLinkCommand + +@Controller +class LinkController( + val documentBriefDao: DocumentBriefDao, +) { + + @GetMapping("/document/{id}/link/add") + fun addLabel( + @PathVariable + id: DocumentId, + model: Model + ): String { + model["document"] = documentBriefDao.findById(id) + model["documents"] = documentBriefDao.findAll(Sort.by(Sort.Direction.ASC, "name")) + + model["addForm"] = AddLinkCommand( + id, + emptyList(), + Direction.OUTGOING + ) + + return "addLink" + } + + /*@PostMapping("/document/{id}/field/label/add") + fun addLabel( + @PathVariable + id: DocumentId, + @Valid + command: AddLabelFieldCommand + ): String { + addLabelFieldHandler.exec(command) + return "redirect:/document/$id" + }*/ + +} diff --git a/src/main/kotlin/wanijo/wanijo2/http/controller/ShowController.kt b/src/main/kotlin/wanijo/wanijo2/http/controller/ShowController.kt index a6d50db..7001317 100644 --- a/src/main/kotlin/wanijo/wanijo2/http/controller/ShowController.kt +++ b/src/main/kotlin/wanijo/wanijo2/http/controller/ShowController.kt @@ -9,12 +9,15 @@ import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PathVariable import wanijo.wanijo2.domain.DocumentDao import wanijo.wanijo2.domain.DocumentId +import wanijo.wanijo2.domain.Link +import wanijo.wanijo2.domain.LinkDao import wanijo.wanijo2.domain.TagDao import wanijo.wanijo2.http.DocumentNotFound @Controller class ShowController( val docDao: DocumentDao, + val linkDao: LinkDao, val tagDao: TagDao ) { @@ -36,6 +39,9 @@ class ShowController( model["documentTags"] = documentTags.sortedBy { it.name.lowercase() } model["assignableTags"] = (tagDao.findAll() - documentTags).sortedBy { it.name.lowercase() } + model["incomingLinks"] = emptyList() + model["outgoingLinks"] = emptyList() + return "show" } diff --git a/src/main/resources/db/migration/V202512241340__links.sql b/src/main/resources/db/migration/V202512241340__links.sql new file mode 100644 index 0000000..1bd15f1 --- /dev/null +++ b/src/main/resources/db/migration/V202512241340__links.sql @@ -0,0 +1,15 @@ +CREATE TABLE t_link +( + id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + document_from INT NOT NULL, + document_to INT NOT NULL, + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), + + CONSTRAINT fk_link_document_from + FOREIGN KEY (document_from) + REFERENCES t_document (id), + + CONSTRAINT fk_link_document_to + FOREIGN KEY (document_to) + REFERENCES t_document (id) +); diff --git a/src/main/resources/templates/addLabelField.html b/src/main/resources/templates/addLabelField.html index 47d10ca..a86f0d1 100644 --- a/src/main/resources/templates/addLabelField.html +++ b/src/main/resources/templates/addLabelField.html @@ -11,7 +11,7 @@ << zurück

- label zu + beschriftung zu hinzufügen

diff --git a/src/main/resources/templates/addLink.html b/src/main/resources/templates/addLink.html new file mode 100644 index 0000000..e8b3cb3 --- /dev/null +++ b/src/main/resources/templates/addLink.html @@ -0,0 +1,41 @@ + + + + + + +
+ << zurück + +

+ verknüpfung für + + hinzufügen +

+ +
+ + + + + + + +
+
+ + diff --git a/src/main/resources/templates/edit.html b/src/main/resources/templates/edit.html index 35457f9..456597e 100644 --- a/src/main/resources/templates/edit.html +++ b/src/main/resources/templates/edit.html @@ -8,6 +8,14 @@
+ << zurück + +

+ dokument + + bearbeiten +

+
diff --git a/src/main/resources/templates/show.html b/src/main/resources/templates/show.html index cf9bf00..9adbaee 100644 --- a/src/main/resources/templates/show.html +++ b/src/main/resources/templates/show.html @@ -53,6 +53,33 @@
+

+ verknüpfungen + + + +

+

+ eingehend +

+
    +
  1. + +
  2. +
+

+ ausgehend +

+
    +
  1. + +
  2. +
+

felder @@ -62,7 +89,7 @@

- label + beschriftung