Change 404 to 200 if no comment/vote/follow on article

This commit is contained in:
2020-03-20 02:11:56 +01:00
parent c55eba4219
commit ddea05aea0
3 changed files with 10 additions and 5 deletions

View File

@@ -43,7 +43,9 @@ object CommentArticlePaths {
fun Route.commentArticle(repo: CommentArticleRepository) {
get<CommentArticlePaths.ArticleCommentRequest> {
val comment = repo.findByTarget(it.article, it.page, it.limit, it.sort)
if (comment.result.isNotEmpty()) {
assertCan(VIEW, comment.result)
}
call.respond(HttpStatusCode.OK, comment)
}

View File

@@ -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<FollowArticlePaths.CitizenFollowArticleRequest> {
val follows = repo.findByCitizen(it.citizen)
if (follows.result.isNotEmpty()) {
assertCan(VIEW, follows.result)
}
call.respond(follows)
}
}

View File

@@ -86,8 +86,9 @@ fun Route.voteArticle(repo: VoteArticleRepository, voteCommentRepo: VoteComment,
get<VoteArticlePaths.CitizenVotesByIdsRequest> {
val votes = repo.findCitizenVotesByTargets(it.citizen, it.id)
if (votes.isNotEmpty()) {
assertCan(VIEW, votes)
}
call.respond(votes)
}
}