Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat #92] 채팅방 메시지 조회 API #93

Merged
merged 18 commits into from
Aug 29, 2024
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.dnd.gongmuin.chat.service;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dnd.gongmuin.chat.dto.ChatMapper;
import com.dnd.gongmuin.chat.dto.ChatMessageRequest;
import com.dnd.gongmuin.chat.dto.ChatMessageResponse;
import com.dnd.gongmuin.chat.repository.ChatMessageRepository;
import com.dnd.gongmuin.common.dto.PageMapper;
import com.dnd.gongmuin.common.dto.PageResponse;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class ChatMessageService {

private final ChatMessageRepository chatMessageRepository;

@Transactional
public void saveChatMessage(
ChatMessageRequest request,
Long chatRoomId,
Long memberId
) {
chatMessageRepository.save(ChatMapper.toChatMessage(request, chatRoomId, memberId));
}

@Transactional(readOnly = true)
public PageResponse<ChatMessageResponse> getChatMessage(Long chatRoomId, Pageable pageable) {
hyun2371 marked this conversation as resolved.
Show resolved Hide resolved
Slice<ChatMessageResponse> responsePage = chatMessageRepository
.findByChatRoomIdOrderByCreatedAtDesc(chatRoomId, pageable)
.map(ChatMapper::toChatMessageResponse);
return PageMapper.toPageResponse(responsePage);
}

}