package com.ruoyi.novel.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

// ChapterController.java
@RestController
@RequestMapping("/chapter")
public class ChapterController {

    @Autowired
    private ChapterService chapterService;

    @GetMapping("/{novelId}")
    public AjaxResult getChapters(@PathVariable Long novelId) {
        List<NovelChapter> chapters = chapterService.selectChapterListByNovelId(novelId);
        return AjaxResult.success(chapters);
    }

    @PostMapping("/save")
    public AjaxResult saveChapter(@RequestBody ChapterDTO dto) {
        return toAjax(chapterService.saveChapter(dto.getChapter(), dto.getContent()));
    }
}