Split Entities for remove nullable variables
This commit is contained in:
@@ -1,26 +1,77 @@
|
||||
package fr.dcproject.entity
|
||||
import fr.postgresjson.entity.mutable.*
|
||||
import fr.postgresjson.entity.immutable.*
|
||||
import fr.postgresjson.entity.mutable.EntityDeletedAt
|
||||
import fr.postgresjson.entity.mutable.EntityDeletedAtImp
|
||||
import fr.postgresjson.entity.mutable.EntityVersioning
|
||||
import fr.postgresjson.entity.mutable.UuidEntityVersioning
|
||||
import java.util.*
|
||||
|
||||
class Article(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
var title: String?,
|
||||
var anonymous: Boolean? = true,
|
||||
var content: String?,
|
||||
var description: String?,
|
||||
var tags: List<String> = emptyList(),
|
||||
var draft: Boolean = false,
|
||||
var lastVersion: Boolean = false,
|
||||
createdBy: Citizen?
|
||||
) :
|
||||
UuidEntity(id),
|
||||
EntityVersioning<UUID, Int> by UuidEntityVersioning(),
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityCreatedBy<Citizen> by EntityCreatedByImp(createdBy),
|
||||
EntityDeletedAt by EntityDeletedAtImp(),
|
||||
Votable by VotableImp() {
|
||||
title: String,
|
||||
anonymous: Boolean = true,
|
||||
content: String,
|
||||
description: String,
|
||||
tags: List<String> = emptyList(),
|
||||
override var draft: Boolean = false,
|
||||
override var lastVersion: Boolean = false,
|
||||
createdBy: CitizenBasic
|
||||
) : ArticleFull,
|
||||
ArticleBasic(id, title, anonymous, content, description, tags, createdBy)
|
||||
|
||||
open class ArticleBasic(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
title: String,
|
||||
override var anonymous: Boolean = true,
|
||||
override var content: String,
|
||||
override var description: String,
|
||||
override var tags: List<String> = emptyList(),
|
||||
override val createdBy: CitizenBasic
|
||||
) : ArticleBasicI,
|
||||
ArticleSimple(id, title, createdBy) {
|
||||
|
||||
init {
|
||||
tags = tags.distinct()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class ArticleSimple(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
override var title: String,
|
||||
override val createdBy: CitizenBasic
|
||||
) : ArticleSimpleI,
|
||||
ArticleRef(id),
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityCreatedBy<CitizenBasicI> by EntityCreatedByImp(createdBy),
|
||||
EntityDeletedAt by EntityDeletedAtImp(),
|
||||
EntityVersioning<UUID, Int> by UuidEntityVersioning(),
|
||||
Votable by VotableImp()
|
||||
|
||||
open class ArticleRef(
|
||||
id: UUID = UUID.randomUUID()
|
||||
) : ArticleI, TargetRef(id)
|
||||
|
||||
interface ArticleI : UuidEntityI, TargetI
|
||||
|
||||
interface ArticleSimpleI :
|
||||
ArticleI,
|
||||
EntityVersioning<UUID, Int>,
|
||||
EntityCreatedBy<CitizenBasicI>,
|
||||
EntityCreatedAt,
|
||||
EntityDeletedAt,
|
||||
Votable {
|
||||
var title: String
|
||||
}
|
||||
interface ArticleBasicI :
|
||||
ArticleSimpleI {
|
||||
var anonymous: Boolean
|
||||
var content: String
|
||||
var description: String
|
||||
var tags: List<String>
|
||||
}
|
||||
|
||||
interface ArticleFull :
|
||||
ArticleBasicI {
|
||||
var draft: Boolean
|
||||
var lastVersion: Boolean
|
||||
}
|
||||
|
||||
@@ -1,24 +1,68 @@
|
||||
package fr.dcproject.entity
|
||||
|
||||
import fr.postgresjson.entity.mutable.*
|
||||
import fr.dcproject.entity.CitizenI.Name
|
||||
import fr.postgresjson.entity.immutable.EntityCreatedAt
|
||||
import fr.postgresjson.entity.immutable.EntityCreatedAtImp
|
||||
import fr.postgresjson.entity.immutable.UuidEntity
|
||||
import fr.postgresjson.entity.immutable.UuidEntityI
|
||||
import fr.postgresjson.entity.mutable.EntityDeletedAt
|
||||
import fr.postgresjson.entity.mutable.EntityDeletedAtImp
|
||||
import org.joda.time.DateTime
|
||||
import java.util.*
|
||||
|
||||
class Citizen(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
var name: Name?,
|
||||
var email: String?,
|
||||
var birthday: DateTime?,
|
||||
var userId: UUID? = null,
|
||||
var voteAnonymous: Boolean = true,
|
||||
var followAnonymous: Boolean = true,
|
||||
var user: User?
|
||||
name: Name,
|
||||
email: String,
|
||||
birthday: DateTime,
|
||||
voteAnonymous: Boolean = true,
|
||||
followAnonymous: Boolean = true,
|
||||
override val user: User
|
||||
) : CitizenFull,
|
||||
CitizenBasic(id, name, email, birthday, voteAnonymous, followAnonymous, user),
|
||||
EntityCreatedAt by EntityCreatedAtImp()
|
||||
|
||||
open class CitizenBasic(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
name: Name,
|
||||
override var email: String,
|
||||
override var birthday: DateTime,
|
||||
override var voteAnonymous: Boolean = true,
|
||||
override var followAnonymous: Boolean = true,
|
||||
user: UserRef
|
||||
) : CitizenBasicI,
|
||||
CitizenSimple(id, name, user)
|
||||
|
||||
open class CitizenSimple(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
var name: Name,
|
||||
user: UserRef
|
||||
) : CitizenRef(id, user)
|
||||
|
||||
open class CitizenRef(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
open val user: UserRef
|
||||
) : UuidEntity(id),
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityDeletedAt by EntityDeletedAtImp() {
|
||||
CitizenI,
|
||||
EntityDeletedAt by EntityDeletedAtImp()
|
||||
|
||||
interface CitizenI : UuidEntityI {
|
||||
data class Name(
|
||||
var firstName: String?,
|
||||
var lastName: String?,
|
||||
var firstName: String,
|
||||
var lastName: String,
|
||||
var civility: String? = null
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
interface CitizenBasicI : CitizenI, EntityDeletedAt {
|
||||
var name: Name
|
||||
var email: String
|
||||
var birthday: DateTime
|
||||
var voteAnonymous: Boolean
|
||||
var followAnonymous: Boolean
|
||||
val user: UserI
|
||||
}
|
||||
|
||||
interface CitizenFull : CitizenBasicI {
|
||||
override val user: User
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package fr.dcproject.entity
|
||||
|
||||
import fr.postgresjson.entity.mutable.*
|
||||
import fr.postgresjson.entity.immutable.EntityUpdatedAt
|
||||
import fr.postgresjson.entity.immutable.EntityUpdatedAtImp
|
||||
import fr.postgresjson.entity.mutable.EntityDeletedAt
|
||||
import fr.postgresjson.entity.mutable.EntityDeletedAtImp
|
||||
import java.util.*
|
||||
|
||||
open class Comment <T : UuidEntity> (
|
||||
open class Comment<T : TargetI>(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
createdBy: Citizen,
|
||||
override val createdBy: CitizenBasic,
|
||||
target: T,
|
||||
override var targetReference: String = target::class.simpleName!!.toLowerCase(),
|
||||
var content: String,
|
||||
val responses: List<Comment<T>>? = null,
|
||||
var parent: Comment<T>? = null,
|
||||
@@ -16,17 +18,18 @@ open class Comment <T : UuidEntity> (
|
||||
) : Extra<T>(id, createdBy, target),
|
||||
EntityUpdatedAt by EntityUpdatedAtImp(),
|
||||
EntityDeletedAt by EntityDeletedAtImp(),
|
||||
Votable by VotableImp()
|
||||
{
|
||||
Votable by VotableImp(),
|
||||
TargetI {
|
||||
constructor(
|
||||
createdBy: Citizen,
|
||||
createdBy: CitizenBasic,
|
||||
parent: Comment<T>,
|
||||
content: String
|
||||
) : this(
|
||||
createdBy = createdBy,
|
||||
parent = parent,
|
||||
target = parent.target,
|
||||
targetReference = parent.targetReference,
|
||||
content = content
|
||||
)
|
||||
|
||||
override val reference get() = TargetI.getReference(this)
|
||||
}
|
||||
|
||||
@@ -1,36 +1,69 @@
|
||||
package fr.dcproject.entity
|
||||
|
||||
import fr.postgresjson.entity.mutable.*
|
||||
import fr.postgresjson.entity.immutable.*
|
||||
import fr.postgresjson.entity.mutable.EntityDeletedAt
|
||||
import fr.postgresjson.entity.mutable.EntityDeletedAtImp
|
||||
import java.util.*
|
||||
|
||||
class Constitution(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
var title: String?,
|
||||
var anonymous: Boolean? = true,
|
||||
var titles: List<Title> = listOf(),
|
||||
title: String,
|
||||
anonymous: Boolean = true,
|
||||
titles: MutableList<TitleSimple<ArticleSimple>> = mutableListOf(),
|
||||
draft: Boolean = false,
|
||||
lastVersion: Boolean = false,
|
||||
override val createdBy: CitizenSimple
|
||||
) : ConstitutionSimple<CitizenSimple, ConstitutionSimple.TitleSimple<ArticleSimple>>(
|
||||
id,
|
||||
title = title,
|
||||
anonymous = anonymous,
|
||||
titles = titles,
|
||||
draft = draft,
|
||||
lastVersion = lastVersion,
|
||||
createdBy = createdBy
|
||||
) {
|
||||
|
||||
class Title(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
name: String,
|
||||
rank: Int? = null,
|
||||
override val articles: MutableList<ArticleSimple> = mutableListOf()
|
||||
) : ConstitutionSimple.TitleSimple<ArticleSimple>(id, name, rank)
|
||||
}
|
||||
|
||||
open class ConstitutionSimple<Cr : CitizenRef, T : ConstitutionSimple.TitleSimple<*>>(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
var title: String,
|
||||
var anonymous: Boolean = true,
|
||||
open var titles: MutableList<T> = mutableListOf(),
|
||||
var draft: Boolean = false,
|
||||
var lastVersion: Boolean = false,
|
||||
createdBy: Citizen?
|
||||
) : UuidEntity(id),
|
||||
EntityVersioning<UUID, Int> by UuidEntityVersioning(),
|
||||
override val createdBy: Cr,
|
||||
versionId: UUID = UUID.randomUUID()
|
||||
) : ConstitutionRef(id),
|
||||
EntityVersioning<UUID, Int?> by UuidEntityVersioning(versionId = versionId),
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityCreatedBy<Citizen> by EntityCreatedByImp(createdBy),
|
||||
EntityCreatedBy<Cr> by EntityCreatedByImp(createdBy),
|
||||
EntityDeletedAt by EntityDeletedAtImp() {
|
||||
|
||||
init {
|
||||
titles.forEachIndexed { index, title ->
|
||||
title.createdBy = this.createdBy
|
||||
title.rank = index
|
||||
}
|
||||
}
|
||||
|
||||
class Title(
|
||||
open class TitleSimple<A : ArticleI>(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
var name: String?,
|
||||
var name: String,
|
||||
var rank: Int? = null,
|
||||
var articles: List<Article> = listOf(),
|
||||
createdBy: Citizen? = null
|
||||
) : UuidEntity(id),
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityCreatedBy<Citizen> by EntityCreatedByImp(createdBy)
|
||||
open val articles: MutableList<A> = mutableListOf()
|
||||
) : TitleRef(id)
|
||||
}
|
||||
|
||||
open class ConstitutionRef(id: UUID = UUID.randomUUID()) : ConstitutionS(id) {
|
||||
open class TitleRef(
|
||||
id: UUID = UUID.randomUUID()
|
||||
) : UuidEntity(id)
|
||||
}
|
||||
|
||||
sealed class ConstitutionS(id: UUID = UUID.randomUUID()) : TargetRef(id), TargetI
|
||||
@@ -1,24 +1,62 @@
|
||||
package fr.dcproject.entity
|
||||
|
||||
import fr.postgresjson.entity.EntityI
|
||||
import fr.postgresjson.entity.mutable.*
|
||||
import fr.postgresjson.entity.immutable.*
|
||||
import java.util.*
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.full.isSuperclassOf
|
||||
|
||||
interface ExtraI <T : EntityI> :
|
||||
EntityI,
|
||||
interface ExtraI<T : TargetI> :
|
||||
UuidEntityI,
|
||||
EntityCreatedAt,
|
||||
EntityCreatedBy<Citizen> {
|
||||
EntityCreatedBy<CitizenBasicI> {
|
||||
var target: T
|
||||
var targetReference: String
|
||||
}
|
||||
|
||||
abstract class Extra<T : UuidEntity>(
|
||||
id: UUID? = UUID.randomUUID(),
|
||||
createdBy: Citizen,
|
||||
override var target: T,
|
||||
override var targetReference: String = target::class.simpleName!!.toLowerCase()
|
||||
abstract class Extra<T : TargetI>(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
override val createdBy: CitizenBasic,
|
||||
override var target: T
|
||||
) :
|
||||
ExtraI<T>,
|
||||
UuidEntity(id),
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityCreatedBy<Citizen> by EntityCreatedByImp(createdBy)
|
||||
EntityCreatedBy<CitizenBasicI> by EntityCreatedByImp(createdBy)
|
||||
|
||||
open class TargetRef(id: UUID = UUID.randomUUID()) : TargetI, UuidEntity(id) {
|
||||
override val reference: String = ""
|
||||
get() {
|
||||
return if (field != "") field else TargetI.getReference(this)
|
||||
}
|
||||
}
|
||||
|
||||
interface TargetI : UuidEntityI {
|
||||
enum class TargetName(val targetReference: String) {
|
||||
Article("article"),
|
||||
Constitution("constitution"),
|
||||
Comment("comment")
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun <T : TargetI> getReference(t: KClass<T>): String {
|
||||
return when {
|
||||
t.isSuperclassOf(Article::class) -> TargetName.Article.targetReference
|
||||
t.isSuperclassOf(Constitution::class) -> TargetName.Constitution.targetReference
|
||||
t.isSuperclassOf(Comment::class) -> TargetName.Comment.targetReference
|
||||
else -> throw error("target not implemented")
|
||||
}
|
||||
}
|
||||
|
||||
fun getReference(t: TargetI): String {
|
||||
val ref = this.getReference(t::class)
|
||||
return if (t is ExtraI<*>) {
|
||||
ref +
|
||||
"_on_" +
|
||||
t.target.reference
|
||||
} else {
|
||||
ref
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val reference: String
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
package fr.dcproject.entity
|
||||
import fr.postgresjson.entity.mutable.UuidEntity
|
||||
import java.util.*
|
||||
|
||||
class Follow <T : UuidEntity> (
|
||||
class Follow <T : TargetI> (
|
||||
id: UUID = UUID.randomUUID(),
|
||||
createdBy: Citizen,
|
||||
override val createdBy: CitizenBasic,
|
||||
target: T
|
||||
) : Extra<T>(id, createdBy, target)
|
||||
|
||||
@@ -1,19 +1,41 @@
|
||||
package fr.dcproject.entity
|
||||
|
||||
import fr.postgresjson.entity.mutable.*
|
||||
import fr.dcproject.entity.UserI.Roles
|
||||
import fr.postgresjson.entity.immutable.*
|
||||
import io.ktor.auth.Principal
|
||||
import org.joda.time.DateTime
|
||||
import java.util.*
|
||||
|
||||
class User(
|
||||
id: UUID? = UUID.randomUUID(),
|
||||
var username: String?,
|
||||
var blockedAt: DateTime? = null,
|
||||
var plainPassword: String?,
|
||||
var roles: List<Roles> = emptyList()
|
||||
) : UuidEntity(id),
|
||||
id: UUID = UUID.randomUUID(),
|
||||
username: String,
|
||||
blockedAt: DateTime? = null,
|
||||
override var plainPassword: String?,
|
||||
override var roles: List<Roles> = emptyList()
|
||||
) : UserFull, UserBasic(id, username, blockedAt),
|
||||
EntityCreatedAt by EntityCreatedAtImp(),
|
||||
EntityUpdatedAt by EntityUpdatedAtImp(),
|
||||
Principal {
|
||||
EntityUpdatedAt by EntityUpdatedAtImp()
|
||||
|
||||
open class UserBasic(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
override var username: String,
|
||||
override var blockedAt: DateTime? = null
|
||||
) : UserBasicI, UserRef(id)
|
||||
|
||||
open class UserRef(
|
||||
id: UUID = UUID.randomUUID()
|
||||
) : UserI, UuidEntity(id)
|
||||
|
||||
interface UserI : UuidEntityI, Principal {
|
||||
enum class Roles { ROLE_USER, ROLE_ADMIN }
|
||||
}
|
||||
|
||||
interface UserBasicI : UserI {
|
||||
var username: String
|
||||
var blockedAt: DateTime?
|
||||
}
|
||||
|
||||
interface UserFull : UserBasicI, EntityCreatedAt, EntityUpdatedAt {
|
||||
var plainPassword: String?
|
||||
var roles: List<Roles>
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package fr.dcproject.entity
|
||||
|
||||
import fr.postgresjson.entity.mutable.EntityUpdatedAt
|
||||
import fr.postgresjson.entity.mutable.EntityUpdatedAtImp
|
||||
import fr.postgresjson.entity.mutable.UuidEntity
|
||||
import fr.postgresjson.entity.immutable.EntityUpdatedAt
|
||||
import fr.postgresjson.entity.immutable.EntityUpdatedAtImp
|
||||
import java.util.*
|
||||
|
||||
open class Vote <T : UuidEntity> (
|
||||
open class Vote <T : TargetI> (
|
||||
id: UUID = UUID.randomUUID(),
|
||||
createdBy: Citizen,
|
||||
override val createdBy: CitizenBasic,
|
||||
target: T,
|
||||
var note: Int,
|
||||
var anonymous: Boolean = true
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fr.dcproject.entity.request
|
||||
|
||||
import fr.dcproject.entity.ArticleFull
|
||||
import fr.dcproject.entity.Citizen
|
||||
import java.util.*
|
||||
import fr.dcproject.entity.Article as ArticleEntity
|
||||
@@ -7,7 +8,7 @@ import fr.dcproject.entity.Article as ArticleEntity
|
||||
class Article(
|
||||
val id: UUID?,
|
||||
val title: String,
|
||||
val anonymous: Boolean? = true,
|
||||
val anonymous: Boolean = true,
|
||||
val content: String,
|
||||
val description: String,
|
||||
val tags: List<String> = emptyList(),
|
||||
@@ -16,7 +17,7 @@ class Article(
|
||||
) :
|
||||
Request {
|
||||
|
||||
fun merge(article: ArticleEntity) {
|
||||
fun merge(article: ArticleFull) {
|
||||
article.title = this.title
|
||||
article.content = this.content
|
||||
article.description = this.description
|
||||
|
||||
48
src/main/kotlin/fr/dcproject/entity/request/Constitution.kt
Normal file
48
src/main/kotlin/fr/dcproject/entity/request/Constitution.kt
Normal file
@@ -0,0 +1,48 @@
|
||||
package fr.dcproject.entity.request
|
||||
|
||||
import fr.dcproject.entity.ArticleRef
|
||||
import fr.dcproject.entity.Citizen
|
||||
import fr.dcproject.entity.CitizenSimple
|
||||
import fr.dcproject.entity.ConstitutionSimple
|
||||
import fr.postgresjson.entity.immutable.UuidEntity
|
||||
import java.util.*
|
||||
|
||||
class Constitution(
|
||||
var title: String,
|
||||
var anonymous: Boolean = true,
|
||||
var titles: MutableList<Title> = mutableListOf(),
|
||||
var draft: Boolean = false,
|
||||
var lastVersion: Boolean = false,
|
||||
var versionId: UUID = UUID.randomUUID()
|
||||
) {
|
||||
init {
|
||||
titles.forEachIndexed { index, title ->
|
||||
title.rank = index
|
||||
}
|
||||
}
|
||||
|
||||
class Title(
|
||||
id: UUID = UUID.randomUUID(),
|
||||
var name: String,
|
||||
var rank: Int? = null,
|
||||
var articles: MutableList<ArticleRef> = mutableListOf()
|
||||
) : UuidEntity(id) {
|
||||
fun create(): ConstitutionSimple.TitleSimple<ArticleRef> {
|
||||
return ConstitutionSimple.TitleSimple(
|
||||
id, name, rank, articles
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun create(createdBy: Citizen): ConstitutionSimple<CitizenSimple, ConstitutionSimple.TitleSimple<ArticleRef>> {
|
||||
return ConstitutionSimple(
|
||||
title = title,
|
||||
titles = titles.create(),
|
||||
createdBy = createdBy,
|
||||
versionId = versionId
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun List<Constitution.Title>.create(): MutableList<ConstitutionSimple.TitleSimple<ArticleRef>> =
|
||||
map { it.create() }.toMutableList()
|
||||
Reference in New Issue
Block a user