package com.jwipc.sys.controller.pc;

import com.jwipc.page.PageView;
import com.jwipc.sys.dto.MsgNoticeDTO;
import com.jwipc.sys.logic.NoticeLogic;
import com.jwipc.sys.model.query.MsgNoticeQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.jwipc.sys.constant.ModuleConst.MODULE_ROOT;

/**
 * @author shenyang.ou
 * @date 2024/1/31 15:14
 * @desc 公告
 */
@RestController
@RequestMapping(MODULE_ROOT + "/notice/rest")
@RequiredArgsConstructor
public class NoticeRestController {
    private final NoticeLogic noticeLogic;
    /**
     * 列表
     * @param query
     * @return
     */
    @RequestMapping("/list")
    public PageView list(MsgNoticeQuery query) {
        return noticeLogic.findByPage(query);
    }

    /**
     * 保存更新
     *
     * @param param 参数
     */
    @PostMapping("/saveOrUpdate")
    public ResponseEntity saveOrUpdate(MsgNoticeDTO param) {
        noticeLogic.saveOrUpdate(param);
        return ResponseEntity.ok(true);
    }

    /**
     * 发布
     *
     * @param id 参数
     */
    @PostMapping("/publish")
    public ResponseEntity publish(Long id) {
        noticeLogic.publish(id);
        return ResponseEntity.ok(true);
    }

    /**
     * 删除
     *
     * @param id 参数
     */
    @PostMapping("/remove")
    public ResponseEntity remove(Long id) {
        noticeLogic.remove(id);
        return ResponseEntity.ok(true);
    }
}
