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") @Table("T_DOCUMENT")
data class Document( data class Document(
@Id @Id
val id: Int = 0, val id: Long = 0,
val createdAt: ZonedDateTime = ZonedDateTime.now(),
val updatedAt: ZonedDateTime = ZonedDateTime.now(),
val name: String, 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 package wanijo.wanijo2.domain
import org.springframework.data.jdbc.repository.query.Query
import org.springframework.data.repository.Repository import org.springframework.data.repository.Repository
interface DocumentDao: Repository<Document, Int> { interface DocumentDao: Repository<Document, Int> {
fun findAll(): List<Document> fun findAll(): List<Document>
fun findById(id: Int): Document? fun findById(id: Long): Document?
fun findByName(name: String): List<Document> fun findByName(name: String): List<Document>
fun save(doc: 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}") @GetMapping("/document/{id}")
fun show( fun show(
model: Model, model: Model,
@PathVariable id: Int @PathVariable id: Long
): String { ): String {
val document = docDao.findById(id) ?: throw DocumentNotFound() val document = docDao.findById(id) ?: throw DocumentNotFound()
model["document"] = document model["document"] = document

@ -1,8 +1,9 @@
CREATE TABLE t_document CREATE TABLE t_document
( (
id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE DEFAULT now(), created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT now(), updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
name VARCHAR NOT NULL, name VARCHAR NOT NULL,
description VARCHAR 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 { main {
.show__meta { .show__meta {
display: flex; display: flex;
justify-content: space-evenly; justify-content: space-evenly;
font-size: 70%; font-size: 90%;
} }
a:link, a:visited { a:link, a:visited {
text-decoration: none; text-decoration: none;
color: dodgerblue; color: LinkText;
} }
a:hover, a:active { a:hover, a:active {
@ -16,18 +20,24 @@ main {
} }
fieldset { fieldset {
border-color: highlight; border: 1px solid AccentColor;
} }
} }
table { table {
width: 100%;
td {
padding: .3rem;
}
thead { thead {
background-color: lightgray; background-color: ButtonFace;
} }
tbody { tbody {
tr:hover { tr:hover {
background-color: beige; background-color: ButtonBorder;
} }
} }
} }

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