package com.contract.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.contract.entity.CurrencyCoin;
import com.contract.entity.resp.MessageResult;
import com.contract.service.CurrencyCoinService;
import com.contract.util.RequestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
@RequestMapping("/currency")
public class CurrencyCoinController {

    @Autowired
    private CurrencyCoinService currencyCoinService;

    @GetMapping("/rate")
    public MessageResult rate(HttpServletRequest request) {
        String lang = RequestUtils.getLangFromHeader(request);
        List<CurrencyCoin> coin = currencyCoinService.list(new LambdaQueryWrapper<>());
        return MessageResult.successLang(lang, coin);
    }
}
