package kr.wisestone.owl.web.controller;
|
|
import kr.wisestone.owl.constant.Constants;
|
import kr.wisestone.owl.domain.ApiToken;
|
import kr.wisestone.owl.service.ApiTokenService;
|
import kr.wisestone.owl.util.ConvertUtil;
|
import kr.wisestone.owl.vo.ApiTokenVo;
|
import kr.wisestone.owl.web.condition.ApiTokenCondition;
|
import kr.wisestone.owl.web.controller.BaseController;
|
import kr.wisestone.owl.web.form.ApiTokenForm;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.domain.Pageable;
|
import org.springframework.http.MediaType;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
@Controller
|
public class ApiTokenController extends BaseController {
|
|
@Autowired
|
private ApiTokenService apiTokenService;
|
|
// 토큰 생성
|
@RequestMapping(value = "/apiToken/add", produces = MediaType.APPLICATION_JSON_VALUE)
|
public
|
@ResponseBody
|
Map<String, Object> add(@RequestBody Map<String, Map<String, Object>> params) {
|
Map<String, Object> resJsonData = new HashMap<>();
|
|
ApiTokenForm form = ConvertUtil.convertMapToClass(params.get(Constants.REQ_KEY_CONTENT), ApiTokenForm.class);
|
|
ApiToken apiToken = apiTokenService.add(form);
|
resJsonData.put(Constants.RES_KEY_CONTENTS, ConvertUtil.copyProperties(apiToken, ApiTokenVo.class));
|
|
return this.setSuccessMessage(resJsonData);
|
}
|
|
// 토큰 조회
|
@RequestMapping(value = "/apiToken/find", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
public
|
@ResponseBody
|
Map<String, Object> find(@RequestBody Map<String, Map<String, Object>> params) {
|
Map<String, Object> resJsonData = new HashMap<>();
|
Pageable pageable = this.pageUtil.convertPageable(this.getPageVo(params));
|
|
ApiTokenVo token = this.apiTokenService.find();
|
resJsonData.put(Constants.RES_KEY_CONTENTS, token);
|
|
return this.setSuccessMessage(resJsonData);
|
}
|
|
// 토큰 삭제
|
@RequestMapping(value = "/apiToken/remove", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
public
|
@ResponseBody
|
Map<String, Object> remove(@RequestBody Map<String, Map<String, Object>> params) {
|
Map<String, Object> resJsonData = new HashMap<>();
|
|
ApiTokenForm apiTokenForm = ConvertUtil.convertMapToClass(params.get(Constants.REQ_KEY_CONTENT), ApiTokenForm.class);
|
this.apiTokenService.remove(apiTokenForm);
|
|
return this.setSuccessMessage(resJsonData);
|
}
|
}
|