Bảo Ngô
Beginner
Asked At:
1709646399000
In:
EzyFox Server
Bàn về cách ezy trả response
@Override<p>
protected void execute() throws EzyBadRequestException {
</p>
<p>
if (message.length() > 255) {
</p>
<p>
throw new EzyBadRequestException(ChatErrors.MESSAGE_TOO_LONG, "message too long");
</p>
<p>
}
</p>
<p>
ChatChannelUsers channelUsers =
</p>
<p>
channelUserService.getChannelUsers(channelId, user.getName());
</p>
<p>
if (channelUsers == null) {
</p>
<p>
throw new EzyBadRequestException(ChatErrors.CHANNEL_NOT_FOUND, "channel with id: " + channelId + " not found");
</p>
<p>
}
</p>
<p>
messageService.save(new ChatMessage(
</p>
<p>
maxIdService.incrementAndGet(ChatEntities.CHAT_MESSAGE),
</p>
<p>
true, message, channelId, user.getName(), clientMessageId
</p>
<p>
));
</p>
<p>
responseFactory.newObjectResponse()
</p>
<p>
.command(CHAT_USER_MESSAGE)
</p>
<p>
.param("from", user.getName())
</p>
<p>
.param("message", message)
</p>
<p>
.param("channelId", channelId)
</p>
<p>
.usernames(channelUsers.getUsers())
</p>
<p>
.execute();
</p>
<p>
}
</p>
<p>
Đoạn code trên xử lý request và gửi response cho user. Tuy nhiên e có thắc mắc là tại sao mình ko thiết kế để return 1 cái response entity (ví dụ bên spring) hoặc 1 dto màcác lại return void và để việc response cho developer?
</p>
<p>
Nếu như e có 1 concurrent map/list để cache user lại và sau đó bốc bừa 1 vài user ra để gửi thì sẽ có vấn đề không?
</p>
<p>
Tệ hơn nữa, nếu e cache lại responseFactory và dùng nó cùng với list user để spam message thì có ổn không?
</p>
<p>
Regards
</p>