feat: 增加章节阅读功能
This commit is contained in:
@@ -5,6 +5,7 @@ import jakarta.annotation.Resource
|
|||||||
import jakarta.transaction.Transactional
|
import jakarta.transaction.Transactional
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.data.domain.PageRequest
|
import org.springframework.data.domain.PageRequest
|
||||||
|
import org.springframework.data.domain.Sort
|
||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
|
|
||||||
data class PageResponse<E>(
|
data class PageResponse<E>(
|
||||||
@@ -12,6 +13,12 @@ data class PageResponse<E>(
|
|||||||
val total: Long,
|
val total: Long,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class SingleResponse<E>(
|
||||||
|
val data: Map<String, E>,
|
||||||
|
) {
|
||||||
|
constructor(e: E): this(mapOf("item" to e))
|
||||||
|
}
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("book")
|
@RequestMapping("book")
|
||||||
class BookController {
|
class BookController {
|
||||||
@@ -154,6 +161,17 @@ class ChapterController {
|
|||||||
return chapterRepository.findById(chapterId).orElseThrow().let { ViewItem(it) }
|
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
|
@Transactional
|
||||||
@GetMapping("remove/{chapterId}")
|
@GetMapping("remove/{chapterId}")
|
||||||
fun remove(@PathVariable("chapterId") chapterId: String) {
|
fun remove(@PathVariable("chapterId") chapterId: String) {
|
||||||
|
|||||||
@@ -150,6 +150,26 @@
|
|||||||
label: '编辑',
|
label: '编辑',
|
||||||
...chapterDetailDialog(),
|
...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',
|
type: 'action',
|
||||||
label: '导入',
|
label: '导入',
|
||||||
|
|||||||
Reference in New Issue
Block a user