Lint project
This commit is contained in:
@@ -143,7 +143,7 @@ fun Application.module(env: Env = PROD) {
|
|||||||
|
|
||||||
registerModule(JodaModule())
|
registerModule(JodaModule())
|
||||||
disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||||
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||||
configure(SerializationFeature.INDENT_OUTPUT, true)
|
configure(SerializationFeature.INDENT_OUTPUT, true)
|
||||||
setDefaultPrettyPrinter(DefaultPrettyPrinter().apply {
|
setDefaultPrettyPrinter(DefaultPrettyPrinter().apply {
|
||||||
indentArraysWith(DefaultPrettyPrinter.FixedSpaceIndenter.instance)
|
indentArraysWith(DefaultPrettyPrinter.FixedSpaceIndenter.instance)
|
||||||
|
|||||||
@@ -50,5 +50,4 @@ object JwtConfig {
|
|||||||
* Calculate the expiration Date based on current time + the given validity
|
* Calculate the expiration Date based on current time + the given validity
|
||||||
*/
|
*/
|
||||||
private fun getExpiration() = Date(System.currentTimeMillis() + validityInMs)
|
private fun getExpiration() = Date(System.currentTimeMillis() + validityInMs)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -50,6 +50,6 @@ val Module = module {
|
|||||||
|
|
||||||
single { Migrations(connection = get(), directory = config.sqlFiles) }
|
single { Migrations(connection = get(), directory = config.sqlFiles) }
|
||||||
|
|
||||||
single { Mailer(config.sendGridKey) }
|
single { Mailer(config.sendGridKey) }
|
||||||
single { SsoManager(get<Mailer>(), config.domain, get()) }
|
single { SsoManager(get<Mailer>(), config.domain, get()) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class Article(
|
|||||||
var draft: Boolean = false,
|
var draft: Boolean = false,
|
||||||
var lastVersion: Boolean = false,
|
var lastVersion: Boolean = false,
|
||||||
createdBy: Citizen?
|
createdBy: Citizen?
|
||||||
):
|
) :
|
||||||
UuidEntity(id),
|
UuidEntity(id),
|
||||||
EntityVersioning<UUID, Int> by UuidEntityVersioning(),
|
EntityVersioning<UUID, Int> by UuidEntityVersioning(),
|
||||||
EntityCreatedAt by EntityCreatedAtImp(),
|
EntityCreatedAt by EntityCreatedAtImp(),
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package fr.dcproject.entity
|
package fr.dcproject.entity
|
||||||
|
|
||||||
import fr.postgresjson.entity.*
|
import fr.postgresjson.entity.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
open class Comment <T: UuidEntity> (
|
open class Comment <T : UuidEntity> (
|
||||||
id: UUID = UUID.randomUUID(),
|
id: UUID = UUID.randomUUID(),
|
||||||
createdBy: Citizen,
|
createdBy: Citizen,
|
||||||
target: T,
|
target: T,
|
||||||
@@ -12,7 +12,7 @@ open class Comment <T: UuidEntity> (
|
|||||||
var parent: Comment<T>? = null,
|
var parent: Comment<T>? = null,
|
||||||
var parentsIds: List<UUID>? = null,
|
var parentsIds: List<UUID>? = null,
|
||||||
val childrenCount: Int? = null
|
val childrenCount: Int? = null
|
||||||
): Extra<T>(id, createdBy, target),
|
) : Extra<T>(id, createdBy, target),
|
||||||
EntityUpdatedAt by EntityUpdatedAtImp(),
|
EntityUpdatedAt by EntityUpdatedAtImp(),
|
||||||
EntityDeletedAt by EntityDeletedAtImp(),
|
EntityDeletedAt by EntityDeletedAtImp(),
|
||||||
Votable by VotableImp()
|
Votable by VotableImp()
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ class Constitution(
|
|||||||
var draft: Boolean = false,
|
var draft: Boolean = false,
|
||||||
var lastVersion: Boolean = false,
|
var lastVersion: Boolean = false,
|
||||||
createdBy: Citizen?
|
createdBy: Citizen?
|
||||||
): UuidEntity(id),
|
) : UuidEntity(id),
|
||||||
EntityVersioning<UUID, Int> by UuidEntityVersioning(),
|
EntityVersioning<UUID, Int> by UuidEntityVersioning(),
|
||||||
EntityCreatedAt by EntityCreatedAtImp(),
|
EntityCreatedAt by EntityCreatedAtImp(),
|
||||||
EntityCreatedBy<Citizen> by EntityCreatedByImp(createdBy),
|
EntityCreatedBy<Citizen> by EntityCreatedByImp(createdBy),
|
||||||
EntityDeletedAt by EntityDeletedAtImp() {
|
EntityDeletedAt by EntityDeletedAtImp() {
|
||||||
|
|
||||||
init{
|
init {
|
||||||
titles.forEachIndexed { index, title ->
|
titles.forEachIndexed { index, title ->
|
||||||
title.createdBy = this.createdBy
|
title.createdBy = this.createdBy
|
||||||
title.rank = index
|
title.rank = index
|
||||||
@@ -30,7 +30,7 @@ class Constitution(
|
|||||||
var rank: Int? = null,
|
var rank: Int? = null,
|
||||||
var articles: List<Article> = listOf(),
|
var articles: List<Article> = listOf(),
|
||||||
createdBy: Citizen? = null
|
createdBy: Citizen? = null
|
||||||
): UuidEntity(id),
|
) : UuidEntity(id),
|
||||||
EntityCreatedAt by EntityCreatedAtImp(),
|
EntityCreatedAt by EntityCreatedAtImp(),
|
||||||
EntityCreatedBy<Citizen> by EntityCreatedByImp(createdBy)
|
EntityCreatedBy<Citizen> by EntityCreatedByImp(createdBy)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,20 +3,20 @@ package fr.dcproject.entity
|
|||||||
import fr.postgresjson.entity.*
|
import fr.postgresjson.entity.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
interface ExtraI <T: EntityI>:
|
interface ExtraI <T : EntityI> :
|
||||||
EntityI,
|
EntityI,
|
||||||
EntityCreatedAt,
|
EntityCreatedAt,
|
||||||
EntityCreatedBy<Citizen>{
|
EntityCreatedBy<Citizen> {
|
||||||
var target: T
|
var target: T
|
||||||
var targetReference: String
|
var targetReference: String
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class Extra<T: UuidEntity>(
|
abstract class Extra<T : UuidEntity>(
|
||||||
id: UUID? = UUID.randomUUID(),
|
id: UUID? = UUID.randomUUID(),
|
||||||
createdBy: Citizen,
|
createdBy: Citizen,
|
||||||
override var target: T,
|
override var target: T,
|
||||||
override var targetReference: String = target::class.simpleName!!.toLowerCase()
|
override var targetReference: String = target::class.simpleName!!.toLowerCase()
|
||||||
):
|
) :
|
||||||
ExtraI<T>,
|
ExtraI<T>,
|
||||||
UuidEntity(id),
|
UuidEntity(id),
|
||||||
EntityCreatedAt by EntityCreatedAtImp(),
|
EntityCreatedAt by EntityCreatedAtImp(),
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package fr.dcproject.entity
|
|||||||
import fr.postgresjson.entity.UuidEntity
|
import fr.postgresjson.entity.UuidEntity
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class Follow <T: UuidEntity> (
|
class Follow <T : UuidEntity> (
|
||||||
id: UUID = UUID.randomUUID(),
|
id: UUID = UUID.randomUUID(),
|
||||||
createdBy: Citizen,
|
createdBy: Citizen,
|
||||||
target: T
|
target: T
|
||||||
): Extra<T>(id, createdBy, target)
|
) : Extra<T>(id, createdBy, target)
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ class User(
|
|||||||
) : UuidEntity(id),
|
) : UuidEntity(id),
|
||||||
EntityCreatedAt by EntityCreatedAtImp(),
|
EntityCreatedAt by EntityCreatedAtImp(),
|
||||||
EntityUpdatedAt by EntityUpdatedAtImp(),
|
EntityUpdatedAt by EntityUpdatedAtImp(),
|
||||||
Principal
|
Principal {
|
||||||
{
|
|
||||||
enum class Roles { ROLE_USER, ROLE_ADMIN }
|
enum class Roles { ROLE_USER, ROLE_ADMIN }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ interface Votable {
|
|||||||
var votes: VoteAggregation
|
var votes: VoteAggregation
|
||||||
}
|
}
|
||||||
|
|
||||||
class VotableImp: Votable {
|
class VotableImp : Votable {
|
||||||
override var votes: VoteAggregation = VoteAggregation(0,0,0)
|
override var votes: VoteAggregation = VoteAggregation(0, 0, 0)
|
||||||
}
|
}
|
||||||
@@ -5,13 +5,13 @@ import fr.postgresjson.entity.EntityUpdatedAtImp
|
|||||||
import fr.postgresjson.entity.UuidEntity
|
import fr.postgresjson.entity.UuidEntity
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
open class Vote <T: UuidEntity> (
|
open class Vote <T : UuidEntity> (
|
||||||
id: UUID = UUID.randomUUID(),
|
id: UUID = UUID.randomUUID(),
|
||||||
createdBy: Citizen,
|
createdBy: Citizen,
|
||||||
target: T,
|
target: T,
|
||||||
var note: Int,
|
var note: Int,
|
||||||
var anonymous: Boolean = true
|
var anonymous: Boolean = true
|
||||||
): Extra<T>(id, createdBy, target),
|
) : Extra<T>(id, createdBy, target),
|
||||||
EntityUpdatedAt by EntityUpdatedAtImp() {
|
EntityUpdatedAt by EntityUpdatedAtImp() {
|
||||||
init {
|
init {
|
||||||
if (note > 1 && note < -1) {
|
if (note > 1 && note < -1) {
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import fr.postgresjson.entity.EntityI
|
|||||||
import fr.postgresjson.entity.EntityUpdatedAt
|
import fr.postgresjson.entity.EntityUpdatedAt
|
||||||
import fr.postgresjson.entity.EntityUpdatedAtImp
|
import fr.postgresjson.entity.EntityUpdatedAtImp
|
||||||
|
|
||||||
open class VoteAggregation (
|
open class VoteAggregation(
|
||||||
val up: Int,
|
val up: Int,
|
||||||
val neutral: Int,
|
val neutral: Int,
|
||||||
val down: Int
|
val down: Int
|
||||||
): EntityI,
|
) : EntityI,
|
||||||
EntityUpdatedAt by EntityUpdatedAtImp()
|
EntityUpdatedAt by EntityUpdatedAtImp()
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class Article(
|
|||||||
val tags: List<String> = emptyList(),
|
val tags: List<String> = emptyList(),
|
||||||
val draft: Boolean = false,
|
val draft: Boolean = false,
|
||||||
val versionId: UUID?
|
val versionId: UUID?
|
||||||
):
|
) :
|
||||||
Request {
|
Request {
|
||||||
|
|
||||||
fun merge(article: ArticleEntity) {
|
fun merge(article: ArticleEntity) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package fr.dcproject.entity.request
|
package fr.dcproject.entity.request
|
||||||
|
|
||||||
class Comment (
|
class Comment(
|
||||||
val content: String
|
val content: String
|
||||||
): Request
|
) : Request
|
||||||
@@ -6,7 +6,7 @@ import com.sendgrid.SendGrid
|
|||||||
import com.sendgrid.helpers.mail.Mail
|
import com.sendgrid.helpers.mail.Mail
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
class Mailer (
|
class Mailer(
|
||||||
private val key: String
|
private val key: String
|
||||||
) {
|
) {
|
||||||
fun sendEmail(action: () -> Mail): Boolean {
|
fun sendEmail(action: () -> Mail): Boolean {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import io.ktor.http.URLBuilder
|
|||||||
import fr.dcproject.entity.Citizen as CitizenEntity
|
import fr.dcproject.entity.Citizen as CitizenEntity
|
||||||
import fr.dcproject.repository.Citizen as CitizenRepository
|
import fr.dcproject.repository.Citizen as CitizenRepository
|
||||||
|
|
||||||
class SsoManager (
|
class SsoManager(
|
||||||
private val mailer: Mailer,
|
private val mailer: Mailer,
|
||||||
private val domain: String,
|
private val domain: String,
|
||||||
private val citizenRepo: CitizenRepository
|
private val citizenRepo: CitizenRepository
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import fr.dcproject.entity.Citizen as CitizenEntity
|
|||||||
import fr.dcproject.entity.Comment as CommentEntity
|
import fr.dcproject.entity.Comment as CommentEntity
|
||||||
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
||||||
|
|
||||||
abstract class Comment <T: UuidEntity>(override var requester: Requester): RepositoryI {
|
abstract class Comment <T : UuidEntity>(override var requester: Requester) : RepositoryI {
|
||||||
abstract fun findById(id: UUID): CommentEntity<T>?
|
abstract fun findById(id: UUID): CommentEntity<T>?
|
||||||
|
|
||||||
abstract fun findByCitizen(
|
abstract fun findByCitizen(
|
||||||
@@ -81,7 +81,7 @@ abstract class Comment <T: UuidEntity>(override var requester: Requester): Repos
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CommentGeneric (requester: Requester): Comment<UuidEntity>(requester) {
|
class CommentGeneric(requester: Requester) : Comment<UuidEntity>(requester) {
|
||||||
override fun findById(id: UUID): CommentEntity<UuidEntity>? {
|
override fun findById(id: UUID): CommentEntity<UuidEntity>? {
|
||||||
return requester
|
return requester
|
||||||
.getFunction("find_comment_by_id")
|
.getFunction("find_comment_by_id")
|
||||||
@@ -102,7 +102,7 @@ class CommentGeneric (requester: Requester): Comment<UuidEntity>(requester) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CommentArticle (requester: Requester): Comment<ArticleEntity>(requester) {
|
class CommentArticle(requester: Requester) : Comment<ArticleEntity>(requester) {
|
||||||
override fun findById(id: UUID): CommentEntity<ArticleEntity>? {
|
override fun findById(id: UUID): CommentEntity<ArticleEntity>? {
|
||||||
return requester
|
return requester
|
||||||
.getFunction("find_comment_by_id")
|
.getFunction("find_comment_by_id")
|
||||||
@@ -125,7 +125,7 @@ class CommentArticle (requester: Requester): Comment<ArticleEntity>(requester) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CommentConstitution (requester: Requester): Comment<ConstitutionEntity>(requester) {
|
class CommentConstitution(requester: Requester) : Comment<ConstitutionEntity>(requester) {
|
||||||
override fun findById(id: UUID): CommentEntity<ConstitutionEntity>? {
|
override fun findById(id: UUID): CommentEntity<ConstitutionEntity>? {
|
||||||
return requester
|
return requester
|
||||||
.getFunction("find_comment_by_id")
|
.getFunction("find_comment_by_id")
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import fr.dcproject.entity.Citizen as CitizenEntity
|
|||||||
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
||||||
import fr.dcproject.entity.Follow as FollowEntity
|
import fr.dcproject.entity.Follow as FollowEntity
|
||||||
|
|
||||||
open class Follow <T: UuidEntity>(override var requester: Requester): RepositoryI {
|
open class Follow <T : UuidEntity>(override var requester: Requester) : RepositoryI {
|
||||||
open fun findByCitizen(
|
open fun findByCitizen(
|
||||||
citizen: CitizenEntity,
|
citizen: CitizenEntity,
|
||||||
page: Int = 1,
|
page: Int = 1,
|
||||||
@@ -54,7 +54,7 @@ open class Follow <T: UuidEntity>(override var requester: Requester): Repository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FollowArticle (requester: Requester): Follow<ArticleEntity>(requester) {
|
class FollowArticle(requester: Requester) : Follow<ArticleEntity>(requester) {
|
||||||
override fun findByCitizen(
|
override fun findByCitizen(
|
||||||
citizenId: UUID,
|
citizenId: UUID,
|
||||||
page: Int,
|
page: Int,
|
||||||
@@ -69,7 +69,7 @@ class FollowArticle (requester: Requester): Follow<ArticleEntity>(requester) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FollowConstitution (requester: Requester): Follow<ConstitutionEntity>(requester) {
|
class FollowConstitution(requester: Requester) : Follow<ConstitutionEntity>(requester) {
|
||||||
override fun findByCitizen(
|
override fun findByCitizen(
|
||||||
citizenId: UUID,
|
citizenId: UUID,
|
||||||
page: Int,
|
page: Int,
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class User(override var requester: Requester) : RepositoryI {
|
|||||||
.sendQuery("resource" to user)
|
.sendQuery("resource" to user)
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserNotFound(override val message: String?, override val cause: Throwable?): Throwable(message, cause) {
|
class UserNotFound(override val message: String?, override val cause: Throwable?) : Throwable(message, cause) {
|
||||||
constructor(id: UUID): this("No User with ID $id", null)
|
constructor(id: UUID) : this("No User with ID $id", null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import java.util.*
|
|||||||
import fr.dcproject.entity.Citizen as CitizenEntity
|
import fr.dcproject.entity.Citizen as CitizenEntity
|
||||||
import fr.dcproject.entity.Vote as VoteEntity
|
import fr.dcproject.entity.Vote as VoteEntity
|
||||||
|
|
||||||
open class Vote <T: UuidEntity>(override var requester: Requester): RepositoryI {
|
open class Vote <T : UuidEntity>(override var requester: Requester) : RepositoryI {
|
||||||
fun vote(vote: VoteEntity<T>): VoteAggregation {
|
fun vote(vote: VoteEntity<T>): VoteAggregation {
|
||||||
val target = vote.target
|
val target = vote.target
|
||||||
val reference = if (target is Comment<*>) {
|
val reference = if (target is Comment<*>) {
|
||||||
@@ -56,7 +56,7 @@ open class Vote <T: UuidEntity>(override var requester: Requester): RepositoryI
|
|||||||
citizen: CitizenEntity,
|
citizen: CitizenEntity,
|
||||||
targets: List<UUID>
|
targets: List<UUID>
|
||||||
): List<VoteEntity<*>> {
|
): List<VoteEntity<*>> {
|
||||||
val typeReference = object: TypeReference<List<VoteEntity<UuidEntity>>>() {}
|
val typeReference = object : TypeReference<List<VoteEntity<UuidEntity>>>() {}
|
||||||
return requester.run {
|
return requester.run {
|
||||||
val citizenId = citizen.id ?: error("The citizen must have an id")
|
val citizenId = citizen.id ?: error("The citizen must have an id")
|
||||||
getFunction("find_citizen_votes_by_target_ids")
|
getFunction("find_citizen_votes_by_target_ids")
|
||||||
@@ -68,7 +68,7 @@ open class Vote <T: UuidEntity>(override var requester: Requester): RepositoryI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class VoteArticle (requester: Requester): Vote<Article>(requester) {
|
class VoteArticle(requester: Requester) : Vote<Article>(requester) {
|
||||||
fun findByCitizen(
|
fun findByCitizen(
|
||||||
citizen: CitizenEntity,
|
citizen: CitizenEntity,
|
||||||
page: Int = 1,
|
page: Int = 1,
|
||||||
@@ -77,13 +77,13 @@ class VoteArticle (requester: Requester): Vote<Article>(requester) {
|
|||||||
findByCitizen(
|
findByCitizen(
|
||||||
citizen.id ?: error("The citizen must have an id"),
|
citizen.id ?: error("The citizen must have an id"),
|
||||||
"article",
|
"article",
|
||||||
object: TypeReference<List<VoteEntity<Article>>>() {},
|
object : TypeReference<List<VoteEntity<Article>>>() {},
|
||||||
page,
|
page,
|
||||||
limit
|
limit
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
class VoteArticleComment (requester: Requester): Vote<Comment<Article>>(requester) {
|
class VoteArticleComment(requester: Requester) : Vote<Comment<Article>>(requester) {
|
||||||
fun findByCitizen(
|
fun findByCitizen(
|
||||||
citizen: CitizenEntity,
|
citizen: CitizenEntity,
|
||||||
page: Int = 1,
|
page: Int = 1,
|
||||||
@@ -92,13 +92,13 @@ class VoteArticleComment (requester: Requester): Vote<Comment<Article>>(requeste
|
|||||||
findByCitizen(
|
findByCitizen(
|
||||||
citizen.id ?: error("The citizen must have an id"),
|
citizen.id ?: error("The citizen must have an id"),
|
||||||
"article",
|
"article",
|
||||||
object: TypeReference<List<VoteEntity<Comment<Article>>>>() {},
|
object : TypeReference<List<VoteEntity<Comment<Article>>>>() {},
|
||||||
page,
|
page,
|
||||||
limit
|
limit
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
class VoteComment (requester: Requester): Vote<Comment<UuidEntity>>(requester) {
|
class VoteComment(requester: Requester) : Vote<Comment<UuidEntity>>(requester) {
|
||||||
fun findByCitizen(
|
fun findByCitizen(
|
||||||
citizen: CitizenEntity,
|
citizen: CitizenEntity,
|
||||||
page: Int = 1,
|
page: Int = 1,
|
||||||
@@ -107,13 +107,13 @@ class VoteComment (requester: Requester): Vote<Comment<UuidEntity>>(requester) {
|
|||||||
findByCitizen(
|
findByCitizen(
|
||||||
citizen.id ?: error("The citizen must have an id"),
|
citizen.id ?: error("The citizen must have an id"),
|
||||||
"article",
|
"article",
|
||||||
object: TypeReference<List<VoteEntity<Comment<UuidEntity>>>>() {},
|
object : TypeReference<List<VoteEntity<Comment<UuidEntity>>>>() {},
|
||||||
page,
|
page,
|
||||||
limit
|
limit
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
class VoteConstitution (requester: Requester): Vote<Constitution>(requester) {
|
class VoteConstitution(requester: Requester) : Vote<Constitution>(requester) {
|
||||||
fun findByCitizen(
|
fun findByCitizen(
|
||||||
citizen: CitizenEntity,
|
citizen: CitizenEntity,
|
||||||
page: Int = 1,
|
page: Int = 1,
|
||||||
@@ -122,7 +122,7 @@ class VoteConstitution (requester: Requester): Vote<Constitution>(requester) {
|
|||||||
findByCitizen(
|
findByCitizen(
|
||||||
citizen.id ?: error("The citizen must have an id"),
|
citizen.id ?: error("The citizen must have an id"),
|
||||||
"constitution",
|
"constitution",
|
||||||
object: TypeReference<List<VoteEntity<Constitution>>>() {},
|
object : TypeReference<List<VoteEntity<Constitution>>>() {},
|
||||||
page,
|
page,
|
||||||
limit
|
limit
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ fun Route.comment(repo: CommentRepository) {
|
|||||||
|
|
||||||
put<CommentPaths.CommentRequest> {
|
put<CommentPaths.CommentRequest> {
|
||||||
val comment = repo.findById(it.comment)!!
|
val comment = repo.findById(it.comment)!!
|
||||||
assertCan(UPDATE,comment)
|
assertCan(UPDATE, comment)
|
||||||
|
|
||||||
comment.content = call.receiveText()
|
comment.content = call.receiveText()
|
||||||
repo.edit(comment)
|
repo.edit(comment)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ interface PaginatedRequestI {
|
|||||||
open class PaginatedRequest(
|
open class PaginatedRequest(
|
||||||
page: Int = 1,
|
page: Int = 1,
|
||||||
limit: Int = 50
|
limit: Int = 50
|
||||||
): PaginatedRequestI {
|
) : PaginatedRequestI {
|
||||||
override val page: Int = if (page < 1) 1 else page
|
override val page: Int = if (page < 1) 1 else page
|
||||||
override val limit: Int = if (limit > 50) 50 else if (limit < 1) 1 else limit
|
override val limit: Int = if (limit > 50) 50 else if (limit < 1) 1 else limit
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ object VoteArticlePaths {
|
|||||||
page: Int = 1,
|
page: Int = 1,
|
||||||
limit: Int = 50,
|
limit: Int = 50,
|
||||||
val search: String? = null
|
val search: String? = null
|
||||||
): PaginatedRequestI by PaginatedRequest(page, limit)
|
) : PaginatedRequestI by PaginatedRequest(page, limit)
|
||||||
|
|
||||||
@Location("/citizens/{citizen}/votes")
|
@Location("/citizens/{citizen}/votes")
|
||||||
class CitizenVotesByIdsRequest(val citizen: Citizen, id: List<String>) {
|
class CitizenVotesByIdsRequest(val citizen: Citizen, id: List<String>) {
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import fr.dcproject.entity.Article as ArticleEntity
|
|||||||
import fr.dcproject.entity.Comment as CommentEntity
|
import fr.dcproject.entity.Comment as CommentEntity
|
||||||
import fr.dcproject.entity.Vote as VoteEntity
|
import fr.dcproject.entity.Vote as VoteEntity
|
||||||
|
|
||||||
class ArticleVoter: Voter {
|
class ArticleVoter : Voter {
|
||||||
enum class Action: ActionI {
|
enum class Action : ActionI {
|
||||||
CREATE,
|
CREATE,
|
||||||
UPDATE,
|
UPDATE,
|
||||||
VIEW,
|
VIEW,
|
||||||
@@ -16,8 +16,7 @@ class ArticleVoter: Voter {
|
|||||||
|
|
||||||
override fun supports(action: ActionI, call: ApplicationCall, subject: Any?): Boolean {
|
override fun supports(action: ActionI, call: ApplicationCall, subject: Any?): Boolean {
|
||||||
return (action is Action || action is CommentVoter.Action || action is VoteVoter.Action)
|
return (action is Action || action is CommentVoter.Action || action is VoteVoter.Action)
|
||||||
&&
|
.and(subject is List<*> || subject is ArticleEntity? || subject is VoteEntity<*> || subject is CommentEntity<*>)
|
||||||
(subject is List<*> || subject is ArticleEntity? || subject is VoteEntity<*> || subject is CommentEntity<*>)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun vote(action: ActionI, call: ApplicationCall, subject: Any?): Vote {
|
override fun vote(action: ActionI, call: ApplicationCall, subject: Any?): Vote {
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import io.ktor.application.ApplicationCall
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
|
|
||||||
@KtorExperimentalLocationsAPI
|
@KtorExperimentalLocationsAPI
|
||||||
class CitizenVoter: Voter {
|
class CitizenVoter : Voter {
|
||||||
enum class Action: ActionI {
|
enum class Action : ActionI {
|
||||||
CREATE,
|
CREATE,
|
||||||
UPDATE,
|
UPDATE,
|
||||||
VIEW,
|
VIEW,
|
||||||
@@ -17,10 +17,7 @@ class CitizenVoter: Voter {
|
|||||||
|
|
||||||
override fun supports(action: ActionI, call: ApplicationCall, subject: Any?): Boolean {
|
override fun supports(action: ActionI, call: ApplicationCall, subject: Any?): Boolean {
|
||||||
return (action is Action)
|
return (action is Action)
|
||||||
&& (
|
.and(subject is List<*> || subject is Citizen?)
|
||||||
subject is List<*> ||
|
|
||||||
subject is Citizen?
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun vote(action: ActionI, call: ApplicationCall, subject: Any?): Vote {
|
override fun vote(action: ActionI, call: ApplicationCall, subject: Any?): Vote {
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package fr.dcproject.security.voter
|
|||||||
import fr.dcproject.entity.Comment
|
import fr.dcproject.entity.Comment
|
||||||
import io.ktor.application.ApplicationCall
|
import io.ktor.application.ApplicationCall
|
||||||
|
|
||||||
class CommentVoter: Voter {
|
class CommentVoter : Voter {
|
||||||
enum class Action: ActionI {
|
enum class Action : ActionI {
|
||||||
CREATE,
|
CREATE,
|
||||||
UPDATE,
|
UPDATE,
|
||||||
VIEW,
|
VIEW,
|
||||||
@@ -12,8 +12,8 @@ class CommentVoter: Voter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun supports(action: ActionI, call: ApplicationCall, subject: Any?): Boolean {
|
override fun supports(action: ActionI, call: ApplicationCall, subject: Any?): Boolean {
|
||||||
return (action is Action) &&
|
return (action is Action)
|
||||||
(subject is Comment<*>? || subject is List<*>)
|
.and(subject is Comment<*>? || subject is List<*>)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun vote(action: ActionI, call: ApplicationCall, subject: Any?): Vote {
|
override fun vote(action: ActionI, call: ApplicationCall, subject: Any?): Vote {
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import io.ktor.application.ApplicationCall
|
|||||||
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
||||||
import fr.dcproject.entity.Vote as VoteEntity
|
import fr.dcproject.entity.Vote as VoteEntity
|
||||||
|
|
||||||
class ConstitutionVoter: Voter {
|
class ConstitutionVoter : Voter {
|
||||||
enum class Action: ActionI {
|
enum class Action : ActionI {
|
||||||
CREATE,
|
CREATE,
|
||||||
UPDATE,
|
UPDATE,
|
||||||
VIEW,
|
VIEW,
|
||||||
@@ -16,8 +16,7 @@ class ConstitutionVoter: Voter {
|
|||||||
|
|
||||||
override fun supports(action: ActionI, call: ApplicationCall, subject: Any?): Boolean {
|
override fun supports(action: ActionI, call: ApplicationCall, subject: Any?): Boolean {
|
||||||
return (action is Action || action is CommentVoter.Action || action is VoteVoter.Action)
|
return (action is Action || action is CommentVoter.Action || action is VoteVoter.Action)
|
||||||
&&
|
.and(subject is List<*> || subject is ConstitutionEntity? || subject is VoteEntity<*> || subject is Comment<*>)
|
||||||
(subject is List<*> || subject is ConstitutionEntity? || subject is VoteEntity<*> || subject is Comment<*>)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun vote(action: ActionI, call: ApplicationCall, subject: Any?): Vote {
|
override fun vote(action: ActionI, call: ApplicationCall, subject: Any?): Vote {
|
||||||
|
|||||||
@@ -4,16 +4,16 @@ import io.ktor.application.ApplicationCall
|
|||||||
import fr.dcproject.entity.Follow as FollowEntity
|
import fr.dcproject.entity.Follow as FollowEntity
|
||||||
import fr.dcproject.entity.User as UserEntity
|
import fr.dcproject.entity.User as UserEntity
|
||||||
|
|
||||||
class FollowVoter: Voter {
|
class FollowVoter : Voter {
|
||||||
enum class Action: ActionI {
|
enum class Action : ActionI {
|
||||||
CREATE,
|
CREATE,
|
||||||
DELETE,
|
DELETE,
|
||||||
VIEW
|
VIEW
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun supports(action: ActionI, call: ApplicationCall, subject: Any?): Boolean {
|
override fun supports(action: ActionI, call: ApplicationCall, subject: Any?): Boolean {
|
||||||
return (action is Action) &&
|
return (action is Action)
|
||||||
(subject is List<*> || subject is FollowEntity<*>?)
|
.and(subject is List<*> || subject is FollowEntity<*>?)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun vote(action: ActionI, call: ApplicationCall, subject: Any?): Vote {
|
override fun vote(action: ActionI, call: ApplicationCall, subject: Any?): Vote {
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ package fr.dcproject.security.voter
|
|||||||
import io.ktor.application.ApplicationCall
|
import io.ktor.application.ApplicationCall
|
||||||
import fr.dcproject.entity.Vote as VoteEntity
|
import fr.dcproject.entity.Vote as VoteEntity
|
||||||
|
|
||||||
class VoteVoter: Voter {
|
class VoteVoter : Voter {
|
||||||
enum class Action: ActionI {
|
enum class Action : ActionI {
|
||||||
CREATE,
|
CREATE,
|
||||||
VIEW
|
VIEW
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun supports(action: ActionI, call: ApplicationCall, subject: Any?): Boolean {
|
override fun supports(action: ActionI, call: ApplicationCall, subject: Any?): Boolean {
|
||||||
return action is Action && (
|
return action is Action && (
|
||||||
subject is VoteEntity<*>?
|
subject is VoteEntity<*>? ||
|
||||||
|| subject is List<*>
|
subject is List<*>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,6 @@ import org.slf4j.LoggerFactory
|
|||||||
import kotlin.properties.ReadOnlyProperty
|
import kotlin.properties.ReadOnlyProperty
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
internal class LoggerDelegate<in R: Any>: ReadOnlyProperty<R, Logger> {
|
internal class LoggerDelegate<in R : Any> : ReadOnlyProperty<R, Logger> {
|
||||||
override fun getValue(thisRef: R, property: KProperty<*>) = LoggerFactory.getLogger(thisRef.javaClass.packageName)
|
override fun getValue(thisRef: R, property: KProperty<*>) = LoggerFactory.getLogger(thisRef.javaClass.packageName)
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@ import org.koin.test.get
|
|||||||
@KtorExperimentalLocationsAPI
|
@KtorExperimentalLocationsAPI
|
||||||
@KtorExperimentalAPI
|
@KtorExperimentalAPI
|
||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
class MailerTest: KoinTest, AutoCloseKoinTest() {
|
class MailerTest : KoinTest, AutoCloseKoinTest() {
|
||||||
@Test
|
@Test
|
||||||
fun `can be send an email`() {
|
fun `can be send an email`() {
|
||||||
withTestApplication({ module(Env.TEST) }) {
|
withTestApplication({ module(Env.TEST) }) {
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
import fr.dcproject.Env
|
|
||||||
import fr.dcproject.module
|
|
||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
|
||||||
import io.ktor.server.testing.withTestApplication
|
|
||||||
import io.ktor.util.KtorExperimentalAPI
|
|
||||||
import org.amshove.kluent.shouldBe
|
|
||||||
import org.junit.jupiter.api.Test
|
|
||||||
import org.junit.jupiter.api.TestInstance
|
|
||||||
import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS
|
|
||||||
import org.koin.test.AutoCloseKoinTest
|
|
||||||
import org.koin.test.KoinTest
|
|
||||||
import org.koin.test.get
|
|
||||||
import fr.dcproject.repository.Article as RepositoryArticle
|
|
||||||
import fr.dcproject.repository.Constitution as RepositoryConstitution
|
|
||||||
|
|
||||||
@KtorExperimentalLocationsAPI
|
|
||||||
@KtorExperimentalAPI
|
|
||||||
@TestInstance(PER_CLASS)
|
|
||||||
class RepositoryTest: KoinTest, AutoCloseKoinTest() {
|
|
||||||
@Test
|
|
||||||
fun `test get repository`() {
|
|
||||||
withTestApplication({ module(Env.TEST) }) {
|
|
||||||
val repoArticle = get<RepositoryArticle>()
|
|
||||||
(repoArticle is RepositoryArticle) shouldBe true
|
|
||||||
|
|
||||||
val repoConstitution = get<RepositoryConstitution>()
|
|
||||||
(repoConstitution is RepositoryConstitution) shouldBe true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -24,7 +24,7 @@ var unitialized: Boolean = false
|
|||||||
@KtorExperimentalLocationsAPI
|
@KtorExperimentalLocationsAPI
|
||||||
@RunWith(Cucumber::class)
|
@RunWith(Cucumber::class)
|
||||||
@CucumberOptions(plugin = ["pretty"])
|
@CucumberOptions(plugin = ["pretty"])
|
||||||
class RunCucumberTest: En, KoinTest {
|
class RunCucumberTest : En, KoinTest {
|
||||||
private val logger: Logger? by LoggerDelegate()
|
private val logger: Logger? by LoggerDelegate()
|
||||||
|
|
||||||
val ktorContext = KtorServerContext {
|
val ktorContext = KtorServerContext {
|
||||||
@@ -44,7 +44,7 @@ class RunCucumberTest: En, KoinTest {
|
|||||||
unitialized = true
|
unitialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
Before(-1) { scenario: Scenario ->
|
Before(-1) { _: Scenario ->
|
||||||
config.database = "test"
|
config.database = "test"
|
||||||
config.username = "test"
|
config.username = "test"
|
||||||
config.password = "test"
|
config.password = "test"
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import fr.dcproject.entity.User as UserEntity
|
|||||||
import fr.dcproject.repository.Article as ArticleRepository
|
import fr.dcproject.repository.Article as ArticleRepository
|
||||||
import fr.dcproject.repository.Citizen as CitizenRepository
|
import fr.dcproject.repository.Citizen as CitizenRepository
|
||||||
|
|
||||||
class ArticleSteps: En, KoinTest {
|
class ArticleSteps : En, KoinTest {
|
||||||
init {
|
init {
|
||||||
Given("I have article with id {string}") { id: String ->
|
Given("I have article with id {string}") { id: String ->
|
||||||
var citizen = Citizen(
|
var citizen = Citizen(
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import fr.dcproject.entity.User as UserEntity
|
|||||||
import fr.dcproject.repository.Citizen as CitizenRepository
|
import fr.dcproject.repository.Citizen as CitizenRepository
|
||||||
import fr.dcproject.repository.Constitution as ConstitutionRepository
|
import fr.dcproject.repository.Constitution as ConstitutionRepository
|
||||||
|
|
||||||
class ConstitutionSteps: En, KoinTest {
|
class ConstitutionSteps : En, KoinTest {
|
||||||
init {
|
init {
|
||||||
Given("I have constitution with id {string}") { id: String ->
|
Given("I have constitution with id {string}") { id: String ->
|
||||||
var citizen = Citizen(
|
var citizen = Citizen(
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ import java.util.concurrent.CompletionException
|
|||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
import fr.dcproject.repository.Citizen as CitizenRepository
|
import fr.dcproject.repository.Citizen as CitizenRepository
|
||||||
|
|
||||||
class KtorServerAuthSteps: En, KoinTest {
|
class KtorServerAuthSteps : En, KoinTest {
|
||||||
private val requester: Requester by inject()
|
private val requester: Requester by inject()
|
||||||
init {
|
init {
|
||||||
When("I have citizen:") { body: DataTable ->
|
When("I have citizen:") { body: DataTable ->
|
||||||
val user = User(username = "jaque_${Random.nextInt(0, 10000)}", plainPassword = "azerty")
|
val user = User(username = "jaque_${Random.nextInt(0, 10000)}", plainPassword = "azerty")
|
||||||
@@ -53,7 +53,7 @@ class KtorServerAuthSteps: En, KoinTest {
|
|||||||
val citizen = Citizen(
|
val citizen = Citizen(
|
||||||
id = UUID.fromString(id),
|
id = UUID.fromString(id),
|
||||||
name = Citizen.Name(firstName, lastName),
|
name = Citizen.Name(firstName, lastName),
|
||||||
email = ("$firstName-$lastName".toLowerCase())+"@dc-project.fr",
|
email = ("$firstName-$lastName".toLowerCase()) + "@dc-project.fr",
|
||||||
birthday = DateTime.now(),
|
birthday = DateTime.now(),
|
||||||
user = user
|
user = user
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user