package com.education.api.controller.admin.education;

import com.education.business.service.education.GoalInfoService;
import com.education.common.base.BaseController;
import com.education.common.utils.Result;
import com.education.common.utils.ResultCode;
import com.education.model.dto.GoalInfoDto;
import com.education.model.entity.ExtKnowledgePoint;
import com.education.model.entity.GoalInfo;
import com.education.model.request.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 导向目标管理
 */
@RequestMapping("/system/goalInfo")
@RestController
public class GoalInfoController extends BaseController {

    @Autowired
    private GoalInfoService goalInfoService;

    /**
     * 添加导向目标
     * @param goalInfo
     * @return
     */
    @PostMapping
    //@RequiresPermissions("system:goalInfo:save")
    public Result add(@RequestBody GoalInfoDto goalInfo) {
        Integer id = goalInfoService.add(goalInfo);
        return Result.success(id);
    }

    /**
     * 更新导向目标
     * @param goalInfo
     * @return
     */
    @PutMapping
    //@RequiresPermissions("system:goalInfo:update")
    public Result update(@RequestBody @Validated(GoalInfo.Update.class) GoalInfo goalInfo) {
        goalInfoService.saveOrUpdate(goalInfo);
        return Result.success();
    }

    /**
     * 删除导向目标
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    //@RequiresPermissions("system:goalInfo:delete")
    public Result delete(@PathVariable Integer id) {
        //todo check goal info's relation and status
        goalInfoService.removeById(id);
        return Result.success(ResultCode.SUCCESS, "删除成功");
    }

    /**
     * 查询导向目标列表
     * @param pageParam
     * @param goalInfo
     * @return
     */
    @GetMapping
    //@RequiresPermissions("system:extKnowledgePoint:list")
    public Result selectPage(PageParam pageParam, GoalInfo goalInfo) {
        return Result.success(goalInfoService.selectPageList(pageParam, goalInfo));
    }
}