Skip to content

Commit

Permalink
feat: 채팅 메시지를 가져오는 엔드포인트 구현
Browse files Browse the repository at this point in the history
Related to: #136
  • Loading branch information
rudeh1253 committed Jan 7, 2025
1 parent 1a85aa0 commit 93fa057
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package com.hf.healthfriend.domain.chat.controller;

import com.hf.healthfriend.domain.chat.constant.ChatroomListSearchCondition;
import com.hf.healthfriend.domain.chat.controller.schema.ChatMessageListResponseSchema;
import com.hf.healthfriend.domain.chat.dto.response.ChatMessageListResponseDto;
import com.hf.healthfriend.domain.chat.dto.response.ChatroomListResponseDto;
import com.hf.healthfriend.domain.chat.service.ChatService;
import com.hf.healthfriend.global.spec.ApiBasicResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -28,4 +37,117 @@ public ResponseEntity<ApiBasicResponse<List<ChatroomListResponseDto>>> getChatro
ApiBasicResponse.of(this.chatService.getChatroomList(participantId, searchCondition, page, pageSize), HttpStatus.OK)
);
}

@GetMapping("/chatrooms/{chatroomId}/chat-messages")
@Operation(
summary = "채팅 메시지 불러오기",
parameters = {
@Parameter(
name = "chatroomId",
in = ParameterIn.PATH,
description = "채팅 목록을 가져올 채팅방의 ID",
required = true
),
@Parameter(
name = "page",
in = ParameterIn.QUERY,
description = "채팅 목록 페이지. 생략 시 1"
),
@Parameter(
name = "pageSize",
in = ParameterIn.QUERY,
description = "한 번에 가져올 채팅의 개수. default: 50"
)
},
responses = {
@ApiResponse(
description = "채팅 목록 가져오기 성공",
responseCode = "200",
content = @Content(
schema = @Schema(implementation = ChatMessageListResponseSchema.class),
examples = @ExampleObject("""
{
"statusCode": 200,
"statusCodeSeries": 2,
"content": {
"isFirst": true,
"isLast": false,
"page": 1,
"pageSize": 5,
"chatMessages": [
{
"chatMessageId": 456,
"senderId": 120,
"creationTime": "2025-01-07T12:00:00.000Z",
"lastModified": "2025-01-07T12:00:00.000Z",
"chatMessageType": "TEXT",
"content": {
"text": "Good Bye!"
},
"read": true
},
{
"chatMessageId": 447,
"senderId": 120,
"creationTime": "2025-01-07T11:30:00.000Z",
"lastModified": "2025-01-07T11:30:00.000Z",
"chatMessageType": "TEXT",
"content": {
"text": "Hello!"
},
"read": true
},
{
"chatMessageId": 420,
"senderId": 80,
"creationTime": "2025-01-07T11:27:00.000Z",
"lastModified": "2025-01-07T11:27:00.000Z",
"chatMessageType": "MATCHING_RESPONSE",
"content": {
"matchingResponseType": "ACCEPTED",
"cancelMessage": null
},
"read": true
},
{
"chatMessageId": 415,
"senderId": 120,
"creationTime": "2025-01-07T11:00:00.000Z",
"lastModified": "2025-01-07T11:00:00.000Z",
"chatMessageType": "MATCHING_REQUEST",
"content": {
"meetingTime": "2025-01-08T18:00:00.000Z",
"meetingPlace": "스포애니 당산점",
"meetingPlaceAddress": "서울시 영등포구 당산역"
},
"read": true
},
{
"chatMessageId": 410,
"senderId": 80,
"creationTime": "2025-01-07T10:00:00.000Z",
"lastModified": "2025-01-07T10:00:00.000Z",
"chatMessageType": "TEXT",
"content": {
"TEXT": "매칭 신청 걸어주세요"
},
"read": true
}
]
}
}
""")
)
)
}
)
public ResponseEntity<ApiBasicResponse<ChatMessageListResponseDto>> getChatMessages(
@PathVariable("chatroomId") Long chatroomId,
@RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
ChatMessageListResponseDto result = this.chatService.getChatMessages(chatroomId, page, pageSize);
return ResponseEntity.ok(
ApiBasicResponse.of(result, HttpStatus.OK)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.hf.healthfriend.domain.chat.controller.schema;

import com.hf.healthfriend.domain.chat.dto.response.ChatMessageListResponseDto;
import com.hf.healthfriend.global.spec.ApiBasicResponse;

public class ChatMessageListResponseSchema extends ApiBasicResponse<ChatMessageListResponseDto> {
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package com.hf.healthfriend.domain.chat.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

import java.util.List;

@Builder
public record ChatMessageListResponseDto(
List<ChatMessageResponseDto> chatMessages,

@Schema(description = "현재 페이지가 첫 번째 페이지인지 여부")
boolean isFirst,

@Schema(description = "현재 페이지가 마지막 페이지인지 여부")
boolean isLast,

@Schema(description = "현재 페이지")
int page,

@Schema(description = "페이지의 크기 (채팅 메시지를 불러온 개수)")
int pageSize
) {
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.hf.healthfriend.domain.chat.dto.response.messagecontent;

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

public record MatchingResponseChatMessageResponseContent(

@Schema(description = "매칭 신청의 응답 타입")
MatchingResponseType matchingResponseType,

@Schema(description = "매칭 신청을 거절할 경우의 메시지. matchingResponsetype이 " +
"ACCEPTED일 경우 null")
String cancelMessage
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public List<ChatroomListResponseDto> getChatroomList(Long participantId,
.toList();
}

public ChatMessageListResponseDto getChatMessages(Long chatroomId, int page, int pageSize) {
public ChatMessageListResponseDto getChatMessages(Long chatroomId, Integer page, Integer pageSize) {
page = page == null ? ChatDefaultValues.DEFAULT_PAGE : page;
pageSize = pageSize == null ? ChatDefaultValues.DEFAULT_CHAT_MESSAGE_FETCH_SIZE : pageSize;
this.chatMessageRepository.readMessagesInChatroomByOpponent(chatroomId);

Page<ChatMessage> messages =
Expand Down

0 comments on commit 93fa057

Please sign in to comment.