feature #14: create route for follow article
This commit is contained in:
31
src/main/kotlin/fr/dcproject/routes/Follow.kt
Normal file
31
src/main/kotlin/fr/dcproject/routes/Follow.kt
Normal file
@@ -0,0 +1,31 @@
|
||||
package fr.dcproject.routes
|
||||
|
||||
import Paths
|
||||
import fr.dcproject.entity.Citizen
|
||||
import fr.dcproject.entity.User
|
||||
import fr.dcproject.repository.FollowArticleRepository
|
||||
import io.ktor.application.call
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||
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 currentCitizen = 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.followArticle(repo: FollowArticleRepository) {
|
||||
post<Paths.ArticleFollowRequest> {
|
||||
repo.follow(FollowEntity(target = it.article, citizen = currentCitizen))
|
||||
call.respond(HttpStatusCode.Created)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import fr.dcproject.entity.Article
|
||||
import fr.dcproject.entity.Constitution
|
||||
import fr.dcproject.entity.Follow
|
||||
import fr.postgresjson.repository.RepositoryI.Direction
|
||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||
import io.ktor.locations.Location
|
||||
@@ -11,6 +12,7 @@ object Paths {
|
||||
val limit: Int = if (limit > 50) 50 else if (limit < 1) 1 else limit
|
||||
}
|
||||
@Location("/articles/{article}") class ArticleRequest(val article: Article)
|
||||
@Location("/articles/{article}/follow") class ArticleFollowRequest(val article: Article)
|
||||
@Location("/articles") class PostArticleRequest
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user