package com.xiaoniu.system.platformsettings.notice.controller;

import com.xiaoniu.common.core.resdata.Result;
import com.xiaoniu.common.core.resdata.RowsData;
import com.xiaoniu.system.platformsettings.notice.dto.AddNoticeDTO;
import com.xiaoniu.system.platformsettings.notice.dto.EditNoticeDTO;
import com.xiaoniu.system.platformsettings.notice.dto.NoticeListQueryDTO;
import com.xiaoniu.system.platformsettings.notice.service.ITbNoticeService;
import com.xiaoniu.system.platformsettings.notice.vo.NoticeDetailsVO;
import com.xiaoniu.system.platformsettings.notice.vo.NoticeListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 活动公告 前端控制器
 * </p>
 *
 * @author haoxuyang
 * @since 2024-10-11 11:30:35
 */
@Tag(name = "通知公告管理")
@RestController
@RequestMapping("/notice")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TbNoticeController {

    private final ITbNoticeService tbNoticeService;

    @Operation(summary = "通知公告列表")
    @PostMapping("/list")
    public Result<RowsData<NoticeListVO>> list(@RequestBody NoticeListQueryDTO dto) {
        return Result.success("查询成功", tbNoticeService.noticeList(dto));
    }

    @Operation(summary = "新增通知公告")
    @PostMapping("/add")
    public Result<String> add(@RequestBody @Validated AddNoticeDTO dto) {
        tbNoticeService.addNotice(dto);
        return Result.success("操作成功");
    }

    @Operation(summary = "修改通知公告")
    @PostMapping("/edit")
    public Result<String> edit(@RequestBody @Validated EditNoticeDTO dto) {
        tbNoticeService.editNotice(dto);
        return Result.success("操作成功");
    }

    @Operation(summary = "修改通知公告状态")
    @GetMapping("/changeState")
    public Result<String> changeState(@RequestParam Long id) {
        tbNoticeService.changeState(id);
        return Result.success("操作成功");
    }

    @Operation(summary = "通知公告详情")
    @GetMapping("/details")
    public Result<NoticeDetailsVO> details(@RequestParam Long id) {
        return Result.success("查询成功", tbNoticeService.details(id));
    }

    @Operation(summary = "删除通知公告")
    @GetMapping("/del")
    public Result<String> delNotice(@RequestParam Long id) {
        tbNoticeService.delNotice(id);
        return Result.success("操作成功");
    }

}
