feature #12: Add constitution Entity, repository and route
This commit is contained in:
@@ -2,8 +2,8 @@ package fr.dcproject.repository
|
||||
|
||||
import fr.postgresjson.connexion.Paginated
|
||||
import fr.postgresjson.connexion.Requester
|
||||
import fr.postgresjson.entity.EntitiesCollections
|
||||
import fr.postgresjson.repository.RepositoryI
|
||||
import fr.postgresjson.repository.RepositoryI.Direction
|
||||
import net.pearx.kasechange.toSnakeCase
|
||||
import java.util.*
|
||||
import fr.dcproject.entity.Article as ArticleEntity
|
||||
@@ -13,12 +13,7 @@ class Article(override var requester: Requester) : RepositoryI<ArticleEntity> {
|
||||
|
||||
fun findById(id: UUID): ArticleEntity? {
|
||||
val function = requester.getFunction("find_article_by_id")
|
||||
return when (val e = EntitiesCollections().get(id) as ArticleEntity?) {
|
||||
null -> {
|
||||
function.selectOne("id" to id)
|
||||
}
|
||||
else -> e
|
||||
}
|
||||
return function.selectOne("id" to id)
|
||||
}
|
||||
|
||||
fun find(
|
||||
@@ -41,13 +36,6 @@ class Article(override var requester: Requester) : RepositoryI<ArticleEntity> {
|
||||
fun upsert(article: ArticleEntity): ArticleEntity? {
|
||||
return requester
|
||||
.getFunction("upsert_article")
|
||||
.selectOne<ArticleEntity>("resource" to article)?.also {
|
||||
EntitiesCollections().set(it)
|
||||
}
|
||||
}
|
||||
|
||||
enum class Direction {
|
||||
asc,
|
||||
desc
|
||||
.selectOne("resource" to article)
|
||||
}
|
||||
}
|
||||
|
||||
41
src/main/kotlin/fr/dcproject/repository/Constitution.kt
Normal file
41
src/main/kotlin/fr/dcproject/repository/Constitution.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
package fr.dcproject.repository
|
||||
|
||||
import fr.postgresjson.connexion.Paginated
|
||||
import fr.postgresjson.connexion.Requester
|
||||
import fr.postgresjson.repository.RepositoryI
|
||||
import fr.postgresjson.repository.RepositoryI.Direction
|
||||
import net.pearx.kasechange.toSnakeCase
|
||||
import java.util.*
|
||||
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
||||
|
||||
class Constitution(override var requester: Requester) : RepositoryI<ConstitutionEntity> {
|
||||
override val entityName = ConstitutionEntity::class
|
||||
|
||||
fun findById(id: UUID): ConstitutionEntity? {
|
||||
val function = requester.getFunction("find_constitution_by_id")
|
||||
return function.selectOne("id" to id)
|
||||
}
|
||||
|
||||
fun find(
|
||||
page: Int = 1,
|
||||
limit: Int = 50,
|
||||
sort: String? = null,
|
||||
direction: Direction? = null,
|
||||
search: String? = null
|
||||
): Paginated<ConstitutionEntity> {
|
||||
return requester
|
||||
.getFunction("find_constitutions")
|
||||
.select(
|
||||
page, limit,
|
||||
"sort" to sort?.toSnakeCase(),
|
||||
"direction" to direction,
|
||||
"search" to search
|
||||
)
|
||||
}
|
||||
|
||||
fun upsert(article: ConstitutionEntity): ConstitutionEntity? {
|
||||
return requester
|
||||
.getFunction("upsert_constitution")
|
||||
.selectOne("resource" to article)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user