From 9821833dd8e44fb1f654ae1bcd884adfd489c202 Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Wed, 14 Aug 2019 22:49:01 +0200 Subject: [PATCH] feature #14: create route for unfollow article --- .../kotlin/fr/dcproject/repository/Follow.kt | 11 +++++++++++ src/main/kotlin/fr/dcproject/routes/Follow.kt | 6 ++++++ src/test/resources/feature/follow.feature | 16 +++++++++++----- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/fr/dcproject/repository/Follow.kt b/src/main/kotlin/fr/dcproject/repository/Follow.kt index c24ebc7..06d9d18 100644 --- a/src/main/kotlin/fr/dcproject/repository/Follow.kt +++ b/src/main/kotlin/fr/dcproject/repository/Follow.kt @@ -21,5 +21,16 @@ open class Follow >(override var requester: Requester): Reposit "citizen_id" to follow.citizen.id ) } + + fun unfollow(follow: FollowEntity) { + 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(requester) diff --git a/src/main/kotlin/fr/dcproject/routes/Follow.kt b/src/main/kotlin/fr/dcproject/routes/Follow.kt index 6cdfda4..7ae2b92 100644 --- a/src/main/kotlin/fr/dcproject/routes/Follow.kt +++ b/src/main/kotlin/fr/dcproject/routes/Follow.kt @@ -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 { + repo.unfollow(FollowEntity(target = it.article, citizen = currentCitizen)) + call.respond(HttpStatusCode.NoContent) + } } \ No newline at end of file diff --git a/src/test/resources/feature/follow.feature b/src/test/resources/feature/follow.feature index fcce7c1..3aacfcf 100644 --- a/src/test/resources/feature/follow.feature +++ b/src/test/resources/feature/follow.feature @@ -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: - """ - """ - Then the response status code should be 201 \ No newline at end of file + 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