From ddea05aea0a2bf66777a634368e0904fb00c49b7 Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Fri, 20 Mar 2020 02:11:56 +0100 Subject: [PATCH] Change 404 to 200 if no comment/vote/follow on article --- src/main/kotlin/fr/dcproject/routes/CommentArticle.kt | 4 +++- src/main/kotlin/fr/dcproject/routes/FollowArticle.kt | 6 ++++-- src/main/kotlin/fr/dcproject/routes/VoteArticle.kt | 5 +++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/fr/dcproject/routes/CommentArticle.kt b/src/main/kotlin/fr/dcproject/routes/CommentArticle.kt index 6a34afd..a5c33b2 100644 --- a/src/main/kotlin/fr/dcproject/routes/CommentArticle.kt +++ b/src/main/kotlin/fr/dcproject/routes/CommentArticle.kt @@ -43,7 +43,9 @@ object CommentArticlePaths { fun Route.commentArticle(repo: CommentArticleRepository) { get { val comment = repo.findByTarget(it.article, it.page, it.limit, it.sort) - assertCan(VIEW, comment.result) + if (comment.result.isNotEmpty()) { + assertCan(VIEW, comment.result) + } call.respond(HttpStatusCode.OK, comment) } diff --git a/src/main/kotlin/fr/dcproject/routes/FollowArticle.kt b/src/main/kotlin/fr/dcproject/routes/FollowArticle.kt index cb0f2c5..d829959 100644 --- a/src/main/kotlin/fr/dcproject/routes/FollowArticle.kt +++ b/src/main/kotlin/fr/dcproject/routes/FollowArticle.kt @@ -42,12 +42,14 @@ fun Route.followArticle(repo: FollowArticleRepository) { repo.findFollow(citizen, it.article)?.let { follow -> assertCan(VIEW, follow) call.respond(follow) - } ?: call.respond(HttpStatusCode.NotFound) + } ?: call.respond(HttpStatusCode.NoContent) } get { val follows = repo.findByCitizen(it.citizen) - assertCan(VIEW, follows.result) + if (follows.result.isNotEmpty()) { + assertCan(VIEW, follows.result) + } call.respond(follows) } } \ No newline at end of file diff --git a/src/main/kotlin/fr/dcproject/routes/VoteArticle.kt b/src/main/kotlin/fr/dcproject/routes/VoteArticle.kt index 5b35998..dd67019 100644 --- a/src/main/kotlin/fr/dcproject/routes/VoteArticle.kt +++ b/src/main/kotlin/fr/dcproject/routes/VoteArticle.kt @@ -86,8 +86,9 @@ fun Route.voteArticle(repo: VoteArticleRepository, voteCommentRepo: VoteComment, get { val votes = repo.findCitizenVotesByTargets(it.citizen, it.id) - assertCan(VIEW, votes) - + if (votes.isNotEmpty()) { + assertCan(VIEW, votes) + } call.respond(votes) } } \ No newline at end of file