package net.northking.cctp.dw.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.dw.api.service.CpProjectDetailApiService;
import net.northking.cctp.dw.dto.CpProjectDetailAddDto;
import net.northking.cctp.dw.dto.CpProjectDetailQueryDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: puchao.ma
 * @date: 2022/1/4 10:55
 */
@RestController
@RequestMapping("/v1/cpProjectDetail")
@Api(tags = "系统详情")
public class CpProjectDetailCtrl {
    @Autowired
    private CpProjectDetailApiService apiService;

    /**
     * Restful接口-post： 新增系统详情界面信息
     *
     * @param inputDto         接口数据传输对象
     * @return 数据库主键
     */
    @ApiOperation(value = "新增：系统详情界面信息")
    @PostMapping(
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<Void> add(
            @RequestBody @Validated CpProjectDetailAddDto inputDto)
    {
        ResultWrapper<Void> wrapper = new ResultWrapper<>();
        apiService.add(inputDto);
        return wrapper.success();
    }

    /**
     *  获取系统详情界面信息
     *
     * @param projectId      系统id
     * @return 接口数据传输对象
     */
    @ApiOperation(value = "获取：系统详情界面信息")
    @GetMapping(
            value = "/{projectId}",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<List<CpProjectDetailQueryDto>> findByProjectId(
            @PathVariable("projectId") String projectId)
    {
        ResultWrapper<List<CpProjectDetailQueryDto>> wrapper = new ResultWrapper<>();
        List<CpProjectDetailQueryDto> user = apiService.findByProjectId(projectId);
        return wrapper.success(user);
    }
}
