lowered code smells
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / controller / LanguageController.java
1 /**
2  * Copyright (C) 2019 CMCC, Inc. and others. All rights reserved.
3  *
4  *  Modification Copyright © 2020 IBM.
5  * ===================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 package org.onap.portalapp.portal.controller;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22 import org.onap.portalapp.portal.service.LanguageService;
23 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.web.bind.annotation.PathVariable;
25 import org.springframework.web.bind.annotation.RequestBody;
26 import org.springframework.web.bind.annotation.RequestMapping;
27 import org.springframework.web.bind.annotation.GetMapping;
28 import org.springframework.web.bind.annotation.PostMapping;
29 import org.springframework.web.bind.annotation.RestController;
30 import com.alibaba.fastjson.JSONObject;
31
32 @RestController
33 @RequestMapping("/auxapi")
34 public class LanguageController {
35
36     @Autowired
37     private LanguageService languageService;
38
39     @GetMapping(value = "/language", produces = "application/json;charset=UTF-8")
40     public JSONObject getLanguageList() {
41         return languageService.getLanguages();
42     }
43
44     @PostMapping(value = "/languageSetting/user/{loginId}")
45     public void setUpUserLanguage(@RequestBody JSONObject jsonLanguageId,
46                                   @PathVariable("loginId") String loginId) throws Exception {
47         Integer languageId = jsonLanguageId.getInteger("languageId");
48         languageService.setUpUserLanguage(languageId,loginId);
49     }
50
51     @GetMapping(value = "/languageSetting/user/{loginId}")
52     public JSONObject getUserLanguage(HttpServletRequest request, HttpServletResponse response,
53                                       @PathVariable("loginId") String loginId) {
54         return languageService.getUserLanguage(loginId);
55     }
56
57 }