package jnpf.notice.controller.web;


import jnpf.base.ActionResult;
import jnpf.model.notice.domain.FtbNoticeCategories;
import jnpf.model.notice.dto.FtbNoticeCategoriesDto;
import jnpf.model.notice.req.category.AddCategoryReq;
import jnpf.model.notice.req.category.QueryCategoryListReq;
import jnpf.model.notice.req.category.QueryNextCategoryListReq;
import jnpf.model.notice.req.category.UpdateCategoryReq;
import jnpf.notice.service.FtbNoticeCategoriesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * web公告分类模块
 *
 * @author xgl
 * @since 2024-05-08 09:51:36
 */
@RestController
@RequestMapping("/web/noticeCategories")
public class FtbNoticeCategoriesController {

    @Autowired
    private FtbNoticeCategoriesService ftbNoticeCategoriesService;


    /**
     * 查询公告分类接口
     *
     * @param req
     * @return
     */
    @GetMapping("/lists")
    public ActionResult<List<FtbNoticeCategoriesDto>> lists(QueryCategoryListReq req) {

        return ActionResult.success("成功", ftbNoticeCategoriesService.listCategory(req));
    }

    /**
     * 根据分类ID查询直接下级分类接口
     *
     * @param req
     * @return
     */
    @GetMapping("/nextCatelists")
    public ActionResult<List<FtbNoticeCategoriesDto>> nextCatelists(QueryNextCategoryListReq req) {
        return ActionResult.success("成功", ftbNoticeCategoriesService.nextCatelists(req));
    }


    /**
     * 添加公告分类
     *
     * @param req
     * @return
     */
    @PostMapping("/add")
    public ActionResult<FtbNoticeCategories> add(@RequestBody @Valid AddCategoryReq req) {
        return ActionResult.success("添加成功", ftbNoticeCategoriesService.insertData(req));
    }

    /**
     * 修改公告分类
     *
     * @param id  分类ID
     * @param req
     * @return
     */
    @PutMapping("/update/{id}")
    public ActionResult<FtbNoticeCategories> update(@PathVariable("id") String id, @RequestBody @Valid UpdateCategoryReq req) {


        return ActionResult.success("编辑成功",  ftbNoticeCategoriesService.updateData(id, req));
    }

    /**
     * 删除公告分类
     *
     * @param id 分类ID
     * @return
     */
    @DeleteMapping("/del/{id}")
    public ActionResult<Boolean> del(@PathVariable("id") String id) {
        ftbNoticeCategoriesService.deleteData(id);
        return ActionResult.success("删除成功", true);
    }


}

