package ink.wgink.common.base;

import freemarker.template.TemplateException;
import ink.wgink.common.service.api.IApiInfoService;
import ink.wgink.pojo.dtos.permission.SystemApiDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: IndexController
 * @Description: index
 * @Author: WangGeng
 * @Date: 2021/2/24 20:17
 * @Version: 1.0
 **/
@RestController
public class ApiInfoController {

    @Autowired
    private IApiInfoService apiInfoService;

    @GetMapping("system-api/{group}/{apiType}")
    @ResponseBody
    public SystemApiDTO getSystemApi(@PathVariable("group") String group, @PathVariable("apiType") String apiType, HttpServletRequest request) {
        return apiInfoService.getSystemApi(group, apiType, request);

    }

    @GetMapping("api-info/get-api")
    public Map<String, Object> getApi(@RequestParam(name = "apiTypes", required = false) List<String> apiTypes) {
        return apiInfoService.getApi(apiTypes);
    }

    @GetMapping("api-info/get")
    public void get(HttpServletRequest request, HttpServletResponse response) throws IOException, TemplateException {
        apiInfoService.get(request, response);
    }
}
