Refactor: split content order API; near-default detekt thresholds

This commit is contained in:
2026-09-27 22:38:48 +03:00
parent 3ed48b35fc
commit 290b2a5a20
3 changed files with 94 additions and 86 deletions

View File

@@ -33,31 +33,6 @@ fun ApiClient.contentArticle(
.body(ContentArticleDto::class.java)
}
fun ApiClient.setContentPublished(
token: String,
kind: String,
id: String,
published: Boolean,
) {
val path =
when (kind) {
"chapters" -> "/api/v1/content/chapters/{id}/published"
"sections" -> "/api/v1/content/sections/{id}/published"
"articles" -> "/api/v1/content/articles/{id}/published"
else -> throw IllegalArgumentException("Неизвестный тип материала: $kind")
}
call {
client
.put()
.uri(path, id)
.header(HttpHeaders.AUTHORIZATION, bearer(token))
.contentType(MediaType.APPLICATION_JSON)
.body(mapOf("published" to published))
.retrieve()
.toBodilessEntity()
}
}
fun ApiClient.contentTreeList(token: String?): List<ContentArticleDto> {
val type = object : ParameterizedTypeReference<List<ContentArticleDto>>() {}
return call {
@@ -68,56 +43,6 @@ fun ApiClient.contentTreeList(token: String?): List<ContentArticleDto> {
}
}
fun ApiClient.reorderContent(
token: String,
tree: ContentReorderDto,
) {
call {
client
.post()
.uri("/api/v1/content/reorder")
.header(HttpHeaders.AUTHORIZATION, bearer(token))
.contentType(MediaType.APPLICATION_JSON)
.body(tree)
.retrieve()
.toBodilessEntity()
}
}
fun ApiClient.reorderSections(
token: String,
chapterId: String,
body: SectionsReorderDto,
) {
call {
client
.post()
.uri("/api/v1/content/chapters/{id}/sections/reorder", chapterId)
.header(HttpHeaders.AUTHORIZATION, bearer(token))
.contentType(MediaType.APPLICATION_JSON)
.body(body)
.retrieve()
.toBodilessEntity()
}
}
fun ApiClient.reorderArticles(
token: String,
sectionId: String,
body: ArticlesReorderDto,
) {
call {
client
.post()
.uri("/api/v1/content/sections/{id}/articles/reorder", sectionId)
.header(HttpHeaders.AUTHORIZATION, bearer(token))
.contentType(MediaType.APPLICATION_JSON)
.body(body)
.retrieve()
.toBodilessEntity()
}
}
fun ApiClient.importContent(
token: String,
filename: String,

View File

@@ -0,0 +1,79 @@
package ru.ysu.lms.web.api
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
fun ApiClient.setContentPublished(
token: String,
kind: String,
id: String,
published: Boolean,
) {
val path =
when (kind) {
"chapters" -> "/api/v1/content/chapters/{id}/published"
"sections" -> "/api/v1/content/sections/{id}/published"
"articles" -> "/api/v1/content/articles/{id}/published"
else -> throw IllegalArgumentException("Неизвестный тип материала: $kind")
}
call {
client
.put()
.uri(path, id)
.header(HttpHeaders.AUTHORIZATION, bearer(token))
.contentType(MediaType.APPLICATION_JSON)
.body(mapOf("published" to published))
.retrieve()
.toBodilessEntity()
}
}
fun ApiClient.reorderContent(
token: String,
tree: ContentReorderDto,
) {
call {
client
.post()
.uri("/api/v1/content/reorder")
.header(HttpHeaders.AUTHORIZATION, bearer(token))
.contentType(MediaType.APPLICATION_JSON)
.body(tree)
.retrieve()
.toBodilessEntity()
}
}
fun ApiClient.reorderSections(
token: String,
chapterId: String,
body: SectionsReorderDto,
) {
call {
client
.post()
.uri("/api/v1/content/chapters/{id}/sections/reorder", chapterId)
.header(HttpHeaders.AUTHORIZATION, bearer(token))
.contentType(MediaType.APPLICATION_JSON)
.body(body)
.retrieve()
.toBodilessEntity()
}
}
fun ApiClient.reorderArticles(
token: String,
sectionId: String,
body: ArticlesReorderDto,
) {
call {
client
.post()
.uri("/api/v1/content/sections/{id}/articles/reorder", sectionId)
.header(HttpHeaders.AUTHORIZATION, bearer(token))
.contentType(MediaType.APPLICATION_JSON)
.body(body)
.retrieve()
.toBodilessEntity()
}
}