package org.qinan.safetyeval.adapter.web;

import io.swagger.annotations.Api;
import org.qinan.safetyeval.client.dto.PageResponse;
import org.qinan.safetyeval.client.dto.SingleResponse;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.qinan.safetyeval.client.api.OrgPositionApi;
import org.qinan.safetyeval.client.co.OrgPositionCO;
import org.qinan.safetyeval.client.dto.OrgPositionAddCmd;
import org.qinan.safetyeval.client.dto.OrgPositionModifyCmd;
import org.qinan.safetyeval.client.dto.OrgPositionPageQuery;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 岗位适配层（Controller）
 *
 * @author safety-eval
 */
@Api(tags = "岗位管理")
@RestController
@RequestMapping("/safetyEval/org-position")
public class OrgPositionController {

    @Resource
    private OrgPositionApi orgPositionApi;

    @ApiOperation("新增岗位")
    @PostMapping("/save")
    public SingleResponse<OrgPositionCO> add(@Validated @RequestBody OrgPositionAddCmd cmd) {
        return orgPositionApi.add(cmd);
    }

    @ApiOperation("查询岗位详情")
    @GetMapping("/get")
    public SingleResponse<OrgPositionCO> get(@ApiParam("主键ID") @RequestParam Long id) {
        return orgPositionApi.get(id);
    }

    @ApiOperation("修改岗位")
    @PostMapping("/modify")
    public SingleResponse<OrgPositionCO> modify(@Validated @RequestBody OrgPositionModifyCmd cmd) {
        return orgPositionApi.modify(cmd);
    }

    @ApiOperation("删除岗位")
    @PostMapping("/delete")
    public SingleResponse<Void> delete(@ApiParam("主键ID") @RequestParam Long id) {
        return orgPositionApi.delete(id);
    }

    @ApiOperation("分页查询岗位")
    @GetMapping("/page")
    public PageResponse<OrgPositionCO> page(@Validated OrgPositionPageQuery query) {
        return orgPositionApi.page(query);
    }
}
