记得加注释,传值太多记得封装
Showing
... | ... | @@ -6,11 +6,13 @@ import cn.meteor.beyondclouds.core.api.Response; |
import cn.meteor.beyondclouds.core.bean.Subject; | ||
import cn.meteor.beyondclouds.modules.user.entity.User; | ||
import cn.meteor.beyondclouds.modules.user.exception.UserServiceException; | ||
import cn.meteor.beyondclouds.modules.user.form.UserBaseinfoFrom; | ||
import cn.meteor.beyondclouds.modules.user.form.UserBaseInfoFrom; | ||
import cn.meteor.beyondclouds.modules.user.form.UserRegisterFrom; | ||
import cn.meteor.beyondclouds.modules.user.service.IUserService; | ||
import cn.meteor.beyondclouds.modules.user.vo.UserInfoVO; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import org.springframework.beans.BeanUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.web.bind.annotation.*; | ||
... | ... | @@ -53,14 +55,19 @@ public class UserApi { |
@ApiOperation("修改我的基本信息") | ||
@PutMapping("/my/baseinfo") | ||
public Response alterBaseinfo(@RequestBody @Valid UserBaseinfoFrom userBaseinfoFrom, BindingResult result, | ||
public Response alterBaseInfo(@RequestBody @Valid UserBaseInfoFrom userBaseinfoFrom, BindingResult result, | ||
@CurrentSubject Subject subject){ | ||
if (result.hasErrors()) { | ||
return Response.fieldError(result.getFieldError()); | ||
} | ||
userService.alterBaseinfo(userBaseinfoFrom.getNickName(),userBaseinfoFrom.getUserAvatar(), | ||
userBaseinfoFrom.getGender(),userBaseinfoFrom.getMobile(),userBaseinfoFrom.getSignature(), | ||
userBaseinfoFrom.getQqNumber(),userBaseinfoFrom.getWxNumber(), String.valueOf(subject.getId())); | ||
// 将form转换为user对象 | ||
User user = new User(); | ||
BeanUtils.copyProperties(userBaseinfoFrom, user); | ||
// 修改基本信息 | ||
user.setUserId(user.getUserId()); | ||
Please
register
or
sign in
to reply
|
||
userService.alterBaseInfo(user); | ||
return Response.success(); | ||
} | ||
... | ... | @@ -84,18 +91,35 @@ public class UserApi { |
@ApiOperation(("获取我的基本信息")) | ||
@GetMapping("/my/baseinfo") | ||
public Response myBaseinfo(@CurrentSubject Subject subject){ | ||
return Response.success(userService.myBaseinfo(String.valueOf(subject.getId()))); | ||
public Response myBaseInfo(@CurrentSubject Subject subject){ | ||
// 获取用户信息 | ||
User user = userService.getById(subject.getId()); | ||
UserInfoVO userInfoVO = new UserInfoVO(); | ||
BeanUtils.copyProperties(user, userInfoVO); | ||
// 返回结果 | ||
return Response.success(userInfoVO); | ||
} | ||
@Anonymous | ||
@ApiOperation(("获取他人基本信息")) | ||
@GetMapping("/user/{userId}/baseinfo") | ||
public Response otherBaseinfo(@PathVariable(name = "userId") String userId ){ | ||
return Response.success(userService.otherBaseinfo(userId)); | ||
public Response<UserInfoVO> updateOtherBaseInfo(@PathVariable(name = "userId") String userId ){ | ||
} | ||
// 获取用户信息 | ||
User user = userService.getById(userId); | ||
UserInfoVO userInfoVO = new UserInfoVO(); | ||
BeanUtils.copyProperties(user, userInfoVO); | ||
// 去掉敏感信息 | ||
userInfoVO.setMobile(null); | ||
userInfoVO.setWxNumber(null); | ||
userInfoVO.setQqNumber(null); | ||
// 返回结果 | ||
return Response.success(userInfoVO); | ||
} | ||
} |