package com.cslg.ppa.controller;

import com.cslg.ppa.common.core.auth.Response;
import com.cslg.ppa.common.core.base.Constants;
import com.cslg.ppa.dto.ArticleInfoIdDTO;
import com.cslg.ppa.dto.SelectArticleInfoDTO;
import com.cslg.ppa.dto.UpdateArticleInfoDTO;
import com.cslg.ppa.service.ArticleInfoService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping(Constants.API_PPA + "/articleInfo")
@RestController
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class ArticleInfoController {

    @Autowired
    private ArticleInfoService articleInfoService;

    @Operation(summary = "查询资讯列表")
    @PostMapping("/selectArticleInfoList")
    public String selectArticleInfoList(@RequestBody SelectArticleInfoDTO vo) {
        return articleInfoService.selectArticleInfoList(vo);
    }

    @Operation(summary = "编辑资讯信息")
    @PostMapping("/updateArticleInfo")
    public String updateArticleInfo(@RequestBody UpdateArticleInfoDTO infoDTO) {
        final Integer id = articleInfoService.updateArticleInfo(infoDTO);
        return Response.success(id);
    }

    @Operation(summary = "删除资讯信息")
    @PostMapping("/deleteArticleInfo")
    public String deleteArticleInfo(@RequestBody ArticleInfoIdDTO vo) {
        articleInfoService.deleteArticleInfo(vo);
        return Response.success("删除成功");
    }
}
