Lint
This commit is contained in:
@@ -1,14 +1,6 @@
|
|||||||
package fr.dcproject.application
|
package fr.dcproject.application
|
||||||
|
|
||||||
import fr.dcproject.component.citizen.Citizen
|
|
||||||
import fr.dcproject.component.citizen.CitizenBasic
|
import fr.dcproject.component.citizen.CitizenBasic
|
||||||
import fr.dcproject.component.citizen.CitizenRef
|
|
||||||
import fr.dcproject.component.citizen.CitizenRepository
|
|
||||||
import fr.dcproject.component.constitution.Constitution
|
|
||||||
import fr.dcproject.component.constitution.ConstitutionRef
|
|
||||||
import fr.dcproject.component.constitution.ConstitutionRepository
|
|
||||||
import fr.dcproject.component.opinion.OpinionChoiceRepository
|
|
||||||
import fr.dcproject.component.opinion.entity.OpinionChoice
|
|
||||||
import fr.dcproject.component.workgroup.Workgroup
|
import fr.dcproject.component.workgroup.Workgroup
|
||||||
import fr.dcproject.component.workgroup.WorkgroupRef
|
import fr.dcproject.component.workgroup.WorkgroupRef
|
||||||
import fr.dcproject.component.workgroup.WorkgroupRepository
|
import fr.dcproject.component.workgroup.WorkgroupRepository
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import io.ktor.application.call
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.post
|
import io.ktor.locations.post
|
||||||
import io.ktor.request.receive
|
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import io.ktor.http.HttpStatusCode
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.post
|
import io.ktor.locations.post
|
||||||
import io.ktor.request.receive
|
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.response.respondText
|
import io.ktor.response.respondText
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import io.ktor.http.HttpStatusCode
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.post
|
import io.ktor.locations.post
|
||||||
import io.ktor.request.receive
|
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.response.respondText
|
import io.ktor.response.respondText
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import io.ktor.http.HttpStatusCode
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.post
|
import io.ktor.locations.post
|
||||||
import io.ktor.request.receive
|
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package fr.dcproject.component.citizen.routes
|
package fr.dcproject.component.citizen.routes
|
||||||
|
|
||||||
import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException
|
|
||||||
import fr.dcproject.component.auth.UserRepository
|
import fr.dcproject.component.auth.UserRepository
|
||||||
import fr.dcproject.component.auth.citizen
|
import fr.dcproject.component.auth.citizen
|
||||||
import fr.dcproject.component.auth.citizenOrNull
|
import fr.dcproject.component.auth.citizenOrNull
|
||||||
import fr.dcproject.component.citizen.Citizen
|
|
||||||
import fr.dcproject.component.citizen.CitizenAccessControl
|
import fr.dcproject.component.citizen.CitizenAccessControl
|
||||||
import fr.dcproject.component.citizen.CitizenRef
|
import fr.dcproject.component.citizen.CitizenRef
|
||||||
import fr.dcproject.security.assert
|
import fr.dcproject.security.assert
|
||||||
@@ -16,8 +14,6 @@ import io.ktor.http.HttpStatusCode
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.put
|
import io.ktor.locations.put
|
||||||
import io.ktor.request.receive
|
|
||||||
import io.ktor.request.receiveOrNull
|
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package fr.dcproject.component.citizen.routes
|
package fr.dcproject.component.citizen.routes
|
||||||
|
|
||||||
import fr.dcproject.component.auth.citizenOrNull
|
import fr.dcproject.component.auth.citizenOrNull
|
||||||
import fr.dcproject.component.citizen.Citizen
|
|
||||||
import fr.dcproject.component.citizen.CitizenAccessControl
|
import fr.dcproject.component.citizen.CitizenAccessControl
|
||||||
import fr.dcproject.component.citizen.CitizenRef
|
import fr.dcproject.component.citizen.CitizenRef
|
||||||
import fr.dcproject.component.citizen.CitizenRepository
|
import fr.dcproject.component.citizen.CitizenRepository
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import io.ktor.http.HttpStatusCode
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.post
|
import io.ktor.locations.post
|
||||||
import io.ktor.request.receive
|
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package fr.dcproject.component.comment.article.routes
|
package fr.dcproject.component.comment.article.routes
|
||||||
|
|
||||||
import fr.dcproject.component.auth.citizenOrNull
|
import fr.dcproject.component.auth.citizenOrNull
|
||||||
import fr.dcproject.component.citizen.Citizen
|
|
||||||
import fr.dcproject.component.citizen.CitizenRef
|
import fr.dcproject.component.citizen.CitizenRef
|
||||||
import fr.dcproject.component.comment.article.CommentArticleRepository
|
import fr.dcproject.component.comment.article.CommentArticleRepository
|
||||||
import fr.dcproject.component.comment.generic.CommentAccessControl
|
import fr.dcproject.component.comment.generic.CommentAccessControl
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package fr.dcproject.component.comment.constitution.routes
|
package fr.dcproject.component.comment.constitution.routes
|
||||||
|
|
||||||
import fr.dcproject.component.auth.citizenOrNull
|
import fr.dcproject.component.auth.citizenOrNull
|
||||||
import fr.dcproject.component.citizen.Citizen
|
|
||||||
import fr.dcproject.component.citizen.CitizenRef
|
import fr.dcproject.component.citizen.CitizenRef
|
||||||
import fr.dcproject.component.comment.constitution.CommentConstitutionRepository
|
import fr.dcproject.component.comment.constitution.CommentConstitutionRepository
|
||||||
import fr.dcproject.component.comment.generic.CommentAccessControl
|
import fr.dcproject.component.comment.generic.CommentAccessControl
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import io.ktor.http.HttpStatusCode
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.post
|
import io.ktor.locations.post
|
||||||
import io.ktor.request.receive
|
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class ConstitutionAccessControl : AccessControl() {
|
|||||||
fun <S : ConstitutionSimple<*, *>> canView(subjects: List<S>, citizen: CitizenI?): AccessResponse =
|
fun <S : ConstitutionSimple<*, *>> canView(subjects: List<S>, citizen: CitizenI?): AccessResponse =
|
||||||
canAll(subjects) { canView(it, citizen) }
|
canAll(subjects) { canView(it, citizen) }
|
||||||
|
|
||||||
fun <S> canView(subject: S, citizen: CitizenI?): AccessResponse where S: EntityDeletedAt, S: ConstitutionS = when {
|
fun <S> canView(subject: S, citizen: CitizenI?): AccessResponse where S : EntityDeletedAt, S : ConstitutionS = when {
|
||||||
subject.isDeleted() -> denied("You cannot view a deleted constitution", "constitution.view.deleted")
|
subject.isDeleted() -> denied("You cannot view a deleted constitution", "constitution.view.deleted")
|
||||||
else -> granted()
|
else -> granted()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import io.ktor.application.call
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.post
|
import io.ktor.locations.post
|
||||||
import io.ktor.request.receive
|
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package fr.dcproject.component.follow.routes.article
|
package fr.dcproject.component.follow.routes.article
|
||||||
|
|
||||||
import fr.dcproject.component.auth.citizenOrNull
|
import fr.dcproject.component.auth.citizenOrNull
|
||||||
import fr.dcproject.component.citizen.Citizen
|
|
||||||
import fr.dcproject.component.citizen.CitizenRef
|
import fr.dcproject.component.citizen.CitizenRef
|
||||||
import fr.dcproject.component.follow.FollowAccessControl
|
import fr.dcproject.component.follow.FollowAccessControl
|
||||||
import fr.dcproject.component.follow.FollowArticleRepository
|
import fr.dcproject.component.follow.FollowArticleRepository
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package fr.dcproject.component.opinion
|
package fr.dcproject.component.opinion
|
||||||
|
|
||||||
import fr.dcproject.common.entity.HasTarget
|
import fr.dcproject.common.entity.HasTarget
|
||||||
import fr.dcproject.common.entity.TargetRef
|
|
||||||
import fr.dcproject.component.citizen.CitizenI
|
import fr.dcproject.component.citizen.CitizenI
|
||||||
import fr.dcproject.component.opinion.entity.Opinion
|
|
||||||
import fr.dcproject.component.opinion.entity.OpinionI
|
import fr.dcproject.component.opinion.entity.OpinionI
|
||||||
import fr.dcproject.security.AccessControl
|
import fr.dcproject.security.AccessControl
|
||||||
import fr.dcproject.security.AccessResponse
|
import fr.dcproject.security.AccessResponse
|
||||||
@@ -24,10 +22,10 @@ class OpinionAccessControl : AccessControl() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <S, SS : List<S>, C: CitizenI> canView(subjects: SS, citizen: CitizenI?): AccessResponse where S : OpinionI, S : EntityCreatedBy<C> =
|
fun <S, SS : List<S>, C : CitizenI> canView(subjects: SS, citizen: CitizenI?): AccessResponse where S : OpinionI, S : EntityCreatedBy<C> =
|
||||||
canAll(subjects) { canView(it, citizen) }
|
canAll(subjects) { canView(it, citizen) }
|
||||||
|
|
||||||
fun <S, C: CitizenI> canView(subject: S, citizen: CitizenI?): AccessResponse where S : OpinionI, S : EntityCreatedBy<C> = when {
|
fun <S, C : CitizenI> canView(subject: S, citizen: CitizenI?): AccessResponse where S : OpinionI, S : EntityCreatedBy<C> = when {
|
||||||
citizen == null -> denied("You must be connected to delete opinion", "opinion.delete.notConnected")
|
citizen == null -> denied("You must be connected to delete opinion", "opinion.delete.notConnected")
|
||||||
subject.createdBy.id != citizen.id -> denied("You cannot view opinions of other citizen", "opinion.view.otherCitizen")
|
subject.createdBy.id != citizen.id -> denied("You cannot view opinions of other citizen", "opinion.view.otherCitizen")
|
||||||
else -> granted()
|
else -> granted()
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package fr.dcproject.component.opinion
|
package fr.dcproject.component.opinion
|
||||||
|
|
||||||
import fr.dcproject.component.citizen.CitizenI
|
import fr.dcproject.component.citizen.CitizenI
|
||||||
import fr.dcproject.component.opinion.entity.OpinionChoice
|
|
||||||
import fr.dcproject.component.opinion.entity.OpinionChoiceI
|
import fr.dcproject.component.opinion.entity.OpinionChoiceI
|
||||||
import fr.dcproject.component.opinion.entity.OpinionChoiceRef
|
|
||||||
import fr.dcproject.security.AccessControl
|
import fr.dcproject.security.AccessControl
|
||||||
import fr.dcproject.security.AccessResponse
|
import fr.dcproject.security.AccessResponse
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,7 @@ import io.ktor.locations.Location
|
|||||||
import io.ktor.locations.get
|
import io.ktor.locations.get
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import org.koin.core.KoinComponent
|
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import fr.dcproject.component.citizen.Citizen as CitizenEntity
|
|
||||||
import fr.dcproject.component.opinion.OpinionRepositoryArticle as OpinionArticleRepository
|
import fr.dcproject.component.opinion.OpinionRepositoryArticle as OpinionArticleRepository
|
||||||
|
|
||||||
@KtorExperimentalLocationsAPI
|
@KtorExperimentalLocationsAPI
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package fr.dcproject.component.opinion.routes
|
|||||||
import fr.dcproject.common.entity.TargetRef
|
import fr.dcproject.common.entity.TargetRef
|
||||||
import fr.dcproject.component.auth.citizen
|
import fr.dcproject.component.auth.citizen
|
||||||
import fr.dcproject.component.auth.citizenOrNull
|
import fr.dcproject.component.auth.citizenOrNull
|
||||||
import fr.dcproject.component.citizen.CitizenBasicI
|
|
||||||
import fr.dcproject.component.citizen.CitizenRef
|
import fr.dcproject.component.citizen.CitizenRef
|
||||||
import fr.dcproject.component.opinion.OpinionAccessControl
|
import fr.dcproject.component.opinion.OpinionAccessControl
|
||||||
import fr.dcproject.component.opinion.entity.Opinion
|
import fr.dcproject.component.opinion.entity.Opinion
|
||||||
@@ -17,8 +16,8 @@ import io.ktor.locations.Location
|
|||||||
import io.ktor.locations.get
|
import io.ktor.locations.get
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import fr.dcproject.component.opinion.OpinionRepositoryArticle as OpinionArticleRepository
|
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
import fr.dcproject.component.opinion.OpinionRepositoryArticle as OpinionArticleRepository
|
||||||
|
|
||||||
@KtorExperimentalLocationsAPI
|
@KtorExperimentalLocationsAPI
|
||||||
object GetMyOpinionsArticle {
|
object GetMyOpinionsArticle {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import fr.dcproject.component.auth.citizenOrNull
|
|||||||
import fr.dcproject.component.opinion.OpinionChoiceAccessControl
|
import fr.dcproject.component.opinion.OpinionChoiceAccessControl
|
||||||
import fr.dcproject.component.opinion.OpinionChoiceRepository
|
import fr.dcproject.component.opinion.OpinionChoiceRepository
|
||||||
import fr.dcproject.security.assert
|
import fr.dcproject.security.assert
|
||||||
|
import fr.dcproject.utils.toUUID
|
||||||
import io.ktor.application.call
|
import io.ktor.application.call
|
||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import io.ktor.http.HttpStatusCode
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.put
|
import io.ktor.locations.put
|
||||||
import io.ktor.request.receive
|
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package fr.dcproject.component.vote.routes
|
package fr.dcproject.component.vote.routes
|
||||||
|
|
||||||
import fr.dcproject.component.auth.citizenOrNull
|
import fr.dcproject.component.auth.citizenOrNull
|
||||||
import fr.dcproject.component.citizen.Citizen
|
|
||||||
import fr.dcproject.component.citizen.CitizenRef
|
import fr.dcproject.component.citizen.CitizenRef
|
||||||
import fr.dcproject.component.vote.VoteAccessControl
|
import fr.dcproject.component.vote.VoteAccessControl
|
||||||
import fr.dcproject.component.vote.VoteRepository
|
import fr.dcproject.component.vote.VoteRepository
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package fr.dcproject.component.vote.routes
|
package fr.dcproject.component.vote.routes
|
||||||
|
|
||||||
import fr.dcproject.component.auth.citizenOrNull
|
import fr.dcproject.component.auth.citizenOrNull
|
||||||
import fr.dcproject.component.citizen.Citizen
|
|
||||||
import fr.dcproject.component.citizen.CitizenRef
|
import fr.dcproject.component.citizen.CitizenRef
|
||||||
import fr.dcproject.component.vote.VoteAccessControl
|
import fr.dcproject.component.vote.VoteAccessControl
|
||||||
import fr.dcproject.component.vote.VoteArticleRepository
|
import fr.dcproject.component.vote.VoteArticleRepository
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import io.ktor.http.HttpStatusCode
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.put
|
import io.ktor.locations.put
|
||||||
import io.ktor.request.receive
|
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import io.ktor.http.HttpStatusCode
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.put
|
import io.ktor.locations.put
|
||||||
import io.ktor.request.receive
|
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|||||||
@@ -16,10 +16,8 @@ import io.ktor.http.HttpStatusCode
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.put
|
import io.ktor.locations.put
|
||||||
import io.ktor.request.receive
|
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import fr.dcproject.component.constitution.Constitution as ConstitutionEntity
|
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
@KtorExperimentalLocationsAPI
|
@KtorExperimentalLocationsAPI
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import io.ktor.http.HttpStatusCode
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.post
|
import io.ktor.locations.post
|
||||||
import io.ktor.request.receive
|
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import io.ktor.http.HttpStatusCode
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.put
|
import io.ktor.locations.put
|
||||||
import io.ktor.request.receive
|
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import org.koin.core.KoinComponent
|
import org.koin.core.KoinComponent
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import io.ktor.http.HttpStatusCode
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.post
|
import io.ktor.locations.post
|
||||||
import io.ktor.request.receive
|
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import org.koin.core.KoinComponent
|
import org.koin.core.KoinComponent
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import io.ktor.http.HttpStatusCode
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.delete
|
import io.ktor.locations.delete
|
||||||
import io.ktor.request.receive
|
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import org.koin.core.KoinComponent
|
import org.koin.core.KoinComponent
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import io.ktor.http.HttpStatusCode
|
|||||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||||
import io.ktor.locations.Location
|
import io.ktor.locations.Location
|
||||||
import io.ktor.locations.put
|
import io.ktor.locations.put
|
||||||
import io.ktor.request.receive
|
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.Route
|
import io.ktor.routing.Route
|
||||||
import org.koin.core.KoinComponent
|
import org.koin.core.KoinComponent
|
||||||
|
|||||||
@@ -5,21 +5,19 @@ import io.ktor.application.ApplicationCall
|
|||||||
import io.ktor.application.log
|
import io.ktor.application.log
|
||||||
import io.ktor.features.BadRequestException
|
import io.ktor.features.BadRequestException
|
||||||
import io.ktor.request.receive
|
import io.ktor.request.receive
|
||||||
import kotlin.reflect.KType
|
|
||||||
import kotlin.reflect.typeOf
|
import kotlin.reflect.typeOf
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receives content for this request.
|
* Receives content for this request.
|
||||||
* @param type instance of `KClass` specifying type to be received.
|
* @param type instance of `KClass` specifying type to be received.
|
||||||
* @return instance of [T] received from this call, or `null` if content cannot be transformed to the requested type..
|
* @return instance of [T] received from this call, or `null` if content cannot be transformed to the requested type..
|
||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalStdlibApi::class)
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
public suspend inline fun <reified T : Any> ApplicationCall.receiveOrBadRequest(message: String = "Bad Request, wrong body request"): T {
|
public suspend inline fun <reified T : Any> ApplicationCall.receiveOrBadRequest(message: String = "Bad Request, wrong body request"): T {
|
||||||
return try {
|
return try {
|
||||||
receive<T>(typeOf<T>())
|
receive<T>(typeOf<T>())
|
||||||
} catch (cause: MissingKotlinParameterException) {
|
} catch (cause: MissingKotlinParameterException) {
|
||||||
application.log.debug("Conversion failed, throw bad exeption", cause)
|
application.log.debug("Conversion failed, throw bad exeption", cause)
|
||||||
throw BadRequestException(message, cause)
|
throw BadRequestException(message, cause)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user