OWL ITS + 탐지시스템(인터넷 진흥원)
wyu
2022-01-06 306f6173e4dc458074f74ceeddbfbc0d52765401
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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;
 
/**
 * API 토큰 컨트롤러 클래스
 */
@Controller
public class ApiTokenController extends BaseController {
 
    @Autowired
    private ApiTokenService apiTokenService;
 
    /**
     * 토큰 생성
     * @param params 토큰 생성에 필요한 파라미터
     * @return 생성 결과 Map<String, Object>
     */
    @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);
    }
 
 
    /**
     * 토큰 조회
     * @param params 토큰 조회에 필요한 파라미터 
     * @return 조회 결과, Map<String, ApiTokenVo>
     */
    //  토큰 조회
    @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);
    }
 
    /**
     * 토큰 삭제
     * @param params 토큰 삭제에 필요한 파라미터
     * @return 삭제 결과, Map<String, Object>
     */
    //  토큰 삭제
    @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);
    }
}