-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbdb0f2
commit 61ba4c4
Showing
9 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/woongeya/zoing/domain/chat/exception/ChatRoomNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.woongeya.zoing.domain.chat.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
import com.woongeya.zoing.global.error.exception.ErrorCode; | ||
import com.woongeya.zoing.global.error.exception.ZoingException; | ||
|
||
public class ChatRoomNotFoundException extends ZoingException { | ||
|
||
public ChatRoomNotFoundException() { | ||
super(ErrorCode.CHAT_ROOM_NOT_FOUND); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/woongeya/zoing/domain/chat/presentation/ChatController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.woongeya.zoing.domain.chat.presentation; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.messaging.handler.annotation.DestinationVariable; | ||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.messaging.handler.annotation.SendTo; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.woongeya.zoing.domain.chat.presentation.dto.request.ChatRequest; | ||
import com.woongeya.zoing.domain.chat.service.command.CommandChatService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class ChatController { | ||
|
||
private final CommandChatService commandChatService; | ||
|
||
@MessageMapping("/{roomId}") | ||
@SendTo("/room/{roomId}") | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public void send(@DestinationVariable Long roomId, ChatRequest request) { | ||
commandChatService.create(roomId, request); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/woongeya/zoing/domain/chat/presentation/dto/request/ChatRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.woongeya.zoing.domain.chat.presentation.dto.request; | ||
|
||
import com.woongeya.zoing.domain.chat.domain.Chat; | ||
import com.woongeya.zoing.domain.chat.domain.ChatRoom; | ||
import com.woongeya.zoing.domain.user.domain.User; | ||
|
||
public record ChatRequest ( | ||
String message | ||
) { | ||
|
||
public Chat toEntity(User sender, ChatRoom room) { | ||
return new Chat(message, sender.getId(), sender.getName(), room); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/woongeya/zoing/domain/chat/service/command/CommandChatService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.woongeya.zoing.domain.chat.service.command; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.woongeya.zoing.domain.chat.domain.ChatRoom; | ||
import com.woongeya.zoing.domain.chat.domain.repository.ChatRepository; | ||
import com.woongeya.zoing.domain.chat.domain.repository.ChatRoomRepository; | ||
import com.woongeya.zoing.domain.chat.presentation.dto.request.ChatRequest; | ||
import com.woongeya.zoing.domain.user.UserFacade; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CommandChatService { | ||
|
||
private final ChatRepository chatRepository; | ||
private final ChatRoomRepository chatRoomRepository; | ||
private final UserFacade userFacade; | ||
|
||
public void create(Long roomId, ChatRequest request) { | ||
ChatRoom chatRoom = chatRoomRepository.getById(roomId); | ||
chatRepository.save( | ||
request.toEntity(userFacade.getCurrentUser(), chatRoom) | ||
); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/woongeya/zoing/global/config/WebSocketConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.woongeya.zoing.global.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; | ||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; | ||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; | ||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; | ||
|
||
@Configuration | ||
@EnableWebSocketMessageBroker | ||
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { | ||
|
||
@Override | ||
public void registerStompEndpoints(StompEndpointRegistry registry) { | ||
registry.addEndpoint("/chat").setAllowedOriginPatterns("*").withSockJS(); | ||
} | ||
|
||
@Override | ||
public void configureMessageBroker(MessageBrokerRegistry registry) { | ||
registry.enableSimpleBroker("/sub"); | ||
registry.setApplicationDestinationPrefixes("/pub"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters