Add route for get all versions of one article

This commit is contained in:
2019-09-05 17:15:54 +02:00
parent 6423491be3
commit 742927a590
4 changed files with 51 additions and 3 deletions

View File

@@ -16,6 +16,12 @@ class Article(override var requester: Requester) : RepositoryI<ArticleEntity> {
return function.selectOne("id" to id)
}
fun findVerionsByVersionsId(page: Int = 1, limit: Int = 50, versionId: UUID): Paginated<ArticleEntity> {
return requester
.getFunction("find_articles_versions_by_version_id")
.select(page, limit, "version_id" to versionId)
}
fun find(
page: Int = 1,
limit: Int = 50,

View File

@@ -23,6 +23,10 @@ object ArticlesPaths {
val limit: Int = if (limit > 50) 50 else if (limit < 1) 1 else limit
}
@Location("/articles/{article}") class ArticleRequest(val article: ArticleEntity)
@Location("/articles/{article}/versions") class ArticleVersionsRequest(val article: ArticleEntity, page: Int = 1, limit: Int = 50, val sort: String? = null, val direction: RepositoryI.Direction? = null, val search: String? = null) {
val page: Int = if (page < 1) 1 else page
val limit: Int = if (limit > 50) 50 else if (limit < 1) 1 else limit
}
@Location("/articles") class PostArticleRequest
}
@@ -40,6 +44,14 @@ fun Route.article(repo: ArticleRepository) {
call.respond(it.article)
}
get<ArticlesPaths.ArticleVersionsRequest> {
assertCan(VIEW, it.article)
val versions = repo.findVerionsByVersionsId(it.page, it.limit, it.article.versionId)
call.respond(versions)
}
post<ArticlesPaths.PostArticleRequest> {
val article = call.receive<ArticleEntity>()
article.createdBy = citizen

View File

@@ -159,6 +159,32 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/ArticleResponse'
/articles/{article}/versions:
get:
summary: Get all versions of articles
tags:
- article
operationId: getArticleVersions
parameters:
- name: article
in: path
required: true
description: the ID of article
schema:
type: string
format: uuid
responses:
200:
description: The versions of Article
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/Paginated'
- type: object
properties:
result:
type: array
items:
$ref: '#/components/schemas/ArticleResponse'

View File

@@ -4,6 +4,10 @@ Feature: articles routes
When I send a GET request to "/articles"
Then the response status code should be 200
Scenario: Can get versions of article by the id
When I send a GET request to "/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b/versions"
Then the response status code should be 200
Scenario: The route for get one article must response a 200 and return article
When I send a GET request to "/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b"
Then the response status code should be 200