diff --git a/src/main/kotlin/wanijo/wanijo2/domain/document.kt b/src/main/kotlin/wanijo/wanijo2/domain/document.kt index 7b1f006..951f6eb 100644 --- a/src/main/kotlin/wanijo/wanijo2/domain/document.kt +++ b/src/main/kotlin/wanijo/wanijo2/domain/document.kt @@ -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 = emptySet(), val dateFields: Set = 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 { diff --git a/src/main/kotlin/wanijo/wanijo2/domain/event/AddDateFieldCommand.kt b/src/main/kotlin/wanijo/wanijo2/domain/event/AddDateFieldCommand.kt index 87bddcf..4fe8f09 100644 --- a/src/main/kotlin/wanijo/wanijo2/domain/event/AddDateFieldCommand.kt +++ b/src/main/kotlin/wanijo/wanijo2/domain/event/AddDateFieldCommand.kt @@ -17,11 +17,4 @@ data class AddDateFieldCommand( @NotEmpty val dateValue: LocalDateTime, val order: Int = 0, -) { - fun toField() = - DateField( - name = dateName, - value = dateValue, - order = order - ) -} +) diff --git a/src/main/kotlin/wanijo/wanijo2/domain/fields.kt b/src/main/kotlin/wanijo/wanijo2/domain/fields.kt index e8ddab6..daf49a7 100644 --- a/src/main/kotlin/wanijo/wanijo2/domain/fields.kt +++ b/src/main/kotlin/wanijo/wanijo2/domain/fields.kt @@ -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() ) diff --git a/src/main/kotlin/wanijo/wanijo2/domain/handler/AddDateFieldHandler.kt b/src/main/kotlin/wanijo/wanijo2/domain/handler/AddDateFieldHandler.kt index 50779ad..93552b9 100644 --- a/src/main/kotlin/wanijo/wanijo2/domain/handler/AddDateFieldHandler.kt +++ b/src/main/kotlin/wanijo/wanijo2/domain/handler/AddDateFieldHandler.kt @@ -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 + ) + ) ) } diff --git a/src/main/kotlin/wanijo/wanijo2/domain/tag.kt b/src/main/kotlin/wanijo/wanijo2/domain/tag.kt index 9a6cd0a..a6862d9 100644 --- a/src/main/kotlin/wanijo/wanijo2/domain/tag.kt +++ b/src/main/kotlin/wanijo/wanijo2/domain/tag.kt @@ -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, val documentId: AggregateReference, - val createdAt: LocalDateTime = now() + val createdAt: Instant = Instant.now() ) { companion object { fun between(doc: Document, tagId: TagId) =