feature #14: Add routes for follow/unfollow coonstitution
This commit is contained in:
@@ -9,10 +9,7 @@ import com.fasterxml.jackson.datatype.joda.JodaModule
|
||||
import fr.dcproject.entity.Article
|
||||
import fr.dcproject.entity.Citizen
|
||||
import fr.dcproject.entity.Constitution
|
||||
import fr.dcproject.routes.article
|
||||
import fr.dcproject.routes.citizen
|
||||
import fr.dcproject.routes.constitution
|
||||
import fr.dcproject.routes.followArticle
|
||||
import fr.dcproject.routes.*
|
||||
import fr.postgresjson.migration.Migrations
|
||||
import io.ktor.application.Application
|
||||
import io.ktor.application.install
|
||||
@@ -121,6 +118,7 @@ fun Application.module() {
|
||||
citizen(get())
|
||||
constitution(get())
|
||||
followArticle(get())
|
||||
followConstitution(get())
|
||||
}
|
||||
|
||||
// TODO move to postgresJson lib
|
||||
|
||||
@@ -30,6 +30,7 @@ val Module = module {
|
||||
single { CitizenRepository(get()) }
|
||||
single { ConstitutionRepository(get()) }
|
||||
single { FollowArticleRepository(get()) }
|
||||
single { FollowConstitutionRepository(get()) }
|
||||
|
||||
single { Migrations(connection = get(), directory = config.sqlFiles) }
|
||||
}
|
||||
|
||||
@@ -8,4 +8,5 @@ class Follow <T: EntityI<UUID>> (
|
||||
override var target: T
|
||||
): Extra<T>(id, citizen)
|
||||
|
||||
typealias FollowArticleEntity = Follow<Article>
|
||||
typealias FollowArticleEntity = Follow<Article>
|
||||
typealias FollowConstitutionEntity = Follow<Constitution>
|
||||
@@ -6,6 +6,7 @@ import fr.postgresjson.repository.RepositoryI
|
||||
import java.util.*
|
||||
import kotlin.reflect.KClass
|
||||
import fr.dcproject.entity.Article as ArticleEntity
|
||||
import fr.dcproject.entity.Constitution as ConstitutionEntity
|
||||
import fr.dcproject.entity.Follow as FollowEntity
|
||||
|
||||
open class Follow <T: EntityI<UUID>>(override var requester: Requester): RepositoryI<FollowEntity<T>> {
|
||||
@@ -34,3 +35,4 @@ open class Follow <T: EntityI<UUID>>(override var requester: Requester): Reposit
|
||||
}
|
||||
}
|
||||
class FollowArticleRepository(override var requester: Requester): Follow<ArticleEntity>(requester)
|
||||
class FollowConstitutionRepository(override var requester: Requester): Follow<ConstitutionEntity>(requester)
|
||||
|
||||
37
src/main/kotlin/fr/dcproject/routes/FollowConstitution.kt
Normal file
37
src/main/kotlin/fr/dcproject/routes/FollowConstitution.kt
Normal file
@@ -0,0 +1,37 @@
|
||||
package fr.dcproject.routes
|
||||
|
||||
import Paths
|
||||
import fr.dcproject.entity.Citizen
|
||||
import fr.dcproject.entity.User
|
||||
import fr.dcproject.repository.FollowConstitutionRepository
|
||||
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
|
||||
import org.joda.time.DateTime
|
||||
import java.util.*
|
||||
import fr.dcproject.entity.Follow as FollowEntity
|
||||
|
||||
// TODO get current citizen
|
||||
val currentCitizen2 = Citizen(
|
||||
id = UUID.fromString("64b7b379-2298-43ec-b428-ba134930cabd"),
|
||||
name = Citizen.Name("todo", "todo"),
|
||||
birthday = DateTime.now(),
|
||||
user = User(username = "plop", plainPassword = "plip")
|
||||
)
|
||||
|
||||
@KtorExperimentalLocationsAPI
|
||||
fun Route.followConstitution(repo: FollowConstitutionRepository) {
|
||||
post<Paths.ConstitutionFollowRequest> {
|
||||
repo.follow(FollowEntity(target = it.constitution, citizen = currentCitizen2))
|
||||
call.respond(HttpStatusCode.Created)
|
||||
}
|
||||
|
||||
delete<Paths.ConstitutionFollowRequest> {
|
||||
repo.unfollow(FollowEntity(target = it.constitution, citizen = currentCitizen2))
|
||||
call.respond(HttpStatusCode.NoContent)
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ object Paths {
|
||||
val limit: Int = if (limit > 50) 50 else if (limit < 1) 1 else limit
|
||||
}
|
||||
@Location("/constitutions/{constitution}") class ConstitutionRequest(val constitution: Constitution)
|
||||
@Location("/constitutions/{constitution}/follow") class ConstitutionFollowRequest(val constitution: Constitution)
|
||||
@Location("/constitutions") class PostConstitutionRequest
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
Feature: follow routes
|
||||
Feature: follow Article and Constitution
|
||||
|
||||
# Article
|
||||
Scenario: The route for follow article must response a 201 and return object
|
||||
Given I have citizen:
|
||||
| id | 64b7b379-2298-43ec-b428-ba134930cabd |
|
||||
@@ -15,3 +16,20 @@ Feature: follow routes
|
||||
| lastName | Dupuis |
|
||||
When I send a "DELETE" request to "/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/follow"
|
||||
Then the response status code should be 204
|
||||
|
||||
# Constitution
|
||||
Scenario: The route for follow constitution 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 "/constitutions/72aa1ee1-4963-eb44-c9e0-5ce6e0f18f00/follow"
|
||||
Then the response status code should be 201
|
||||
|
||||
Scenario: The route for unfollow constitution 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 "/constitutions/72aa1ee1-4963-eb44-c9e0-5ce6e0f18f00/follow"
|
||||
Then the response status code should be 204
|
||||
|
||||
Reference in New Issue
Block a user