package com.ningdatech.carapi.safe.controller;

import com.ningdatech.basic.model.IdVo;
import com.ningdatech.basic.model.PageVo;
import com.ningdatech.carapi.common.util.CodeUtil;
import com.ningdatech.carapi.safe.entity.NdSecurityNoticeSaveReq;
import com.ningdatech.carapi.safe.manage.SecurityAdvisoryManage;
import com.ningdatech.carapi.safe.model.dto.SecurityAdvisoryPageQuery;
import com.ningdatech.carapi.safe.model.vo.NdSecurityAdvisoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

/**
 * @Classname SecurityAdvisoryController
 * @Description
 * @Date 2022/10/19 16:03
 * @Created by PoffyZhang
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/api/safe/security-advisory")
@Api(value = "SecurityAdvisory", tags = "安全管理-安全通报")
@RequiredArgsConstructor
public class SecurityAdvisoryController {
    private final SecurityAdvisoryManage securityAdvisoryManage;

    @ApiOperation(value = "安全通报", notes = "安全通报")
    @GetMapping("/list")
    public PageVo<NdSecurityAdvisoryVO> queryList(@Valid @ModelAttribute SecurityAdvisoryPageQuery securityAdvisoryPageQuery) {
        CodeUtil.convertRegionCodeToId(securityAdvisoryPageQuery);
        return securityAdvisoryManage.buildWrapper(securityAdvisoryPageQuery);
    }

    @ApiOperation("新增安全通报")
    @PostMapping("/add")
    public void save(@RequestBody NdSecurityNoticeSaveReq req){
        securityAdvisoryManage.saveSecurityNotice(req);
    }

    @ApiOperation("删除安全通报")
    @DeleteMapping("/delete")
    public void delete(@RequestBody IdVo<Long> id){
        securityAdvisoryManage.deleteSecurityNotice(id.getId());
    }

    @ApiOperation("增加下载次数")
    @GetMapping("/incrementDownCount/{id}")
    public void incrementDownCount(@PathVariable Long id) {
        securityAdvisoryManage.incrementDownCount(id);
    }
}
