package cn.ey.biz.module.system.controller.admin.wiki;

import cn.ey.biz.common.pojo.R;
import cn.ey.biz.module.system.controller.admin.wiki.vo.WikiPageAndContentRespVO;
import cn.ey.biz.module.system.controller.admin.wiki.vo.WikiPageRespVO;
import cn.ey.biz.module.system.controller.admin.wiki.vo.WikiSpacePageCreateReqVO;
import cn.ey.biz.module.system.service.wiki.WikiPageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import static cn.ey.biz.common.pojo.R.success;

@Api(tags = "管理后台 -page")
@RestController
@RequestMapping("/system/wiki/page")
@Validated
public class WikiPageController {

    @Resource
    private  WikiPageService wikiPageService;

    @GetMapping("/get-list")
    @ApiOperation("根据空间id获取目录")
    @PreAuthorize("@ss.hasPermission('system:wiki-space-page:query')")
    public R<List<WikiPageRespVO>> getPageList(@RequestParam("id") Long id) {
        List<WikiPageRespVO> wiPageList=wikiPageService.getPageList(id);
        return success(wiPageList);
    }

    @GetMapping("/get")
    @ApiOperation("根据目录Id获取详情及内容")
    @PreAuthorize("@ss.hasPermission('system:wiki-space-page:query')")
    public R<WikiPageAndContentRespVO> getPageContent(@RequestParam("id") Long id) {
        WikiPageAndContentRespVO pageContent=wikiPageService.getPageContent(id);
        return success(pageContent);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除目录")
    @PreAuthorize("@ss.hasPermission('system:wiki-space-page:delete')")
    public R<Boolean> deletePage(@RequestParam("id") Long id) {
        wikiPageService.deletePage(id);
        return success(true);
    }

    @PostMapping("/create")
    @ApiOperation("创建/编辑")
    @PreAuthorize("@ss.hasPermission('system:wiki-space-page:create')")
    public R<Long> createWikiSpacePage(@Valid @RequestBody WikiSpacePageCreateReqVO createReqVO) {
        Long pageId=wikiPageService.createWikiSpacePage(createReqVO);
        return success(pageId);
    }

}
