Fix comment voter
This commit is contained in:
@@ -11,6 +11,7 @@ import fr.postgresjson.repository.RepositoryI
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import fr.dcproject.entity.Citizen as CitizenEntity
|
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.Article as ArticleEntity
|
||||||
|
|
||||||
abstract class Comment<T : TargetI>(override var requester: Requester) : RepositoryI {
|
abstract class Comment<T : TargetI>(override var requester: Requester) : RepositoryI {
|
||||||
abstract fun findById(id: UUID): CommentEntity<T>?
|
abstract fun findById(id: UUID): CommentEntity<T>?
|
||||||
@@ -68,7 +69,7 @@ abstract class Comment<T : TargetI>(override var requester: Requester) : Reposit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun comment(comment: CommentEntity<T>) {
|
fun <I : T> comment(comment: CommentEntity<I>) {
|
||||||
requester
|
requester
|
||||||
.getFunction("comment")
|
.getFunction("comment")
|
||||||
.sendQuery(
|
.sendQuery(
|
||||||
@@ -77,7 +78,7 @@ abstract class Comment<T : TargetI>(override var requester: Requester) : Reposit
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun edit(comment: CommentEntity<T>) {
|
fun <I : T> edit(comment: CommentEntity<I>) {
|
||||||
requester
|
requester
|
||||||
.getFunction("edit_comment")
|
.getFunction("edit_comment")
|
||||||
.sendQuery(
|
.sendQuery(
|
||||||
@@ -123,8 +124,8 @@ class CommentGeneric(requester: Requester) : Comment<TargetRef>(requester) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CommentArticle(requester: Requester) : Comment<ArticleRef>(requester) {
|
class CommentArticle(requester: Requester) : Comment<ArticleEntity>(requester) {
|
||||||
override fun findById(id: UUID): CommentEntity<ArticleRef>? {
|
override fun findById(id: UUID): CommentEntity<ArticleEntity>? {
|
||||||
return requester
|
return requester
|
||||||
.getFunction("find_comment_by_id")
|
.getFunction("find_comment_by_id")
|
||||||
.selectOne(mapOf("id" to id))
|
.selectOne(mapOf("id" to id))
|
||||||
@@ -134,7 +135,7 @@ class CommentArticle(requester: Requester) : Comment<ArticleRef>(requester) {
|
|||||||
citizen: CitizenEntity,
|
citizen: CitizenEntity,
|
||||||
page: Int,
|
page: Int,
|
||||||
limit: Int
|
limit: Int
|
||||||
): Paginated<CommentEntity<ArticleRef>> {
|
): Paginated<CommentEntity<ArticleEntity>> {
|
||||||
return requester.run {
|
return requester.run {
|
||||||
getFunction("find_comments_by_citizen")
|
getFunction("find_comments_by_citizen")
|
||||||
.select(
|
.select(
|
||||||
@@ -150,19 +151,17 @@ class CommentArticle(requester: Requester) : Comment<ArticleRef>(requester) {
|
|||||||
page: Int,
|
page: Int,
|
||||||
limit: Int,
|
limit: Int,
|
||||||
sort: Sort
|
sort: Sort
|
||||||
): Paginated<CommentEntity<ArticleRef>> {
|
): Paginated<CommentEntity<ArticleEntity>> = requester
|
||||||
return requester.run {
|
.getFunction("find_comments_by_target")
|
||||||
getFunction("find_comments_by_target")
|
|
||||||
.select(
|
.select(
|
||||||
page, limit,
|
page, limit,
|
||||||
"target_id" to target.id,
|
"target_id" to target.id,
|
||||||
"sort" to sort.sql
|
"sort" to sort.sql
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class Sort(val sql: String) {
|
enum class Sort(val sql: String) {
|
||||||
CREATED_AT("created_at"), VOTES("votes");
|
CREATED_AT("created_at"), VOTES("votes");
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun fromString(string: String): Sort? {
|
fun fromString(string: String): Sort? {
|
||||||
return values().firstOrNull { it.sql == string }
|
return values().firstOrNull { it.sql == string }
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package fr.dcproject.routes
|
package fr.dcproject.routes
|
||||||
|
|
||||||
import fr.dcproject.citizen
|
import fr.dcproject.citizen
|
||||||
import fr.dcproject.entity.ArticleRef
|
import fr.dcproject.entity.Article
|
||||||
import fr.dcproject.entity.Citizen
|
import fr.dcproject.entity.Citizen
|
||||||
import fr.dcproject.repository.CommentArticle.Sort
|
import fr.dcproject.repository.CommentArticle.Sort
|
||||||
import fr.dcproject.security.voter.CommentVoter.Action.CREATE
|
import fr.dcproject.security.voter.CommentVoter.Action.CREATE
|
||||||
@@ -24,7 +24,7 @@ import fr.dcproject.repository.CommentArticle as CommentArticleRepository
|
|||||||
object CommentArticlePaths {
|
object CommentArticlePaths {
|
||||||
@Location("/articles/{article}/comments")
|
@Location("/articles/{article}/comments")
|
||||||
class ArticleCommentRequest(
|
class ArticleCommentRequest(
|
||||||
val article: ArticleRef,
|
val article: Article,
|
||||||
page: Int = 1,
|
page: Int = 1,
|
||||||
limit: Int = 50,
|
limit: Int = 50,
|
||||||
val search: String? = null,
|
val search: String? = null,
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ class ArticleSteps : En, KoinTest {
|
|||||||
("$firstName-$lastName".toLowerCase()).toLowerCase().replace(' ', '-')
|
("$firstName-$lastName".toLowerCase()).toLowerCase().replace(' ', '-')
|
||||||
) ?: error("Citizen not exist")
|
) ?: error("Citizen not exist")
|
||||||
|
|
||||||
val comment: CommentEntity<ArticleRef> = CommentEntity(
|
val comment: CommentEntity<ArticleEntity> = CommentEntity(
|
||||||
id = id ?: params?.get("id")?.let { UUID.fromString(it) } ?: UUID.randomUUID(),
|
id = id ?: params?.get("id")?.let { UUID.fromString(it) } ?: UUID.randomUUID(),
|
||||||
createdBy = citizen,
|
createdBy = citizen,
|
||||||
target = article,
|
target = article,
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ Feature: comment Article
|
|||||||
And I am authenticated as Pierre Curie
|
And I am authenticated as Pierre Curie
|
||||||
And I have article
|
And I have article
|
||||||
| id | 5e209f63-57ce-43ca-922a-273b0d62f567 |
|
| id | 5e209f63-57ce-43ca-922a-273b0d62f567 |
|
||||||
And I have comment created by Enrico Fermi on article "5e209f63-57ce-43ca-922a-273b0d62f567"
|
And I have comment created by Pierre Curie on article "5e209f63-57ce-43ca-922a-273b0d62f567"
|
||||||
When I send a GET request to "/articles/5e209f63-57ce-43ca-922a-273b0d62f567/comments?sort=votes"
|
When I send a GET request to "/articles/5e209f63-57ce-43ca-922a-273b0d62f567/comments?sort=votes"
|
||||||
Then the response status code should be 200
|
Then the response status code should be 200
|
||||||
And the response should contain object:
|
And the response should contain object:
|
||||||
|
|||||||
Reference in New Issue
Block a user