diff --git a/luoo_common/src/main/java/dto/UserMessageDto.java b/luoo_common/src/main/java/dto/UserMessageDto.java index c724718..2f2fea0 100644 --- a/luoo_common/src/main/java/dto/UserMessageDto.java +++ b/luoo_common/src/main/java/dto/UserMessageDto.java @@ -25,7 +25,7 @@ public class UserMessageDto implements Serializable { private String userId; /** - * 消息类型 1新评论 ,2新赞,3新关注, 4私信 5.系统消息 + * 消息类型 1私信 ,2新赞,3新关注, 4新评论 5.系统消息 */ private Integer type; diff --git a/luoo_user/src/main/java/com/luoo/user/controller/FriendController.java b/luoo_user/src/main/java/com/luoo/user/controller/FriendController.java index 6a167af..eb40df6 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/FriendController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/FriendController.java @@ -11,6 +11,8 @@ import controller.BaseController; import dto.UserLoginDto; import dto.UserMessageDto; import io.jsonwebtoken.Claims; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -19,6 +21,7 @@ import javax.servlet.http.HttpServletRequest; @RestController @RequestMapping("/friend") +@Api(tags = "FriendController") public class FriendController extends BaseController { @Autowired @@ -39,12 +42,12 @@ public class FriendController extends BaseController { * * @return */ + @ApiOperation(value = "关注好友",notes = "friendid为关注好友的ID,type为1时是关注操作,type为2时是接黑名单操作,不是取关操作") @PutMapping("/like/{friendid}/{type}") - public Result addFriend(@PathVariable String friendid, @PathVariable String type) { + public Result addFriend(@PathVariable String friendid, @PathVariable String type,@RequestHeader(value = "Authorization", required = true) String authorization) { //验证是否登录,并且拿到ID - String token = (String) request.getAttribute("claims_user"); - UserLoginDto userLoginDto = getUserLoginDto("Bearer "+token); + UserLoginDto userLoginDto = getUserLoginDto(authorization); if (null == userLoginDto) { return Result.unauthorized(null); } @@ -93,12 +96,12 @@ public class FriendController extends BaseController { } + @ApiOperation(value = "取消关注好友") @DeleteMapping("/{friendid}") - public Result deleteFriend(@PathVariable String friendid){ + public Result deleteFriend(@PathVariable String friendid,@RequestHeader(value = "Authorization", required = true) String authorization){ //验证是否登录,并且拿到ID - String token = (String) request.getAttribute("claims_user"); - UserLoginDto userLoginDto = getUserLoginDto(token); + UserLoginDto userLoginDto = getUserLoginDto(authorization); if (null == userLoginDto) { return Result.unauthorized(null); } diff --git a/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java b/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java index 6cf7a4c..8bbbe66 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java @@ -5,7 +5,11 @@ import api.PageResult; import api.Result; import com.luoo.user.pojo.UserMessage; import com.luoo.user.service.UserMessageService; +import controller.BaseController; +import dto.UserLoginDto; import dto.UserMessageDto; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.*; @@ -14,7 +18,8 @@ import java.util.List; @RestController @RequestMapping("/userMessage") -public class UserMessageController { +@Api(tags = "UserMessageController") +public class UserMessageController extends BaseController { @Autowired private UserMessageService userMessageService; @@ -26,32 +31,38 @@ public class UserMessageController { * @return */ + @ApiOperation(value = "发送私信消息") @PostMapping("/sendUserMessage") public Result sendUserMessage(@RequestBody UserMessageDto userMessageDto) { + userMessageDto.setType(1); userMessageService.sendUserMessage(userMessageDto); return Result.success(); } - /**测试时用的,获取当前登录用户ID请走TOKEN - * 根据登录的用户ID获取消息 - * @return - */ - @GetMapping("/list/{userId}/{page}/{size}") - public Result list(@PathVariable String userId,@PathVariable int page,@PathVariable int size){ + @ApiOperation(value = "获取消息分页列表") + @GetMapping("/list/{page}/{size}") + public Result list(@PathVariable int page,@PathVariable int size,@RequestHeader(value = "Authorization", required = true) String authorization){ // List list = userMessageService.findByUserId(userId); - + //验证是否登录,并且拿到ID + UserLoginDto userLoginDto = getUserLoginDto(authorization); + if (null == userLoginDto) { + return Result.unauthorized(null); + } + String userId = userLoginDto.getUserId(); Page pageList = userMessageService.findSearch(userId,page,size); return Result.success(new PageResult(pageList.getTotalElements(),pageList.getContent())); } + @ApiOperation(value = "更新消息状态为已读") @PutMapping("/haveRead/{messageId}") public Result haveRead(@PathVariable String messageId) { userMessageService.haveRead(messageId); return Result.success(); } + @ApiOperation(value = "批量操作更新消息状态为已读") @PutMapping("/batchHaveRead") public Result haveRead(@RequestBody List userMessageList) { userMessageService.batchHaveRead(userMessageList); diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java b/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java index c4b1ea7..78375f4 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/UserMessage.java @@ -28,7 +28,7 @@ public class UserMessage implements Serializable { /** - * 消息类型 1新评论 ,2新赞,3新关注, 4私信 5.系统消息 + * 消息类型 消息类型 1私信 ,2新赞,3新关注, 4新评论 5.系统消息 */ private Integer type;