return votes after vote
This commit is contained in:
@@ -3,8 +3,8 @@ package fr.dcproject.entity
|
||||
import fr.postgresjson.entity.*
|
||||
import java.util.*
|
||||
|
||||
interface ExtraI <T: EntityI<UUID>>:
|
||||
EntityI<UUID>,
|
||||
interface ExtraI <T: EntityI>:
|
||||
EntityI,
|
||||
EntityCreatedAt,
|
||||
EntityCreatedBy<Citizen>{
|
||||
var target: T
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fr.dcproject.entity
|
||||
|
||||
import fr.postgresjson.entity.EntityI
|
||||
import fr.postgresjson.entity.EntityUpdatedAt
|
||||
import fr.postgresjson.entity.EntityUpdatedAtImp
|
||||
|
||||
@@ -7,4 +8,5 @@ open class VoteAggregation (
|
||||
val up: Int,
|
||||
val neutral: Int,
|
||||
val down: Int
|
||||
): EntityUpdatedAt by EntityUpdatedAtImp()
|
||||
): EntityI,
|
||||
EntityUpdatedAt by EntityUpdatedAtImp()
|
||||
|
||||
@@ -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
|
||||
)
|
||||
)!!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ fun Route.voteArticle(repo: VoteArticleRepository) {
|
||||
createdBy = this.citizen
|
||||
)
|
||||
assertCan(CREATE, vote)
|
||||
repo.vote(vote)
|
||||
call.respond(HttpStatusCode.Created)
|
||||
val votes = repo.vote(vote)
|
||||
call.respond(HttpStatusCode.Created, votes)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user