-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GameChat): MessageController 수정
- Loading branch information
Showing
1 changed file
with
13 additions
and
37 deletions.
There are no files selected for viewing
50 changes: 13 additions & 37 deletions
50
src/main/java/com/sportsecho/gamechat/controller/MessageController.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 |
---|---|---|
@@ -1,52 +1,28 @@ | ||
package com.sportsecho.gamechat.controller; | ||
|
||
import com.sportsecho.gamechat.dto.GameChatRequestDto; | ||
import com.sportsecho.gamechat.dto.GameChatResponseDto; | ||
import java.text.SimpleDateFormat; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Date; | ||
import com.sportsecho.common.kafka.KafkaConst; | ||
import com.sportsecho.common.kafka.KafkaMessageUtil; | ||
import com.sportsecho.gamechat.dto.MessageRequestDto; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.messaging.handler.annotation.DestinationVariable; | ||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.messaging.handler.annotation.SendTo; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Controller | ||
@RestController | ||
@RequiredArgsConstructor | ||
@Slf4j(topic = "MessageController") | ||
public class MessageController { | ||
|
||
@MessageMapping("/gameChat/{gameId}/enter") | ||
@SendTo("/topic/{gameId}") | ||
public GameChatResponseDto enter( | ||
@DestinationVariable("gameId") Long gameId, | ||
GameChatRequestDto request | ||
) { | ||
private final KafkaMessageUtil kafkaMessageUtil; | ||
|
||
return GameChatResponseDto.builder() | ||
.content(request.getSender() + "님이 입장하셨습니다.") | ||
.build(); | ||
} | ||
@MessageMapping("/message") | ||
public void sendMessage(MessageRequestDto messageRequestDto) { | ||
log.info("Received message\nsender = {}, message = {}", messageRequestDto.getSender(), messageRequestDto.getMessage()); | ||
|
||
@MessageMapping("/gameChat/{gameId}") | ||
@SendTo("/topic/{gameId}") | ||
public GameChatResponseDto publish( | ||
@DestinationVariable("gameId") Long gameId, | ||
GameChatRequestDto request | ||
) { | ||
LocalDateTime now = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDateTime(); | ||
|
||
String formattedTime = now.format(DateTimeFormatter.ofPattern("HH:mm")); | ||
|
||
return GameChatResponseDto.builder() | ||
.sender(request.getSender()) | ||
.content(request.getMessage()) | ||
.sendAt(formattedTime) | ||
.build(); | ||
//message service logic | ||
kafkaMessageUtil.send(KafkaConst.KAFKA_TOPIC, messageRequestDto); | ||
} | ||
|
||
} | ||
|
||
|