Test openapi schema response of FindArticlesVersion,GetOneArticle,UpsertArticle

change snack_case to camelCase
This commit is contained in:
2021-03-12 23:32:32 +01:00
parent ed0873837b
commit 9c88adbabd
17 changed files with 432 additions and 156 deletions

View File

@@ -1,7 +1,5 @@
package fr.dcproject.component.article.routes
import fr.dcproject.common.dto.CreatedAt
import fr.dcproject.common.dto.Versionable
import fr.dcproject.common.security.assert
import fr.dcproject.component.article.ArticleAccessControl
import fr.dcproject.component.article.ArticleViewManager
@@ -9,10 +7,6 @@ import fr.dcproject.component.article.database.ArticleForView
import fr.dcproject.component.article.database.ArticleRef
import fr.dcproject.component.article.database.ArticleRepository
import fr.dcproject.component.auth.citizenOrNull
import fr.dcproject.component.opinion.dto.Opinionable
import fr.dcproject.component.views.dto.Viewable
import fr.dcproject.component.views.entity.ViewAggregation
import fr.dcproject.component.vote.dto.Votable
import io.ktor.application.call
import io.ktor.features.NotFoundException
import io.ktor.locations.KtorExperimentalLocationsAPI
@@ -30,39 +24,56 @@ object GetOneArticle {
val article = ArticleRef(article)
}
class Output(
article: ArticleForView,
views: ViewAggregation = ViewAggregation()
) : CreatedAt by CreatedAt.Imp(article),
Opinionable by Opinionable.Imp(article),
Votable by Votable.Imp(article),
Versionable by Versionable.Imp(article),
Viewable by Viewable.Imp(views) {
val id = article.id
val title = article.title
val anonymous = article.anonymous
val content = article.content
val description = article.description
val tags = article.tags
val draft = article.draft
val lastVersion = article.lastVersion
val createdBy = article.createdBy
val workgroup = article.workgroup?.let { Workgroup(article.workgroup.id, article.workgroup.name) }
class Workgroup(val id: UUID, val name: String)
}
fun Route.getOneArticle(viewManager: ArticleViewManager<ArticleForView>, ac: ArticleAccessControl, repo: ArticleRepository) {
get<ArticleRequest> {
val article: ArticleForView = repo.findById(it.article.id) ?: throw NotFoundException("Article ${it.article.id} not found")
ac.assert { canView(article, citizenOrNull) }
Output(
article,
viewManager.getViewsCount(article)
).also { out ->
call.respond(out)
}
call.respond(
article.let { a ->
object {
val id = a.id
val versionId = a.versionId
val versionNumber = a.versionNumber
val title = a.title
val anonymous = a.anonymous
val content = a.content
val description = a.description
val tags = a.tags
val draft = a.draft
val lastVersion = a.lastVersion
val createdAt = a.createdAt
val createdBy: Any = object {
val id: UUID = a.createdBy.id
val name: Any = object {
val firstName: String = a.createdBy.name.firstName
val lastName: String = a.createdBy.name.lastName
}
val email: String = a.createdBy.email
}
val workgroup: Any? = a.workgroup?.let { w ->
object {
val id: UUID = w.id
val name: String = w.name
}
}
val votes: Any = object {
val up: Int = a.votes.up
val neutral: Int = a.votes.neutral
val down: Int = a.votes.down
val total: Int = a.votes.total
val score: Int = a.votes.score
}
val views: Any = viewManager.getViewsCount(article).let { v ->
object {
val total = v.total
val unique = v.unique
}
}
val opinions: Map<String, Int> = a.opinions
}
}
)
launch {
viewManager.addView(call.request.local.remoteHost, article, citizenOrNull)