mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-14 06:03:42 +08:00
增加参数校验
This commit is contained in:
@@ -5,7 +5,8 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -19,6 +20,8 @@ import java.util.List;
|
||||
@NoArgsConstructor
|
||||
public class TextMsgReq {
|
||||
|
||||
@NotBlank(message = "内容不能为空")
|
||||
@Size(max = 5,message = "消息内容过长,服务器扛不住啊,兄dei")
|
||||
@ApiModelProperty("消息内容")
|
||||
private String content;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.abin.mallchat.common.chat.domain.entity.Message;
|
||||
import com.abin.mallchat.common.chat.domain.entity.msg.FileMsgDTO;
|
||||
import com.abin.mallchat.common.chat.domain.entity.msg.MessageExtra;
|
||||
import com.abin.mallchat.common.chat.domain.enums.MessageTypeEnum;
|
||||
import com.abin.mallchat.common.common.utils.AssertUtil;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageReq;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -29,6 +30,8 @@ public class FileMsgHandler extends AbstractMsgHandler {
|
||||
|
||||
@Override
|
||||
public void checkMsg(ChatMessageReq request, Long uid) {
|
||||
FileMsgDTO body = BeanUtil.toBean(request.getBody(), FileMsgDTO.class);
|
||||
AssertUtil.allCheckValidateThrow(body);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.abin.mallchat.common.chat.domain.entity.Message;
|
||||
import com.abin.mallchat.common.chat.domain.entity.msg.ImgMsgDTO;
|
||||
import com.abin.mallchat.common.chat.domain.entity.msg.MessageExtra;
|
||||
import com.abin.mallchat.common.chat.domain.enums.MessageTypeEnum;
|
||||
import com.abin.mallchat.common.common.utils.AssertUtil;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageReq;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -29,6 +30,8 @@ public class ImgMsgHandler extends AbstractMsgHandler {
|
||||
|
||||
@Override
|
||||
public void checkMsg(ChatMessageReq request, Long uid) {
|
||||
ImgMsgDTO body = BeanUtil.toBean(request.getBody(), ImgMsgDTO.class);
|
||||
AssertUtil.allCheckValidateThrow(body);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.abin.mallchat.common.chat.domain.entity.Message;
|
||||
import com.abin.mallchat.common.chat.domain.entity.msg.MessageExtra;
|
||||
import com.abin.mallchat.common.chat.domain.entity.msg.SoundMsgDTO;
|
||||
import com.abin.mallchat.common.chat.domain.enums.MessageTypeEnum;
|
||||
import com.abin.mallchat.common.common.utils.AssertUtil;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageReq;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -29,6 +30,8 @@ public class SoundMsgHandler extends AbstractMsgHandler {
|
||||
|
||||
@Override
|
||||
public void checkMsg(ChatMessageReq request, Long uid) {
|
||||
SoundMsgDTO body = BeanUtil.toBean(request.getBody(), SoundMsgDTO.class);
|
||||
AssertUtil.allCheckValidateThrow(body);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -57,8 +57,7 @@ public class TextMsgHandler extends AbstractMsgHandler {
|
||||
@Override
|
||||
public void checkMsg(ChatMessageReq request, Long uid) {
|
||||
TextMsgReq body = BeanUtil.toBean(request.getBody(), TextMsgReq.class);
|
||||
AssertUtil.isNotEmpty(body.getContent(), "内容不能为空");
|
||||
AssertUtil.isTrue(body.getContent().length() < 500, "消息内容过长,服务器扛不住啊,兄dei");
|
||||
AssertUtil.allCheckValidateThrow(body);
|
||||
//校验下回复消息
|
||||
if (Objects.nonNull(body.getReplyMsgId())) {
|
||||
Message replyMsg = messageDao.getById(body.getReplyMsgId());
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.abin.mallchat.common.chat.domain.entity.Message;
|
||||
import com.abin.mallchat.common.chat.domain.entity.msg.MessageExtra;
|
||||
import com.abin.mallchat.common.chat.domain.entity.msg.VideoMsgDTO;
|
||||
import com.abin.mallchat.common.chat.domain.enums.MessageTypeEnum;
|
||||
import com.abin.mallchat.common.common.utils.AssertUtil;
|
||||
import com.abin.mallchat.custom.chat.domain.vo.request.ChatMessageReq;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -29,6 +30,8 @@ public class VideoMsgHandler extends AbstractMsgHandler {
|
||||
|
||||
@Override
|
||||
public void checkMsg(ChatMessageReq request, Long uid) {
|
||||
VideoMsgDTO body = BeanUtil.toBean(request.getBody(), VideoMsgDTO.class);
|
||||
AssertUtil.allCheckValidateThrow(body);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user