|
|
|
@ -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<UserMessage> pageList = userMessageService.findSearch(userId,page,size);
|
|
|
|
|
return Result.success(new PageResult<UserMessage>(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<UserMessage> userMessageList) {
|
|
|
|
|
userMessageService.batchHaveRead(userMessageList);
|
|
|
|
|