package org.qinan.safetyeval.adapter.web;

import io.swagger.annotations.Api;
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.*;
import org.qinan.safetyeval.infrastructure.dataobject.base.Req;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 部门适配层（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 String id) {
        return orgDepartmentApi.get(Long.parseLong(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") @RequestBody Req<Long> req) {
        return orgDepartmentApi.delete(req.getData());
    }

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

    @ApiOperation("部门树列表")
    @GetMapping("/tree")
    public SingleResponse<List<OrgDepartmentCO>> tree(@Validated OrgDepartmentPageQuery query) {
        return orgDepartmentApi.tree(query);
    }
}
