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

@ -17,11 +17,4 @@ data class AddDateFieldCommand(
@NotEmpty @NotEmpty
val dateValue: LocalDateTime, val dateValue: LocalDateTime,
val order: Int = 0, 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.annotation.Id
import org.springframework.data.relational.core.mapping.Table import org.springframework.data.relational.core.mapping.Table
import java.time.Instant
import java.time.LocalDateTime import java.time.LocalDateTime
import java.time.LocalDateTime.now
typealias FieldId = Long typealias FieldId = Long
@ -14,8 +14,8 @@ data class LabelField(
val order: Int = 0, val order: Int = 0,
val name: String, val name: String,
val value: String = "", val value: String = "",
val updatedAt: LocalDateTime = now(), val updatedAt: Instant = Instant.now(),
val createdAt: LocalDateTime = now(), val createdAt: Instant = Instant.now(),
) )
@Table("T_DATE_FIELD") @Table("T_DATE_FIELD")
@ -25,6 +25,6 @@ data class DateField(
val order: Int = 0, val order: Int = 0,
val name: String, val name: String,
val value: LocalDateTime, val value: LocalDateTime,
val updatedAt: LocalDateTime = now(), val updatedAt: Instant = Instant.now(),
val createdAt: LocalDateTime = now(), val createdAt: Instant = Instant.now()
) )

@ -3,7 +3,6 @@ package wanijo.wanijo2.domain.handler
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
import wanijo.wanijo2.domain.DateField import wanijo.wanijo2.domain.DateField
import wanijo.wanijo2.domain.DocumentDao import wanijo.wanijo2.domain.DocumentDao
import wanijo.wanijo2.domain.LabelField
import wanijo.wanijo2.domain.event.AddDateFieldCommand import wanijo.wanijo2.domain.event.AddDateFieldCommand
import wanijo.wanijo2.http.DocumentNotFound import wanijo.wanijo2.http.DocumentNotFound
@ -15,7 +14,13 @@ class AddDateFieldHandler(
fun exec(command: AddDateFieldCommand) { fun exec(command: AddDateFieldCommand) {
val doc = documentDao.findById(command.documentId) ?: throw DocumentNotFound() val doc = documentDao.findById(command.documentId) ?: throw DocumentNotFound()
documentDao.save( 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.jdbc.repository.query.Query
import org.springframework.data.relational.core.mapping.Table import org.springframework.data.relational.core.mapping.Table
import org.springframework.data.repository.Repository import org.springframework.data.repository.Repository
import java.time.Instant
import java.time.LocalDateTime import java.time.LocalDateTime
import java.time.LocalDateTime.now import java.time.LocalDateTime.now
import java.time.ZonedDateTime
typealias TagId = Long typealias TagId = Long
typealias TagName = String typealias TagName = String
@ -18,7 +18,7 @@ data class Tag(
@Id @Id
val id: TagId = 0, val id: TagId = 0,
val name: TagName, val name: TagName,
val createdAt: LocalDateTime = now() val createdAt: Instant = Instant.now()
) )
typealias DocumentTaggingId = Long typealias DocumentTaggingId = Long
@ -29,7 +29,7 @@ data class DocumentTagging(
val id: DocumentTaggingId = 0, val id: DocumentTaggingId = 0,
val tagId: AggregateReference<Tag, TagId>, val tagId: AggregateReference<Tag, TagId>,
val documentId: AggregateReference<Document, DocumentId>, val documentId: AggregateReference<Document, DocumentId>,
val createdAt: LocalDateTime = now() val createdAt: Instant = Instant.now()
) { ) {
companion object { companion object {
fun between(doc: Document, tagId: TagId) = fun between(doc: Document, tagId: TagId) =

Loading…
Cancel
Save