remove fixed raw citizen and use real current citizen

Fix tests
This commit is contained in:
2019-08-29 14:38:11 +02:00
parent 025153c4cd
commit 201430017e
6 changed files with 14 additions and 32 deletions

View File

@@ -1,26 +1,16 @@
package fr.dcproject.routes
import fr.dcproject.citizen
import fr.dcproject.entity.Citizen
import fr.dcproject.entity.User
import io.ktor.application.call
import io.ktor.http.HttpStatusCode
import io.ktor.locations.*
import io.ktor.response.respond
import io.ktor.routing.Route
import org.joda.time.DateTime
import java.util.*
import fr.dcproject.entity.Article as ArticleEntity
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
object FollowArticlePaths {
@Location("/articles/{article}/follow") class ArticleFollowRequest(val article: ArticleEntity)
@@ -30,12 +20,12 @@ object FollowArticlePaths {
@KtorExperimentalLocationsAPI
fun Route.followArticle(repo: FollowArticleRepository) {
post<FollowArticlePaths.ArticleFollowRequest> {
repo.follow(FollowEntity(target = it.article, createdBy = currentCitizen))
repo.follow(FollowEntity(target = it.article, createdBy = this.citizen))
call.respond(HttpStatusCode.Created)
}
delete<FollowArticlePaths.ArticleFollowRequest> {
repo.unfollow(FollowEntity(target = it.article, createdBy = currentCitizen))
repo.unfollow(FollowEntity(target = it.article, createdBy = this.citizen))
call.respond(HttpStatusCode.NoContent)
}