feature #14: create route for unfollow article

This commit is contained in:
2019-08-14 22:49:01 +02:00
parent 17746d9b1e
commit 9821833dd8
3 changed files with 28 additions and 5 deletions

View File

@@ -21,5 +21,16 @@ open class Follow <T: EntityI<UUID>>(override var requester: Requester): Reposit
"citizen_id" to follow.citizen.id "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) class FollowArticleRepository(override var requester: Requester): Follow<ArticleEntity>(requester)

View File

@@ -7,6 +7,7 @@ import fr.dcproject.repository.FollowArticleRepository
import io.ktor.application.call import io.ktor.application.call
import io.ktor.http.HttpStatusCode import io.ktor.http.HttpStatusCode
import io.ktor.locations.KtorExperimentalLocationsAPI import io.ktor.locations.KtorExperimentalLocationsAPI
import io.ktor.locations.delete
import io.ktor.locations.post import io.ktor.locations.post
import io.ktor.response.respond import io.ktor.response.respond
import io.ktor.routing.Route import io.ktor.routing.Route
@@ -28,4 +29,9 @@ fun Route.followArticle(repo: FollowArticleRepository) {
repo.follow(FollowEntity(target = it.article, citizen = currentCitizen)) repo.follow(FollowEntity(target = it.article, citizen = currentCitizen))
call.respond(HttpStatusCode.Created) call.respond(HttpStatusCode.Created)
} }
delete<Paths.ArticleFollowRequest> {
repo.unfollow(FollowEntity(target = it.article, citizen = currentCitizen))
call.respond(HttpStatusCode.NoContent)
}
} }

View File

@@ -1,11 +1,17 @@
Feature: follow routes 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: Given I have citizen:
| id | 64b7b379-2298-43ec-b428-ba134930cabd | | id | 64b7b379-2298-43ec-b428-ba134930cabd |
| firstName | Jaque | | firstName | Jaque |
| lastName | Dupuis | | 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
"""
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