Skip to content

Commit

Permalink
Merge pull request #79 from wooyeon0626/feature/chatting
Browse files Browse the repository at this point in the history
[FIX] 채팅 목록 반환 값 변경
  • Loading branch information
tenta3802 authored Feb 5, 2024
2 parents 4debe02 + d66d93c commit 66a76a5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/chat")
Expand All @@ -18,7 +16,7 @@ public class ChatController {
private final ChatService chatService;

@GetMapping("/list")
public List<ChatDto.Response> getChatList(@RequestParam Long matchId) {
public ChatDto.Response getChatList(@RequestParam Long matchId) {
return chatService.getChatList(matchId);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/wooyeon/yeon/chat/dto/ChatDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;

public class ChatDto {

Expand All @@ -18,6 +19,12 @@ public static class Request {
@Getter
@Builder
public static class Response {
private List<ChatResponse> chatData;
}

@Getter
@Builder
public static class ChatResponse {
private String message;
private LocalDateTime sendTime;
private String sender;
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/wooyeon/yeon/chat/service/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,27 @@ public void saveChat(StompDto stompDto) {
chatRepository.save(chat);
}

public List<ChatDto.Response> getChatList(Long matchId) {
public ChatDto.Response getChatList(Long matchId) {

UserMatch userMatch = matchRepository.findById(matchId)
.orElseThrow(() -> new IllegalArgumentException(ExceptionMessage.USER_MATCH_NOT_FOUND.toString()));

List<Chat> chatList = chatRepository.findAllByUserMatchOrderBySendTime(userMatch);
List<ChatDto.Response> responseList = new ArrayList<>();
List<ChatDto.ChatResponse> responseList = new ArrayList<>();

String userName = getLoginUserNickName();

for (Chat chat : chatList) {
responseList.add(makeResponse(chat, userName));
}

return responseList;
return ChatDto.Response.builder()
.chatData(responseList)
.build();
}

public ChatDto.Response makeResponse(Chat chat, String userName) {
return ChatDto.Response.builder()
public ChatDto.ChatResponse makeResponse(Chat chat, String userName) {
return ChatDto.ChatResponse.builder()
.message(chat.getMessage())
.sender(chat.getSender())
.sendTime(chat.getSendTime())
Expand Down

0 comments on commit 66a76a5

Please sign in to comment.