package com.yami.shop.api.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.shop.bean.model.Keyword;
import com.yami.shop.service.IKeywordService;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

/**
 * @author wy
 */
@Controller
@RequestMapping("/keyword")
public class KeywordController {

    @Resource
    private IKeywordService keywordService;

    @ApiOperation("获取关键词类型下关键词")
    @GetMapping("/list")
    public ResponseEntity<List<Keyword>> list(@RequestParam(value = "type", required = false) Integer type) {
        LocalDateTime now = LocalDateTime.now();
        List<Keyword> list = keywordService.list(new LambdaQueryWrapper<Keyword>()
                .eq(Objects.nonNull(type), Keyword::getType, type)
                .ge(Keyword::getDeadTime, now));
        return ResponseEntity.ok(list);
    }

}
