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.OrgDepartmentApi;
import org.qinan.safetyeval.client.co.OrgDepartmentCO;
import org.qinan.safetyeval.client.dto.OrgDepartmentAddCmd;
import org.qinan.safetyeval.client.dto.OrgDepartmentModifyCmd;
import org.qinan.safetyeval.client.dto.OrgDepartmentPageQuery;
import org.qinan.safetyeval.infrastructure.adapter.auth.AuthUserContextAdapter;
import org.qinan.safetyeval.infrastructure.adapter.auth.AuthUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
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-department")
public class OrgDepartmentController {


    @Resource
    private OrgDepartmentApi orgDepartmentApi;

    @ApiOperation("新增部门")
    @PostMapping("/save")
    public SingleResponse<OrgDepartmentCO> add(@Validated @RequestBody OrgDepartmentAddCmd cmd) {
        return orgDepartmentApi.add(cmd);
    }

    @ApiOperation("查询部门详情")
    @GetMapping("/get")
    public SingleResponse<OrgDepartmentCO> get(@ApiParam("主键ID") @RequestParam Long id) {
        return orgDepartmentApi.get(id);
    }

    @ApiOperation("修改部门")
    @PostMapping("/modify")
    public SingleResponse<OrgDepartmentCO> modify(@Validated @RequestBody OrgDepartmentModifyCmd cmd) {
        return orgDepartmentApi.modify(cmd);
    }

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

    @ApiOperation("分页查询部门")
    @GetMapping("/page")
    public PageResponse<OrgDepartmentCO> page(@Validated OrgDepartmentPageQuery query) {
        return orgDepartmentApi.page(query);
    }
}
