Bảo Ngô
Beginner
Asked At:
1709646399000
In:
EzyFox Server
Bàn về cách ezy trả response
<div class="markdown-block">@Overrideprotected void execute() throws EzyBadRequestException {if (message.length() > 255) {throw new EzyBadRequestException(ChatErrors.MESSAGE_TOO_LONG, "message too long");}ChatChannelUsers channelUsers =channelUserService.getChannelUsers(channelId, user.getName());if (channelUsers == null) {throw new EzyBadRequestException(ChatErrors.CHANNEL_NOT_FOUND, "channel with id: " + channelId + " not found");}messageService.save(new ChatMessage(maxIdService.incrementAndGet(ChatEntities.CHAT_MESSAGE),true, message, channelId, user.getName(), clientMessageId));responseFactory.newObjectResponse().command(CHAT_USER_MESSAGE).param("from", user.getName()).param("message", message).param("channelId", channelId).usernames(channelUsers.getUsers()).execute();}Đ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?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?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 k</div>