package nlib.sample.web;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import nlib.restful.service.DataApiReqVO;
import nlib.restful.service.DataApiResVO;
import nlib.sample.service.SampleDataApiService;

/**
 * <pre>
 * @Class Name : SampleDataApiController.java
 * 
 * @Description : RESTful API 호출 샘플
 * 
 * 
 * @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
 *
 * </pre>
 *
 * @ ------------    --------    ---------------------------
 * @ 수정일                     수정자             수정내용
 * @ ------------    --------    ---------------------------
 * @ 2021. 6. 22.    KNKIM       최초 생성
 *
 * 
 * @author 이씨플라자 * DIGITALSHIP KNKIM
 * @since 2021. 6. 22.
 * @version 1.0
 *
 */
@Controller
public class SampleDataApiController {
	
	/** SampleDataApiService */
	@Resource(name = "sampleDataApiService")
	private SampleDataApiService sampleDataApiService;
	

	/* DataApi 접속 서버 정보 */ 
	@Value("#{properties['dataapi.server.ip']}") 
	private String dataapiServerIp;
	
	@Value("#{properties['dataapi.server.port']}") 
	private String dataapiServerPort;
	
	@Value("#{properties['dataapi.server.protocol']}") 
	private String dataapiServerProtocol;
	
	
    @RequestMapping("/sample/getSampleInfoForm.do")
    public String getSampleInfoForm(ModelMap model) throws Exception {

		model.addAttribute("serverProtocol", dataapiServerIp);
		model.addAttribute("serverIp", dataapiServerPort);
		model.addAttribute("serverPort", dataapiServerProtocol);
		return "nlib/sample/getSampleInfoForm";
    }

    @RequestMapping("/sample/getSampleInfo.do")
    public String getSampleInfo(@RequestParam Map<String, Object> commandMap, ModelMap model) throws Exception {
		
    	String authKey = (String) commandMap.get("authKey");
    	String page = (String) commandMap.get("page");
    	String rows = (String) commandMap.get("rows");
    	
    	DataApiReqVO reqVO = new DataApiReqVO();
    	reqVO.setAuthKey(authKey);
    	reqVO.setPageIndex(page);
    	reqVO.setPageSize(rows);
    	
    	DataApiResVO resVO = sampleDataApiService.getSampleInfo(reqVO);
    	model.addAttribute("result", resVO);
    	
		return "nlib/sample/getSampleInfo";
    }

}
