UserInfoController.java 2.21 KB
package com.xkl.controller;

import com.xkl.authorization.annotation.Authorization;
import com.xkl.authorization.annotation.CurrentUser;
import com.xkl.domain.User;
import com.xkl.model.ResultModel;
import com.xkl.repository.UserRepository;
import com.xkl.security.AntiXSS;
import com.wordnik.swagger.annotations.ApiImplicitParam;
import com.wordnik.swagger.annotations.ApiImplicitParams;
import com.wordnik.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by win7 on 2016/10/19.
 */
@RestController
@RequestMapping("/userInfo")
public class UserInfoController {
    @Autowired
    private UserRepository userRepository;

    @RequestMapping(method = RequestMethod.GET)
    @Authorization
    @ApiOperation(value = "获取用户昵称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
    })
    public ResponseEntity<ResultModel> getUserNickName(@CurrentUser User user) {
        String dickName=user.getNickname();
        return new ResponseEntity<>(ResultModel.ok(dickName), HttpStatus.OK);
    }

    @RequestMapping(method = RequestMethod.PUT)
    @Authorization
    @AntiXSS
    @ApiOperation(value = "修改用户昵称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "authorization", value = "请输入登录返回信息:userId_tokens", required = true, dataType = "string", paramType = "header"),
    })
    public ResponseEntity<ResultModel> modUserNickName(@CurrentUser User user,@RequestParam String userNickName) {
        Assert.notNull(userNickName, "userDickName can not be empty");
        user.setNickname(userNickName);
        userRepository.save(user);
        return new ResponseEntity<>(ResultModel.ok(), HttpStatus.OK);
    }
}