package com.bawei.mall.search.controller;

import com.bawei.common.core.domain.R;
import com.bawei.mall.product.cache.ProductInfoCache;
import com.bawei.mall.product.domain.reponse.ProductDetailsResponse;
import com.bawei.mall.search.es.config.EsConfig;
import com.bawei.mall.search.sync.ShopItemSync;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * @author DongZl
 * @description: 测试
 * @Date 2022-10-14 上午 11:17
 */
@Controller
@RequestMapping("/test")
public class TestController {

    @Autowired
    private ShopItemSync sync;

    @Autowired
    private ProductInfoCache productInfoCache;

    @GetMapping
    @ResponseBody
    private R test(){
        sync.productSync();
        return R.ok();
    }
    @GetMapping("/{id}")
    @ResponseBody
    private R get(@PathVariable Long id){
        ProductDetailsResponse productDetailsResponse = productInfoCache.get(id);
        return R.ok(productDetailsResponse);
    }
    @GetMapping("/refreshData/{id}")
    @ResponseBody
    private R refreshData(@PathVariable Long id){
        return R.ok(productInfoCache.refreshData(id));
    }

    @GetMapping("/index")
    public String index(Model model){
        model.addAttribute("test","你好");
        return "index";
    }
}
