package com.quinn.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quinn.pojo.About;
import com.quinn.service.AboutService;
import com.quinn.utils.QuinnUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author limqsh
 * @since 2022-05-01
 */
@Controller
public class AboutController extends BaseModelController {

    @Resource
    AboutService aboutService;

    @GetMapping("/about")
    public String userIndexBlog(HttpServletRequest request,Model model){
        Page<About> pageParam = new Page<>(1, 20);
        aboutService.page(pageParam,new QueryWrapper<About>().orderByDesc("gmt_create"));
        // 结果
        List<About> sayList = pageParam.getRecords();
        model.addAttribute("aboutList",sayList);
        model.addAttribute("pageParam",pageParam);

        return "page/about";
    }

    @PostMapping("/about/append")
    @PreAuthorize("hasAuthority('ADMIN')")
    public String saveSay(About about){
        about.setId(QuinnUtils.getUuid());
        about.setGmtCreate(QuinnUtils.getTime());
        // 结果
        aboutService.save(about);
        return "redirect:/about";
    }

}

