styling, entity work

master
Josha von Gizycki 6 days ago
parent dfeb045f1a
commit 81f3972b55

@ -7,9 +7,12 @@ import java.time.ZonedDateTime
@Table("T_DOCUMENT")
data class Document(
@Id
val id: Int = 0,
val createdAt: ZonedDateTime = ZonedDateTime.now(),
val updatedAt: ZonedDateTime = ZonedDateTime.now(),
val id: Long = 0,
val name: String,
val description: String
val description: String = "",
val updatedAt: ZonedDateTime = ZonedDateTime.now(),
val createdAt: ZonedDateTime = ZonedDateTime.now(),
val labelFields: Set<LabelField> = emptySet(),
val dateFields: Set<DateField> = emptySet(),
val tags: Set<Tag> = emptySet()
)

@ -1,15 +1,27 @@
package wanijo.wanijo2.domain
import org.springframework.data.jdbc.repository.query.Query
import org.springframework.data.repository.Repository
interface DocumentDao: Repository<Document, Int> {
fun findAll(): List<Document>
fun findById(id: Int): Document?
fun findById(id: Long): Document?
fun findByName(name: String): List<Document>
fun save(doc: Document)
@Query(
"""
SELECT doc.*
FROM t_document doc
JOIN t_tag tag
ON doc.id = tag.t_document
WHERE LOWER(tag.name) LIKE '%' || LOWER(:tagName) || '%'
"""
)
fun findByTagName(tagName: String): List<Document>
}

@ -0,0 +1,13 @@
package wanijo.wanijo2.domain
import org.springframework.data.annotation.Id
import org.springframework.data.relational.core.mapping.Table
import java.time.ZonedDateTime
@Table("T_TAG")
data class Tag(
@Id
val id: Long = 0,
val name: String,
val createdAt: ZonedDateTime = ZonedDateTime.now()
)

@ -0,0 +1,27 @@
package wanijo.wanijo2.domain
import org.springframework.data.annotation.Id
import org.springframework.data.relational.core.mapping.Table
import java.time.ZonedDateTime
@Table("T_LABEL_FIELD")
data class LabelField(
@Id
val id: Long,
val order: Int = 0,
val name: String,
val value: String = "",
val updatedAt: ZonedDateTime = ZonedDateTime.now(),
val createdAt: ZonedDateTime = ZonedDateTime.now(),
)
@Table("T_DATE_FIELD")
data class DateField(
@Id
val id: Long,
val order: Int = 0,
val name: String,
val value: ZonedDateTime,
val updatedAt: ZonedDateTime = ZonedDateTime.now(),
val createdAt: ZonedDateTime = ZonedDateTime.now(),
)

@ -18,7 +18,7 @@ class ShowController(
@GetMapping("/document/{id}")
fun show(
model: Model,
@PathVariable id: Int
@PathVariable id: Long
): String {
val document = docDao.findById(id) ?: throw DocumentNotFound()
model["document"] = document

@ -1,8 +1,9 @@
CREATE TABLE t_document
(
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE DEFAULT now(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT now(),
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
name VARCHAR NOT NULL,
description VARCHAR
);

@ -0,0 +1,29 @@
CREATE TABLE t_label_field
(
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
name VARCHAR NOT NULL,
"ORDER" INT NOT NULL DEFAULT 0,
"VALUE" VARCHAR,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
t_document INT REFERENCES t_document (id) NOT NULL
);
CREATE TABLE t_date_field
(
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
name VARCHAR NOT NULL,
"ORDER" INT NOT NULL DEFAULT 0,
"VALUE" TIMESTAMP WITH TIME ZONE,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
t_document INT REFERENCES t_document (id) NOT NULL
);
CREATE TABLE t_tag
(
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
name VARCHAR NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
t_document INT REFERENCES t_document (id) NOT NULL
);

@ -1,14 +1,18 @@
body {
margin: 0 5rem;
}
main {
.show__meta {
display: flex;
justify-content: space-evenly;
font-size: 70%;
font-size: 90%;
}
a:link, a:visited {
text-decoration: none;
color: dodgerblue;
color: LinkText;
}
a:hover, a:active {
@ -16,18 +20,24 @@ main {
}
fieldset {
border-color: highlight;
border: 1px solid AccentColor;
}
}
table {
width: 100%;
td {
padding: .3rem;
}
thead {
background-color: lightgray;
background-color: ButtonFace;
}
tbody {
tr:hover {
background-color: beige;
background-color: ButtonBorder;
}
}
}

@ -19,10 +19,7 @@ class DocumentDaoTest {
assertEquals(0, adapter.findAll().count())
adapter.save(
Document(
name = "name",
description = "desc"
)
Document(name = "name")
)
assertEquals(1, adapter.findAll().count())
@ -30,10 +27,7 @@ class DocumentDaoTest {
@Test
fun findByIdWorks() {
val doc = Document(
name = "name",
description = "desc"
)
val doc = Document(name = "name")
adapter.save(doc)
@ -43,32 +37,61 @@ class DocumentDaoTest {
@Test
fun idsAreGeneratedSequentially() {
adapter.save(
Document(name = "name1")
)
adapter.save(
Document(name = "name2")
)
assertNotNull(adapter.findById(1))
assertNotNull(adapter.findById(2))
}
@Test
fun findByNameWorks() {
adapter.save(
Document(name = "findmich")
)
assertNotNull(adapter.findByName("findmich"))
}
@Test
fun findsDocumentsWithTag() {
adapter.save(
Document(
name = "name1",
description = "desc"
name = "Dok1",
tags = setOf(Tag(name = "tAg1"))
)
)
adapter.save(
Document(
name = "name2",
description = "desc"
name = "Dok2",
tags = setOf(Tag(name = "taG2"))
)
)
assertNotNull(adapter.findById(1))
assertNotNull(adapter.findById(2))
val docs = adapter.findByTagName("tag1")
assertEquals(1, docs.size)
assertEquals("Dok1", docs[0].name)
}
@Test
fun findByNameWorks()
{
fun tagsAreSaved() {
adapter.save(
Document(name = "findmich", description = "")
Document(
name = "dok1",
tags = setOf(Tag(name = "tag1"), Tag(name = "tag2"))
)
)
assertNotNull(adapter.findByName("findmich"))
val doc = adapter.findAll()[0]
assertEquals(2, doc.tags.size)
assertEquals("tag1", doc.tags.first().name)
assertEquals("tag2", doc.tags.last().name)
}
}

Loading…
Cancel
Save