package jnpf.cultivate.controller.web.learn;


import jnpf.base.ActionResult;
import jnpf.cultivate.service.FtbCultivateLearnCategoriesService;
import jnpf.model.cultivate.dto.learn.FtbCultivateLearnCategoriesDto;
import jnpf.model.cultivate.po.learn.FtbCultivateLearnCategories;
import jnpf.model.cultivate.req.learn.AddLearnCategoryReq;
import jnpf.model.cultivate.req.learn.QueryLearnCategoryListReq;
import jnpf.model.cultivate.req.learn.UpdateLearnCategoryReq;
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/learn/Categories")
public class FtbCultivateLearnCategoriesController {

    @Autowired
    private FtbCultivateLearnCategoriesService cultivateLearnCategoriesService;


    /**
     * 查询分类接口
     *
     * @param req
     * @return
     */
    @GetMapping("/lists")
    public ActionResult<List<FtbCultivateLearnCategoriesDto>> lists(@Valid QueryLearnCategoryListReq req) {
        return ActionResult.success("成功", cultivateLearnCategoriesService.listCategory(req));
    }


    /**
     * 添加分类
     *
     * @param req
     * @return
     */
    @PostMapping("/add")
    public ActionResult<FtbCultivateLearnCategories> add(@RequestBody @Valid AddLearnCategoryReq req) {

        return ActionResult.success("添加成功", cultivateLearnCategoriesService.insertData(req));
    }

    /**
     * 修改分类
     *
     * @param id  分类ID
     * @param req
     * @return
     */
    @PutMapping("/update/{id}")
    public ActionResult<FtbCultivateLearnCategories> update(@PathVariable("id") String id, @RequestBody @Valid UpdateLearnCategoryReq req) {
        return ActionResult.success("编辑成功", cultivateLearnCategoriesService.updateData(id, req));
    }

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


}

