Add route for get all versions of one article
This commit is contained in:
@@ -16,6 +16,12 @@ class Article(override var requester: Requester) : RepositoryI<ArticleEntity> {
|
|||||||
return function.selectOne("id" to id)
|
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(
|
fun find(
|
||||||
page: Int = 1,
|
page: Int = 1,
|
||||||
limit: Int = 50,
|
limit: Int = 50,
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ object ArticlesPaths {
|
|||||||
val limit: Int = if (limit > 50) 50 else if (limit < 1) 1 else limit
|
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}") 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
|
@Location("/articles") class PostArticleRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +44,14 @@ fun Route.article(repo: ArticleRepository) {
|
|||||||
call.respond(it.article)
|
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> {
|
post<ArticlesPaths.PostArticleRequest> {
|
||||||
val article = call.receive<ArticleEntity>()
|
val article = call.receive<ArticleEntity>()
|
||||||
article.createdBy = citizen
|
article.createdBy = citizen
|
||||||
|
|||||||
@@ -159,9 +159,35 @@ paths:
|
|||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
type: array
|
$ref: '#/components/schemas/ArticleResponse'
|
||||||
items:
|
/articles/{article}/versions:
|
||||||
$ref: '#/components/schemas/ArticleResponse'
|
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'
|
||||||
|
|
||||||
/constitutions:
|
/constitutions:
|
||||||
get:
|
get:
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ Feature: articles routes
|
|||||||
When I send a GET request to "/articles"
|
When I send a GET request to "/articles"
|
||||||
Then the response status code should be 200
|
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
|
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"
|
When I send a GET request to "/articles/9226c1a3-8091-c3fa-7d0d-c2e98c9bee7b"
|
||||||
Then the response status code should be 200
|
Then the response status code should be 200
|
||||||
|
|||||||
Reference in New Issue
Block a user