implement route /articles/{article}/follows
create repository for find_follow
This commit is contained in:
@@ -40,7 +40,7 @@ interface TargetI : UuidEntityI {
|
|||||||
t.isSubclassOf(ConstitutionRef::class) -> TargetName.Constitution.targetReference
|
t.isSubclassOf(ConstitutionRef::class) -> TargetName.Constitution.targetReference
|
||||||
t.isSubclassOf(CommentRef::class) -> TargetName.Comment.targetReference
|
t.isSubclassOf(CommentRef::class) -> TargetName.Comment.targetReference
|
||||||
t.isSubclassOf(Opinion::class) -> TargetName.Opinion.targetReference
|
t.isSubclassOf(Opinion::class) -> TargetName.Opinion.targetReference
|
||||||
else -> throw error("target not implemented: ${t.qualifiedName}")
|
else -> throw error("target not implemented: ${t.qualifiedName} \nImplement it or return 'reference' from SQL")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import fr.dcproject.entity.Article as ArticleEntity
|
|||||||
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
||||||
import fr.dcproject.entity.Follow as FollowEntity
|
import fr.dcproject.entity.Follow as FollowEntity
|
||||||
|
|
||||||
open class Follow<T : TargetI>(override var requester: Requester) : RepositoryI {
|
open class Follow<T : TargetRef>(override var requester: Requester) : RepositoryI {
|
||||||
open fun findByCitizen(
|
open fun findByCitizen(
|
||||||
citizen: CitizenI,
|
citizen: CitizenI,
|
||||||
page: Int = 1,
|
page: Int = 1,
|
||||||
@@ -25,13 +25,12 @@ open class Follow<T : TargetI>(override var requester: Requester) : RepositoryI
|
|||||||
page: Int = 1,
|
page: Int = 1,
|
||||||
limit: Int = 50
|
limit: Int = 50
|
||||||
): Paginated<FollowEntity<T>> {
|
): Paginated<FollowEntity<T>> {
|
||||||
return requester.run {
|
return requester
|
||||||
getFunction("find_follows_by_citizen")
|
.getFunction("find_follows_by_citizen")
|
||||||
.select(
|
.select(
|
||||||
page, limit,
|
page, limit,
|
||||||
"created_by_id" to citizenId
|
"created_by_id" to citizenId
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun follow(follow: FollowEntity<T>) {
|
fun follow(follow: FollowEntity<T>) {
|
||||||
@@ -53,6 +52,17 @@ open class Follow<T : TargetI>(override var requester: Requester) : RepositoryI
|
|||||||
"created_by_id" to follow.createdBy.id
|
"created_by_id" to follow.createdBy.id
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun findFollow(
|
||||||
|
citizen: CitizenI,
|
||||||
|
target: UuidEntity
|
||||||
|
): FollowEntity<T>? =
|
||||||
|
requester
|
||||||
|
.getFunction("find_follow")
|
||||||
|
.selectOne(
|
||||||
|
"citizen_id" to citizen.id,
|
||||||
|
"target_id" to target.id
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
class FollowArticle(requester: Requester) : Follow<ArticleEntity>(requester) {
|
class FollowArticle(requester: Requester) : Follow<ArticleEntity>(requester) {
|
||||||
|
|||||||
@@ -38,6 +38,13 @@ fun Route.followArticle(repo: FollowArticleRepository) {
|
|||||||
call.respond(HttpStatusCode.NoContent)
|
call.respond(HttpStatusCode.NoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get<FollowArticlePaths.ArticleFollowRequest> {
|
||||||
|
repo.findFollow(citizen, it.article)?.let { follow ->
|
||||||
|
assertCan(VIEW, follow)
|
||||||
|
call.respond(follow)
|
||||||
|
} ?: call.respond(HttpStatusCode.NotFound)
|
||||||
|
}
|
||||||
|
|
||||||
get<FollowArticlePaths.CitizenFollowArticleRequest> {
|
get<FollowArticlePaths.CitizenFollowArticleRequest> {
|
||||||
val follows = repo.findByCitizen(it.citizen)
|
val follows = repo.findByCitizen(it.citizen)
|
||||||
assertCan(VIEW, follows.result)
|
assertCan(VIEW, follows.result)
|
||||||
|
|||||||
@@ -533,6 +533,22 @@ paths:
|
|||||||
/articles/{article}/follows:
|
/articles/{article}/follows:
|
||||||
parameters:
|
parameters:
|
||||||
- $ref: '#/components/parameters/article'
|
- $ref: '#/components/parameters/article'
|
||||||
|
get:
|
||||||
|
security:
|
||||||
|
- JWTAuth: []
|
||||||
|
summary: Return Follow or nothing if you not follow
|
||||||
|
tags:
|
||||||
|
- follow
|
||||||
|
- article
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: Return your follow
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/FollowResponse'
|
||||||
|
404:
|
||||||
|
description: You not follow this article
|
||||||
post:
|
post:
|
||||||
security:
|
security:
|
||||||
- JWTAuth: []
|
- JWTAuth: []
|
||||||
|
|||||||
Reference in New Issue
Block a user