feature #14: Add routes for get follows of one citizen
This commit is contained in:
43
src/main/kotlin/fr/dcproject/routes/FollowArticle.kt
Normal file
43
src/main/kotlin/fr/dcproject/routes/FollowArticle.kt
Normal file
@@ -0,0 +1,43 @@
|
||||
package fr.dcproject.routes
|
||||
|
||||
import Paths
|
||||
import fr.dcproject.entity.Citizen
|
||||
import fr.dcproject.entity.User
|
||||
import io.ktor.application.call
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.locations.KtorExperimentalLocationsAPI
|
||||
import io.ktor.locations.delete
|
||||
import io.ktor.locations.get
|
||||
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
|
||||
import fr.dcproject.repository.FollowArticle as FollowArticleRepository
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
delete<Paths.ArticleFollowRequest> {
|
||||
repo.unfollow(FollowEntity(target = it.article, citizen = currentCitizen))
|
||||
call.respond(HttpStatusCode.NoContent)
|
||||
}
|
||||
|
||||
get<Paths.CitizenFollowArticleRequest> {
|
||||
val follows = repo.findByCitizenId(it.citizen)
|
||||
call.respond(follows)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user