package com.ruoyi.web.app;


import com.github.pagehelper.PageHelper;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.notice.domain.NoticeQuery;
import com.ruoyi.system.notice.domain.enums.NoticeStatus;
import com.ruoyi.system.notice.service.NoticeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/app/notice")
public class AppNoticeController extends BaseController {

    @Autowired
    private NoticeService noticeService;

    @ApiOperation("获取最新的公告")
    @GetMapping("/new")
    @Anonymous
    public AjaxResult getNewNotice(NoticeQuery query) {
        PageHelper.orderBy("create_time desc");
        query.setStatus(NoticeStatus.ENABLED.getStatus());
        return success(noticeService.selectOne(query));
    }

    @ApiOperation("获取公告详情")
    @GetMapping("/{noticeId}")
    @Anonymous
    public AjaxResult getNotice(@PathVariable Long noticeId) {
        return success(noticeService.selectNoticeById(noticeId));
    }

}
