return votes after vote

This commit is contained in:
2019-09-20 22:42:50 +02:00
parent 2311d3986e
commit a37afc1ada
6 changed files with 41 additions and 10 deletions

View File

@@ -2,6 +2,7 @@ package fr.dcproject.repository
import fr.dcproject.entity.Article
import fr.dcproject.entity.Constitution
import fr.dcproject.entity.VoteAggregation
import fr.postgresjson.connexion.Requester
import fr.postgresjson.entity.UuidEntity
import fr.postgresjson.repository.RepositoryI
@@ -11,19 +12,19 @@ import fr.dcproject.entity.Vote as VoteEntity
open class Vote <T: UuidEntity>(override var requester: Requester): RepositoryI<VoteEntity<T>> {
override val entityName = VoteEntity::class as KClass<VoteEntity<T>>
fun vote(vote: VoteEntity<T>) {
fun vote(vote: VoteEntity<T>): VoteAggregation {
val reference = vote.target::class.simpleName!!.toLowerCase()
val author = vote.createdBy ?: error("vote must be contain an author")
val anonymous = author.voteAnonymous
requester
return requester
.getFunction("vote")
.sendQuery(
.selectOne(
"reference" to reference,
"target_id" to vote.target.id,
"note" to vote.note,
"created_by_id" to author.id,
"anonymous" to anonymous
)
)!!
}
}