change to instants for audit fields

master
Josha von Gizycki 2 weeks ago
parent a5c2f5024f
commit 9af57be306

@ -6,8 +6,7 @@ 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.Instant
import java.time.ZonedDateTime
typealias DocumentId = Long
@ -20,8 +19,8 @@ data class Document(
val id: DocumentId = 0,
val name: DocumentName,
val description: DocumentDescription = "",
val updatedAt: LocalDateTime = now(),
val createdAt: LocalDateTime = now(),
val updatedAt: Instant = Instant.now(),
val createdAt: Instant = Instant.now(),
val labelFields: Set<LabelField> = emptySet(),
val dateFields: Set<DateField> = emptySet(),
) {
@ -33,25 +32,25 @@ data class Document(
fun withLabel(field: LabelField) =
copy(
labelFields = labelFields + field,
updatedAt = now()
updatedAt = Instant.now(),
labelFields = labelFields + field
)
fun withDate(field: DateField) =
copy(
dateFields = dateFields + field,
updatedAt = now()
updatedAt = Instant.now(),
dateFields = dateFields + field
)
fun withoutLabel(fieldId: FieldId) =
copy(
updatedAt = now(),
updatedAt = Instant.now(),
labelFields = labelFields.filter { it.id != fieldId }.toSet()
)
fun withoutDate(fieldId: FieldId) =
copy(
updatedAt = now(),
updatedAt = Instant.now(),
dateFields = dateFields.filter { it.id != fieldId }.toSet()
)
}
@ -61,7 +60,7 @@ data class DocumentBrief(
@Id
val id: DocumentId,
val name: DocumentName,
val updatedAt: ZonedDateTime
val updatedAt: Instant
)
interface DocumentDao : Repository<Document, DocumentId> {

@ -17,11 +17,4 @@ data class AddDateFieldCommand(
@NotEmpty
val dateValue: LocalDateTime,
val order: Int = 0,
) {
fun toField() =
DateField(
name = dateName,
value = dateValue,
order = order
)
}

@ -2,8 +2,8 @@ package wanijo.wanijo2.domain
import org.springframework.data.annotation.Id
import org.springframework.data.relational.core.mapping.Table
import java.time.Instant
import java.time.LocalDateTime
import java.time.LocalDateTime.now
typealias FieldId = Long
@ -14,8 +14,8 @@ data class LabelField(
val order: Int = 0,
val name: String,
val value: String = "",
val updatedAt: LocalDateTime = now(),
val createdAt: LocalDateTime = now(),
val updatedAt: Instant = Instant.now(),
val createdAt: Instant = Instant.now(),
)
@Table("T_DATE_FIELD")
@ -25,6 +25,6 @@ data class DateField(
val order: Int = 0,
val name: String,
val value: LocalDateTime,
val updatedAt: LocalDateTime = now(),
val createdAt: LocalDateTime = now(),
val updatedAt: Instant = Instant.now(),
val createdAt: Instant = Instant.now()
)

@ -3,7 +3,6 @@ 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
@ -15,7 +14,13 @@ class AddDateFieldHandler(
fun exec(command: AddDateFieldCommand) {
val doc = documentDao.findById(command.documentId) ?: throw DocumentNotFound()
documentDao.save(
doc.withDate(command.toField())
doc.withDate(
DateField(
name = command.dateName,
value = command.dateValue,
order = command.order
)
)
)
}

@ -6,9 +6,9 @@ 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.Instant
import java.time.LocalDateTime
import java.time.LocalDateTime.now
import java.time.ZonedDateTime
typealias TagId = Long
typealias TagName = String
@ -18,7 +18,7 @@ data class Tag(
@Id
val id: TagId = 0,
val name: TagName,
val createdAt: LocalDateTime = now()
val createdAt: Instant = Instant.now()
)
typealias DocumentTaggingId = Long
@ -29,7 +29,7 @@ data class DocumentTagging(
val id: DocumentTaggingId = 0,
val tagId: AggregateReference<Tag, TagId>,
val documentId: AggregateReference<Document, DocumentId>,
val createdAt: LocalDateTime = now()
val createdAt: Instant = Instant.now()
) {
companion object {
fun between(doc: Document, tagId: TagId) =

Loading…
Cancel
Save