feature #14: create route for unfollow article
This commit is contained in:
@@ -21,5 +21,16 @@ open class Follow <T: EntityI<UUID>>(override var requester: Requester): Reposit
|
||||
"citizen_id" to follow.citizen.id
|
||||
)
|
||||
}
|
||||
|
||||
fun unfollow(follow: FollowEntity<T>) {
|
||||
val reference = follow.target::class.simpleName!!.toLowerCase()
|
||||
requester
|
||||
.getFunction("unfollow")
|
||||
.sendQuery(
|
||||
"reference" to reference,
|
||||
"target_id" to follow.target.id,
|
||||
"citizen_id" to follow.citizen.id
|
||||
)
|
||||
}
|
||||
}
|
||||
class FollowArticleRepository(override var requester: Requester): Follow<ArticleEntity>(requester)
|
||||
|
||||
@@ -7,6 +7,7 @@ import fr.dcproject.repository.FollowArticleRepository
|
||||
import io.ktor.application.call
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||
import io.ktor.locations.delete
|
||||
import io.ktor.locations.post
|
||||
import io.ktor.response.respond
|
||||
import io.ktor.routing.Route
|
||||
@@ -28,4 +29,9 @@ fun Route.followArticle(repo: FollowArticleRepository) {
|
||||
repo.follow(FollowEntity(target = it.article, citizen = currentCitizen))
|
||||
call.respond(HttpStatusCode.Created)
|
||||
}
|
||||
|
||||
delete<Paths.ArticleFollowRequest> {
|
||||
repo.unfollow(FollowEntity(target = it.article, citizen = currentCitizen))
|
||||
call.respond(HttpStatusCode.NoContent)
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,17 @@
|
||||
Feature: follow routes
|
||||
|
||||
Scenario: The route for follow article must response a 200 and return object
|
||||
Scenario: The route for follow article must response a 201 and return object
|
||||
Given I have citizen:
|
||||
| id | 64b7b379-2298-43ec-b428-ba134930cabd |
|
||||
| firstName | Jaque |
|
||||
| lastName | Dupuis |
|
||||
When I send a "POST" request to "/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/follow" with body:
|
||||
"""
|
||||
"""
|
||||
When I send a "POST" request to "/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/follow"
|
||||
Then the response status code should be 201
|
||||
|
||||
Scenario: The route for unfollow article must response a 204
|
||||
Given I have citizen:
|
||||
| id | 64b7b379-2298-43ec-b428-ba134930cabd |
|
||||
| firstName | Jaque |
|
||||
| lastName | Dupuis |
|
||||
When I send a "DELETE" request to "/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/follow"
|
||||
Then the response status code should be 204
|
||||
|
||||
Reference in New Issue
Block a user