Refactor: split content order API; near-default detekt thresholds
This commit is contained in:
@@ -9,31 +9,35 @@ config:
|
|||||||
warningsAsErrors: false
|
warningsAsErrors: false
|
||||||
|
|
||||||
complexity:
|
complexity:
|
||||||
# Пороги выставлены под реальный масштаб классов проекта. Дробление крупных
|
# Крупные агрегаты уже раздроблены (web ApiClient — по доменам, AdminController —
|
||||||
# агрегатов (web ApiClient, AdminController, ContentService) — отдельная задача;
|
# на AdminSupport + 5 контроллеров, импорт материалов — в ContentImporter).
|
||||||
# когда оно будет выполнено, пороги можно вернуть к значениям по умолчанию.
|
# Оставшиеся послабления точечные и перечислены ниже; после дробления ContentService
|
||||||
|
# и выноса хелперов из методов groupDetail/labDetail/editLab их можно снять.
|
||||||
LongMethod:
|
LongMethod:
|
||||||
|
# groupDetail (82), labDetail (73), editLab (86) в админ-контроллерах.
|
||||||
threshold: 90
|
threshold: 90
|
||||||
LongParameterList:
|
LongParameterList:
|
||||||
|
# MVC-обработчики форм принимают набор @RequestParam — для них это нормально.
|
||||||
functionThreshold: 8
|
functionThreshold: 8
|
||||||
constructorThreshold: 8
|
constructorThreshold: 8
|
||||||
ignoreDefaultParameters: true
|
ignoreDefaultParameters: true
|
||||||
# MVC-обработчики форм принимают набор @RequestParam — для них параметров «много» нормально.
|
|
||||||
ignoreAnnotated:
|
ignoreAnnotated:
|
||||||
- 'PostMapping'
|
- 'PostMapping'
|
||||||
- 'GetMapping'
|
- 'GetMapping'
|
||||||
TooManyFunctions:
|
TooManyFunctions:
|
||||||
thresholdInFiles: 80
|
# ContentService (26) — следующий кандидат на разделение.
|
||||||
thresholdInClasses: 80
|
thresholdInFiles: 27
|
||||||
thresholdInInterfaces: 40
|
thresholdInClasses: 27
|
||||||
thresholdInObjects: 40
|
thresholdInInterfaces: 20
|
||||||
thresholdInEnums: 40
|
thresholdInObjects: 20
|
||||||
|
thresholdInEnums: 20
|
||||||
LargeClass:
|
LargeClass:
|
||||||
threshold: 1400
|
threshold: 600
|
||||||
ComplexCondition:
|
ComplexCondition:
|
||||||
threshold: 4
|
threshold: 4
|
||||||
CyclomaticComplexMethod:
|
CyclomaticComplexMethod:
|
||||||
threshold: 20
|
# editLab (16) в AdminLabController.
|
||||||
|
threshold: 17
|
||||||
|
|
||||||
style:
|
style:
|
||||||
MagicNumber:
|
MagicNumber:
|
||||||
|
|||||||
@@ -33,31 +33,6 @@ fun ApiClient.contentArticle(
|
|||||||
.body(ContentArticleDto::class.java)
|
.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> {
|
fun ApiClient.contentTreeList(token: String?): List<ContentArticleDto> {
|
||||||
val type = object : ParameterizedTypeReference<List<ContentArticleDto>>() {}
|
val type = object : ParameterizedTypeReference<List<ContentArticleDto>>() {}
|
||||||
return call {
|
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(
|
fun ApiClient.importContent(
|
||||||
token: String,
|
token: String,
|
||||||
filename: String,
|
filename: String,
|
||||||
|
|||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user