#68 Clean Entities
This commit is contained in:
28
src/main/kotlin/fr/dcproject/common/entity/Action.kt
Normal file
28
src/main/kotlin/fr/dcproject/common/entity/Action.kt
Normal file
@@ -0,0 +1,28 @@
|
||||
package fr.dcproject.common.entity
|
||||
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
|
||||
interface Created<C : CitizenI> : CreatedAt, CreatedBy<C> {
|
||||
class Imp<C : CitizenI>(createdBy: C) :
|
||||
Created<C>,
|
||||
CreatedBy<C> by CreatedBy.Imp(createdBy),
|
||||
CreatedAt by CreatedAt.Imp()
|
||||
}
|
||||
|
||||
interface Updated<C : CitizenI> : UpdatedAt, UpdatedBy<C> {
|
||||
class Imp<C : CitizenI>(updatedAt: C) :
|
||||
Updated<C>,
|
||||
UpdatedBy<C> by UpdatedBy.Imp(updatedAt),
|
||||
UpdatedAt by UpdatedAt.Imp()
|
||||
}
|
||||
|
||||
interface Deleted<C : CitizenI> : DeletedAt, DeletedBy<C> {
|
||||
override fun isDeleted(): Boolean = (this as DeletedAt).isDeleted()
|
||||
|
||||
class Imp<C : CitizenI>(deletedAt: C) :
|
||||
Deleted<C>,
|
||||
DeletedBy<C> by DeletedBy.Imp(deletedAt),
|
||||
DeletedAt by DeletedAt.Imp() {
|
||||
override fun isDeleted(): Boolean = (this as Deleted<C>).isDeleted()
|
||||
}
|
||||
}
|
||||
25
src/main/kotlin/fr/dcproject/common/entity/ActionBy.kt
Normal file
25
src/main/kotlin/fr/dcproject/common/entity/ActionBy.kt
Normal file
@@ -0,0 +1,25 @@
|
||||
package fr.dcproject.common.entity
|
||||
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
|
||||
interface CreatedBy<T : CitizenI> {
|
||||
val createdBy: T
|
||||
|
||||
class Imp<T : CitizenI>(override val createdBy: T) : CreatedBy<T>
|
||||
}
|
||||
|
||||
interface UpdatedBy<T : CitizenI> {
|
||||
val updatedBy: T
|
||||
|
||||
class Imp<T : CitizenI>(override val updatedBy: T) : UpdatedBy<T>
|
||||
}
|
||||
|
||||
interface DeletedBy<T : CitizenI> {
|
||||
val deletedBy: T?
|
||||
|
||||
fun isDeleted(): Boolean {
|
||||
return deletedBy?.let { true } ?: false
|
||||
}
|
||||
|
||||
class Imp<T : CitizenI>(override val deletedBy: T?) : DeletedBy<T>
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package fr.dcproject.common.entity
|
||||
|
||||
import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.postgresjson.entity.EntityCreatedBy
|
||||
import fr.postgresjson.entity.EntityI
|
||||
|
||||
/**
|
||||
* TODO remove EntityCreatedBy<EntityI>
|
||||
*/
|
||||
interface CreatedBy<T : CitizenI> : EntityCreatedBy<EntityI> {
|
||||
override val createdBy: T
|
||||
}
|
||||
|
||||
class CreatedByImp<T : CitizenI>(override val createdBy: T) : CreatedBy<T>
|
||||
30
src/main/kotlin/fr/dcproject/common/entity/Date.kt
Normal file
30
src/main/kotlin/fr/dcproject/common/entity/Date.kt
Normal file
@@ -0,0 +1,30 @@
|
||||
package fr.dcproject.common.entity
|
||||
|
||||
import org.joda.time.DateTime
|
||||
|
||||
/* Interface */
|
||||
interface CreatedAt {
|
||||
val createdAt: DateTime
|
||||
class Imp(
|
||||
override val createdAt: DateTime = DateTime.now()
|
||||
) : CreatedAt
|
||||
}
|
||||
interface UpdatedAt {
|
||||
val updatedAt: DateTime
|
||||
class Imp(
|
||||
override val updatedAt: DateTime = DateTime.now()
|
||||
) : UpdatedAt
|
||||
}
|
||||
|
||||
interface DeletedAt {
|
||||
val deletedAt: DateTime?
|
||||
fun isDeleted(): Boolean {
|
||||
return deletedAt?.let {
|
||||
it < DateTime.now()
|
||||
} ?: false
|
||||
}
|
||||
|
||||
class Imp(
|
||||
override val deletedAt: DateTime? = null
|
||||
) : DeletedAt
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
package fr.dcproject.common.entity
|
||||
|
||||
import fr.postgresjson.entity.EntityI
|
||||
import fr.postgresjson.entity.UuidEntityI
|
||||
import java.util.UUID
|
||||
|
||||
interface EntityI : EntityI {
|
||||
val id: UUID
|
||||
interface EntityI : UuidEntityI {
|
||||
override val id: UUID
|
||||
}
|
||||
|
||||
open class Entity(id: UUID? = null) : EntityI {
|
||||
override val id: UUID = id ?: UUID.randomUUID()
|
||||
}
|
||||
|
||||
@@ -5,25 +5,21 @@ import fr.dcproject.component.citizen.CitizenI
|
||||
import fr.dcproject.component.comment.generic.CommentRef
|
||||
import fr.dcproject.component.constitution.ConstitutionRef
|
||||
import fr.dcproject.component.opinion.entity.OpinionRef
|
||||
import fr.postgresjson.entity.EntityCreatedAt
|
||||
import fr.postgresjson.entity.EntityCreatedBy
|
||||
import fr.postgresjson.entity.UuidEntity
|
||||
import fr.postgresjson.entity.UuidEntityI
|
||||
import java.util.UUID
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.full.isSubclassOf
|
||||
|
||||
interface ExtraI<T : TargetI, C : CitizenI> :
|
||||
UuidEntityI,
|
||||
EntityI,
|
||||
HasTarget<T>,
|
||||
EntityCreatedAt,
|
||||
EntityCreatedBy<C>
|
||||
CreatedAt,
|
||||
CreatedBy<C>
|
||||
|
||||
interface HasTarget<T : TargetI> {
|
||||
val target: T
|
||||
}
|
||||
|
||||
open class TargetRef(id: UUID? = null, reference: String = "") : TargetI, UuidEntity(id) {
|
||||
open class TargetRef(id: UUID? = null, reference: String = "") : TargetI, Entity(id) {
|
||||
|
||||
final override val reference: String
|
||||
get() = if (field != "") field else TargetI.getReference(this)
|
||||
@@ -33,7 +29,7 @@ open class TargetRef(id: UUID? = null, reference: String = "") : TargetI, UuidEn
|
||||
}
|
||||
}
|
||||
|
||||
interface TargetI : UuidEntityI {
|
||||
interface TargetI : EntityI {
|
||||
enum class TargetName(val targetReference: String) {
|
||||
Article("article"),
|
||||
Constitution("constitution"),
|
||||
|
||||
@@ -1,17 +1,25 @@
|
||||
package fr.dcproject.common.entity
|
||||
|
||||
import fr.postgresjson.entity.EntityVersioning
|
||||
import java.util.UUID
|
||||
|
||||
interface VersionableRef {
|
||||
interface VersionableId {
|
||||
val versionId: UUID
|
||||
|
||||
class Imp(
|
||||
versionId: UUID? = null,
|
||||
) : VersionableId {
|
||||
override val versionId: UUID = versionId ?: UUID.randomUUID()
|
||||
}
|
||||
}
|
||||
|
||||
class VersionableRefImp(
|
||||
interface Versionable : VersionableId {
|
||||
override val versionId: UUID
|
||||
) : VersionableRef
|
||||
val versionNumber: Int
|
||||
|
||||
interface Versionable : VersionableRef, EntityVersioning<UUID, Int> {
|
||||
override val versionId: UUID
|
||||
override val versionNumber: Int
|
||||
class Imp(
|
||||
override val versionNumber: Int,
|
||||
versionId: UUID? = null,
|
||||
) : Versionable {
|
||||
override val versionId: UUID = versionId ?: UUID.randomUUID()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user