package cn.van.business.controller.jd;

import cn.van.business.model.ApiResponse;
import cn.van.business.model.jd.ProductOrder;
import cn.van.business.mq.MessageProducerService;
import cn.van.business.repository.ProductOrderRepository;
import cn.van.business.util.JDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author Leo
 * @version 1.0
 * @create 2024/11/7 13:39
 * @description：
 */
@RestController
@RequestMapping("/recordOrder")
public class OrderController {

    public static String TOKEN = "cc0313";
    @Autowired
    private JDUtil jdUtils;
    @Autowired
    private MessageProducerService messageProducerService;
    @Autowired
    private ProductOrderRepository productOrderRepository;

    public boolean checkToken(String token) {
        return TOKEN.equals(token);
    }

    @RequestMapping("/list")
    @ResponseBody
    public ApiResponse<List<ProductOrder>> list(String token) throws Exception {
        try {
            List<ProductOrder> all = productOrderRepository.findAll();
            return ApiResponse.success(all);
        } catch (Exception e) {
            return (ApiResponse<List<ProductOrder>>) ApiResponse.error(500, "Server Error: " + e.getMessage());
        }
    }

}
