1
0

feat: 增加章节阅读功能

This commit is contained in:
2024-12-22 10:38:31 +08:00
parent 0c979985ed
commit 9fd28264dd
2 changed files with 38 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import jakarta.annotation.Resource
import jakarta.transaction.Transactional
import org.slf4j.LoggerFactory
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Sort
import org.springframework.web.bind.annotation.*
data class PageResponse<E>(
@@ -12,6 +13,12 @@ data class PageResponse<E>(
val total: Long,
)
data class SingleResponse<E>(
val data: Map<String, E>,
) {
constructor(e: E): this(mapOf("item" to e))
}
@RestController
@RequestMapping("book")
class BookController {
@@ -154,6 +161,17 @@ class ChapterController {
return chapterRepository.findById(chapterId).orElseThrow().let { ViewItem(it) }
}
@GetMapping("show/{chapterId}")
fun show(@PathVariable("chapterId") chapterId: String): SingleResponse<String> {
return SingleResponse(
lineRepository
.findAll({ root, _, builder ->
builder.equal(root.get<Chapter>("chapter").get<String>("chapterId"), chapterId)
}, Sort.by(Sort.Direction.DESC, "sequence"))
.joinToString("\n") { "<p>${it.text}</p>" }
)
}
@Transactional
@GetMapping("remove/{chapterId}")
fun remove(@PathVariable("chapterId") chapterId: String) {

View File

@@ -150,6 +150,26 @@
label: '编辑',
...chapterDetailDialog(),
},
{
type: 'action',
label: '阅读',
actionType: 'dialog',
dialog: {
title: '阅读',
size: 'lg',
actions: [],
body: {
type: 'service',
className: 'p-10',
api: '${base}/chapter/show/${chapterId}',
silentPolling: true,
body: {
type: 'tpl',
tpl: '${item|raw}'
}
}
}
},
{
type: 'action',
label: '导入',