package com.sqx.modules.app.controller.app;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.sqx.common.utils.Result;
import com.sqx.modules.announcement.entity.Announcement;
import com.sqx.modules.announcement.service.AnnouncementService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/app/announcement")
public class AppAnnouncementController {

    private final AnnouncementService announcementService;

    public AppAnnouncementController(AnnouncementService announcementService) {
        this.announcementService = announcementService;
    }

    @GetMapping
    public Result get() {
        PageHelper.startPage(1,1);
        List<Announcement> list = announcementService.list(new LambdaQueryWrapper<Announcement>()
                .eq(Announcement::getState, 1)
                .orderByDesc(Announcement::getCreateTime));
        return Result.success().put("data", list.isEmpty() ? null : list.get(0));
    }

}
