Skip to content

Commit 93fa057

Browse files
committed
feat: 채팅 메시지를 가져오는 엔드포인트 구현
Related to: #136
1 parent 1a85aa0 commit 93fa057

File tree

5 files changed

+147
-1
lines changed

5 files changed

+147
-1
lines changed

src/main/java/com/hf/healthfriend/domain/chat/controller/ChatRestController.java

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
package com.hf.healthfriend.domain.chat.controller;
22

33
import com.hf.healthfriend.domain.chat.constant.ChatroomListSearchCondition;
4+
import com.hf.healthfriend.domain.chat.controller.schema.ChatMessageListResponseSchema;
5+
import com.hf.healthfriend.domain.chat.dto.response.ChatMessageListResponseDto;
46
import com.hf.healthfriend.domain.chat.dto.response.ChatroomListResponseDto;
57
import com.hf.healthfriend.domain.chat.service.ChatService;
68
import com.hf.healthfriend.global.spec.ApiBasicResponse;
9+
import io.swagger.v3.oas.annotations.Operation;
10+
import io.swagger.v3.oas.annotations.Parameter;
11+
import io.swagger.v3.oas.annotations.enums.ParameterIn;
12+
import io.swagger.v3.oas.annotations.media.Content;
13+
import io.swagger.v3.oas.annotations.media.ExampleObject;
14+
import io.swagger.v3.oas.annotations.media.Schema;
15+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
716
import lombok.RequiredArgsConstructor;
817
import org.springframework.http.HttpStatus;
918
import org.springframework.http.ResponseEntity;
@@ -28,4 +37,117 @@ public ResponseEntity<ApiBasicResponse<List<ChatroomListResponseDto>>> getChatro
2837
ApiBasicResponse.of(this.chatService.getChatroomList(participantId, searchCondition, page, pageSize), HttpStatus.OK)
2938
);
3039
}
40+
41+
@GetMapping("/chatrooms/{chatroomId}/chat-messages")
42+
@Operation(
43+
summary = "채팅 메시지 불러오기",
44+
parameters = {
45+
@Parameter(
46+
name = "chatroomId",
47+
in = ParameterIn.PATH,
48+
description = "채팅 목록을 가져올 채팅방의 ID",
49+
required = true
50+
),
51+
@Parameter(
52+
name = "page",
53+
in = ParameterIn.QUERY,
54+
description = "채팅 목록 페이지. 생략 시 1"
55+
),
56+
@Parameter(
57+
name = "pageSize",
58+
in = ParameterIn.QUERY,
59+
description = "한 번에 가져올 채팅의 개수. default: 50"
60+
)
61+
},
62+
responses = {
63+
@ApiResponse(
64+
description = "채팅 목록 가져오기 성공",
65+
responseCode = "200",
66+
content = @Content(
67+
schema = @Schema(implementation = ChatMessageListResponseSchema.class),
68+
examples = @ExampleObject("""
69+
{
70+
"statusCode": 200,
71+
"statusCodeSeries": 2,
72+
"content": {
73+
"isFirst": true,
74+
"isLast": false,
75+
"page": 1,
76+
"pageSize": 5,
77+
"chatMessages": [
78+
{
79+
"chatMessageId": 456,
80+
"senderId": 120,
81+
"creationTime": "2025-01-07T12:00:00.000Z",
82+
"lastModified": "2025-01-07T12:00:00.000Z",
83+
"chatMessageType": "TEXT",
84+
"content": {
85+
"text": "Good Bye!"
86+
},
87+
"read": true
88+
},
89+
{
90+
"chatMessageId": 447,
91+
"senderId": 120,
92+
"creationTime": "2025-01-07T11:30:00.000Z",
93+
"lastModified": "2025-01-07T11:30:00.000Z",
94+
"chatMessageType": "TEXT",
95+
"content": {
96+
"text": "Hello!"
97+
},
98+
"read": true
99+
},
100+
{
101+
"chatMessageId": 420,
102+
"senderId": 80,
103+
"creationTime": "2025-01-07T11:27:00.000Z",
104+
"lastModified": "2025-01-07T11:27:00.000Z",
105+
"chatMessageType": "MATCHING_RESPONSE",
106+
"content": {
107+
"matchingResponseType": "ACCEPTED",
108+
"cancelMessage": null
109+
},
110+
"read": true
111+
},
112+
{
113+
"chatMessageId": 415,
114+
"senderId": 120,
115+
"creationTime": "2025-01-07T11:00:00.000Z",
116+
"lastModified": "2025-01-07T11:00:00.000Z",
117+
"chatMessageType": "MATCHING_REQUEST",
118+
"content": {
119+
"meetingTime": "2025-01-08T18:00:00.000Z",
120+
"meetingPlace": "스포애니 당산점",
121+
"meetingPlaceAddress": "서울시 영등포구 당산역"
122+
},
123+
"read": true
124+
},
125+
{
126+
"chatMessageId": 410,
127+
"senderId": 80,
128+
"creationTime": "2025-01-07T10:00:00.000Z",
129+
"lastModified": "2025-01-07T10:00:00.000Z",
130+
"chatMessageType": "TEXT",
131+
"content": {
132+
"TEXT": "매칭 신청 걸어주세요"
133+
},
134+
"read": true
135+
}
136+
]
137+
}
138+
}
139+
""")
140+
)
141+
)
142+
}
143+
)
144+
public ResponseEntity<ApiBasicResponse<ChatMessageListResponseDto>> getChatMessages(
145+
@PathVariable("chatroomId") Long chatroomId,
146+
@RequestParam(value = "page", required = false) Integer page,
147+
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
148+
ChatMessageListResponseDto result = this.chatService.getChatMessages(chatroomId, page, pageSize);
149+
return ResponseEntity.ok(
150+
ApiBasicResponse.of(result, HttpStatus.OK)
151+
);
152+
}
31153
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.hf.healthfriend.domain.chat.controller.schema;
2+
3+
import com.hf.healthfriend.domain.chat.dto.response.ChatMessageListResponseDto;
4+
import com.hf.healthfriend.global.spec.ApiBasicResponse;
5+
6+
public class ChatMessageListResponseSchema extends ApiBasicResponse<ChatMessageListResponseDto> {
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
package com.hf.healthfriend.domain.chat.dto.response;
22

3+
import io.swagger.v3.oas.annotations.media.Schema;
34
import lombok.Builder;
45

56
import java.util.List;
67

78
@Builder
89
public record ChatMessageListResponseDto(
910
List<ChatMessageResponseDto> chatMessages,
11+
12+
@Schema(description = "현재 페이지가 첫 번째 페이지인지 여부")
1013
boolean isFirst,
14+
15+
@Schema(description = "현재 페이지가 마지막 페이지인지 여부")
1116
boolean isLast,
17+
18+
@Schema(description = "현재 페이지")
1219
int page,
20+
21+
@Schema(description = "페이지의 크기 (채팅 메시지를 불러온 개수)")
1322
int pageSize
1423
) {
1524
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package com.hf.healthfriend.domain.chat.dto.response.messagecontent;
22

33
import com.hf.healthfriend.domain.chat.constant.MatchingResponseType;
4+
import io.swagger.v3.oas.annotations.media.Schema;
45

56
public record MatchingResponseChatMessageResponseContent(
7+
8+
@Schema(description = "매칭 신청의 응답 타입")
69
MatchingResponseType matchingResponseType,
10+
11+
@Schema(description = "매칭 신청을 거절할 경우의 메시지. matchingResponsetype이 " +
12+
"ACCEPTED일 경우 null")
713
String cancelMessage
814
) {
915
}

src/main/java/com/hf/healthfriend/domain/chat/service/ChatService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ public List<ChatroomListResponseDto> getChatroomList(Long participantId,
8484
.toList();
8585
}
8686

87-
public ChatMessageListResponseDto getChatMessages(Long chatroomId, int page, int pageSize) {
87+
public ChatMessageListResponseDto getChatMessages(Long chatroomId, Integer page, Integer pageSize) {
88+
page = page == null ? ChatDefaultValues.DEFAULT_PAGE : page;
89+
pageSize = pageSize == null ? ChatDefaultValues.DEFAULT_CHAT_MESSAGE_FETCH_SIZE : pageSize;
8890
this.chatMessageRepository.readMessagesInChatroomByOpponent(chatroomId);
8991

9092
Page<ChatMessage> messages =

0 commit comments

Comments
 (0)