diff --git a/src/main/kotlin/com/lanyuanxiaoyao/bookstore/Controller.kt b/src/main/kotlin/com/lanyuanxiaoyao/bookstore/Controller.kt index 6d71efe..1ab6587 100644 --- a/src/main/kotlin/com/lanyuanxiaoyao/bookstore/Controller.kt +++ b/src/main/kotlin/com/lanyuanxiaoyao/bookstore/Controller.kt @@ -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( @@ -12,6 +13,12 @@ data class PageResponse( val total: Long, ) +data class SingleResponse( + val data: Map, +) { + 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 { + return SingleResponse( + lineRepository + .findAll({ root, _, builder -> + builder.equal(root.get("chapter").get("chapterId"), chapterId) + }, Sort.by(Sort.Direction.DESC, "sequence")) + .joinToString("\n") { "

${it.text}

" } + ) + } + @Transactional @GetMapping("remove/{chapterId}") fun remove(@PathVariable("chapterId") chapterId: String) { diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index 0de89c7..5e780e4 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -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: '导入',