Skip to content

Commit 88aefaa

Browse files
committed
[#41] feat: 전체 채팅 조회 기능
1 parent 0bf1032 commit 88aefaa

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.nexters.teamace.chat.application;
2+
3+
import com.nexters.teamace.common.exception.ValidationErrorMessage;
4+
5+
public record AllChatQuery(Long chatRoomId) {
6+
public AllChatQuery {
7+
if (chatRoomId == null) {
8+
throw new IllegalArgumentException(ValidationErrorMessage.CHAT_ROOM_ID_NOT_NULL);
9+
}
10+
if (chatRoomId < 1) {
11+
throw new IllegalArgumentException(ValidationErrorMessage.CHAT_ROOM_ID_POSITIVE);
12+
}
13+
}
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.nexters.teamace.chat.application;
2+
3+
import com.nexters.teamace.chat.domain.MessageType;
4+
import java.util.List;
5+
6+
public record AllChatResult(Long chatRoomId, List<ChatResult> chats) {
7+
8+
public record ChatResult(Long chatId, MessageType type, String message) {}
9+
}

src/main/java/com/nexters/teamace/chat/application/ChatRoomService.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.nexters.teamace.chat.domain.ChatMessageGenerator;
55
import com.nexters.teamace.chat.domain.ChatRoom;
66
import com.nexters.teamace.chat.domain.ChatRoomRepository;
7+
import com.nexters.teamace.common.infrastructure.annotation.ReadOnlyTransactional;
78
import com.nexters.teamace.user.application.GetUserResult;
89
import com.nexters.teamace.user.application.UserService;
910
import lombok.RequiredArgsConstructor;
@@ -44,4 +45,17 @@ public SendMessageResult sendMessage(final SendMessageCommand command) {
4445

4546
return new SendMessageResult(responseMessage);
4647
}
48+
49+
@ReadOnlyTransactional
50+
public AllChatResult getAllChats(final AllChatQuery query) {
51+
final ChatRoom chatRoom = chatRoomRepository.getById(query.chatRoomId());
52+
return new AllChatResult(
53+
chatRoom.getId(),
54+
chatRoom.getChats().stream()
55+
.map(
56+
chat ->
57+
new AllChatResult.ChatResult(
58+
chat.getId(), chat.getType(), chat.getMessage()))
59+
.toList());
60+
}
4761
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.nexters.teamace.common.infrastructure.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
import org.springframework.transaction.annotation.Propagation;
8+
import org.springframework.transaction.annotation.Transactional;
9+
10+
@Target({ElementType.TYPE, ElementType.METHOD})
11+
@Retention(RetentionPolicy.RUNTIME)
12+
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
13+
public @interface ReadOnlyTransactional {}

0 commit comments

Comments
 (0)