package com.contract.controller;

import com.contract.entity.NodeInfo;
import com.contract.entity.resp.MessageResult;
import com.contract.service.NodeInfoService;
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("/node")
public class NodeInfoController {

    @Autowired
    private NodeInfoService nodeInfoService;

    @GetMapping("/list")
    public MessageResult list(HttpServletRequest request) {
        String lang = RequestUtils.getLangFromHeader(request);
        List<NodeInfo> list = nodeInfoService.listEnabled();
        return MessageResult.successLang(lang, list);
    }
}
