diff --git a/src/main/kotlin/fr/postgresjson/serializer/Serializer.kt b/src/main/kotlin/fr/postgresjson/Serializer.kt similarity index 98% rename from src/main/kotlin/fr/postgresjson/serializer/Serializer.kt rename to src/main/kotlin/fr/postgresjson/Serializer.kt index 2d88019..c2487f4 100644 --- a/src/main/kotlin/fr/postgresjson/serializer/Serializer.kt +++ b/src/main/kotlin/fr/postgresjson/Serializer.kt @@ -1,4 +1,4 @@ -package fr.postgresjson.serializer +package fr.postgresjson import com.fasterxml.jackson.core.JsonParser import com.fasterxml.jackson.core.JsonProcessingException diff --git a/src/main/kotlin/fr/postgresjson/connexion/Connection.kt b/src/main/kotlin/fr/postgresjson/connexion/Connection.kt index 8ecc931..94780f0 100644 --- a/src/main/kotlin/fr/postgresjson/connexion/Connection.kt +++ b/src/main/kotlin/fr/postgresjson/connexion/Connection.kt @@ -3,8 +3,8 @@ package fr.postgresjson.connexion import com.github.jasync.sql.db.pool.ConnectionPool import com.github.jasync.sql.db.postgresql.PostgreSQLConnection import com.github.jasync.sql.db.postgresql.PostgreSQLConnectionBuilder +import fr.postgresjson.Serializer import fr.postgresjson.entity.EntityI -import fr.postgresjson.serializer.Serializer import java.io.File diff --git a/src/main/kotlin/fr/postgresjson/entity/Entity.kt b/src/main/kotlin/fr/postgresjson/entity/Entity.kt index 3dbbd42..4f9b132 100644 --- a/src/main/kotlin/fr/postgresjson/entity/Entity.kt +++ b/src/main/kotlin/fr/postgresjson/entity/Entity.kt @@ -1,16 +1,90 @@ package fr.postgresjson.entity +import org.joda.time.DateTime import java.util.* +/* ID */ interface EntityI { var id: T? } + abstract class Entity(override var id: T? = null) : EntityI abstract class UuidEntity(override var id: UUID? = UUID.randomUUID()) : Entity(id) abstract class IdEntity(override var id: Int? = null) : Entity(id) +/* Version */ interface EntityVersioning { var version: T } -interface EntityVersioningIncrement : EntityVersioning +interface EntityVersioningIncrement : EntityVersioning +class EntityVersioningIncrementImp() : EntityVersioningIncrement { + override var version: Int? = null +} + +interface EntityVersioningDate : EntityVersioning +class EntityVersioningDateImp() : EntityVersioningDate { + override var version: DateTime? = null +} + +/* Dates */ +interface EntityCreatedAt { + var createdAt: DateTime? +} + +interface EntityUpdatedAt { + var updatedAt: DateTime? +} + +class EntityCreatedAtImp : EntityCreatedAt { + override var createdAt: DateTime? = null +} + +class EntityUpdatedAtImp : EntityUpdatedAt { + override var updatedAt: DateTime? = null +} + +interface User : EntityI { + fun isValid(): Boolean +} + +/* Author */ +interface CreatedBy { + var createdBy: User? +} + +interface UpdatedBy { + var updatedBy: User? +} + +class EntityCreatedByImp : CreatedBy { + override var createdBy: User? = null +} + +class EntityUpdatedByImp : UpdatedBy { + override var updatedBy: User? = null +} + +/* Published */ +interface Published { + var publishedAt: DateTime? + var publishedBy: User? +} + +class EntityPublishedImp : Published { + override var publishedAt: DateTime? = null + override var publishedBy: User? = null +} + +/* Implementation */ +abstract class EntityImp : Entity(), + EntityCreatedAt by EntityCreatedAtImp(), + EntityUpdatedAt by EntityUpdatedAtImp(), + CreatedBy by EntityCreatedByImp(), + UpdatedBy by EntityUpdatedByImp() + +abstract class EntityExtended : + EntityImp(), + EntityVersioningIncrement by EntityVersioningIncrementImp(), + Published by EntityPublishedImp() + diff --git a/src/main/kotlin/fr/postgresjson/repository/Repository.kt b/src/main/kotlin/fr/postgresjson/repository/Repository.kt index e876ce7..d4228ff 100644 --- a/src/main/kotlin/fr/postgresjson/repository/Repository.kt +++ b/src/main/kotlin/fr/postgresjson/repository/Repository.kt @@ -2,9 +2,9 @@ package fr.postgresjson.repository import com.github.jasync.sql.db.pool.ConnectionPool import com.github.jasync.sql.db.postgresql.PostgreSQLConnection +import fr.postgresjson.Serializer import fr.postgresjson.entity.EntityCollection import fr.postgresjson.entity.EntityI -import fr.postgresjson.serializer.Serializer interface RepositoryI> diff --git a/src/test/kotlin/fr/postgresjson/serializer/ConnectionTest.kt b/src/test/kotlin/fr/postgresjson/ConnectionTest.kt similarity index 98% rename from src/test/kotlin/fr/postgresjson/serializer/ConnectionTest.kt rename to src/test/kotlin/fr/postgresjson/ConnectionTest.kt index d4f45a2..ece901e 100644 --- a/src/test/kotlin/fr/postgresjson/serializer/ConnectionTest.kt +++ b/src/test/kotlin/fr/postgresjson/ConnectionTest.kt @@ -1,4 +1,4 @@ -package fr.postgresjson.serializer +package fr.postgresjson import fr.postgresjson.connexion.Connection import fr.postgresjson.entity.IdEntity diff --git a/src/test/kotlin/fr/postgresjson/EntityTest.kt b/src/test/kotlin/fr/postgresjson/EntityTest.kt new file mode 100644 index 0000000..074a26e --- /dev/null +++ b/src/test/kotlin/fr/postgresjson/EntityTest.kt @@ -0,0 +1,25 @@ +package fr.postgresjson + +import fr.postgresjson.entity.* +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestInstance + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class EntityTest() { + private class ObjTest(var name: String): EntityExtended() + + @Test + fun getObject() { + val obj: ObjTest? = ObjTest("plop") + assertTrue(obj is ObjTest) + assertTrue(obj is EntityExtended) + assertTrue(obj is EntityI) + assertTrue(obj is Entity) + assertTrue(obj is Published) + assertTrue(obj is CreatedBy) + assertTrue(obj is UpdatedBy) + assertTrue(obj is EntityCreatedAt) + assertTrue(obj is EntityUpdatedAt) + } +} \ No newline at end of file diff --git a/src/test/kotlin/fr/postgresjson/serializer/RequestTest.kt b/src/test/kotlin/fr/postgresjson/RequestTest.kt similarity index 94% rename from src/test/kotlin/fr/postgresjson/serializer/RequestTest.kt rename to src/test/kotlin/fr/postgresjson/RequestTest.kt index c4d1a70..85cb30d 100644 --- a/src/test/kotlin/fr/postgresjson/serializer/RequestTest.kt +++ b/src/test/kotlin/fr/postgresjson/RequestTest.kt @@ -1,4 +1,4 @@ -package fr.postgresjson.serializer +package fr.postgresjson import fr.postgresjson.connexion.Connection import fr.postgresjson.entity.IdEntity diff --git a/src/test/kotlin/fr/postgresjson/serializer/SerializerTest.kt b/src/test/kotlin/fr/postgresjson/SerializerTest.kt similarity index 98% rename from src/test/kotlin/fr/postgresjson/serializer/SerializerTest.kt rename to src/test/kotlin/fr/postgresjson/SerializerTest.kt index ed1126d..d957375 100644 --- a/src/test/kotlin/fr/postgresjson/serializer/SerializerTest.kt +++ b/src/test/kotlin/fr/postgresjson/SerializerTest.kt @@ -1,4 +1,4 @@ -package fr.postgresjson.serializer +package fr.postgresjson import fr.postgresjson.entity.IdEntity import org.junit.jupiter.api.Assertions.assertEquals