Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -34,7 +34,7 @@ SELECT COUNT(cm) FROM ChatMessage cm
""")
long countUnreadMessages(@Param("chatRoomId") long chatRoomId, @Param("userId") long userId);

boolean existsByMentoringId(long mentoringId);
ChatRoom findByMentoringId(long mentoringId);

List<ChatRoom> findAllByMentoringIdIn(List<Long> mentoringIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,20 @@ public void sendChatMessage(ChatMessageSendRequest chatMessageSendRequest, long
}

@Transactional
public void createMentoringChatRoom(Long mentoringId, Long mentorId, Long menteeId) {
if (chatRoomRepository.existsByMentoringId(mentoringId)) {
return;
public Long createMentoringChatRoom(Long mentoringId, Long mentorId, Long menteeId) {
ChatRoom existingChatRoom = chatRoomRepository.findByMentoringId(mentoringId);
if (existingChatRoom != null) {
return existingChatRoom.getId();
}

// 새 채팅방 생성
ChatRoom chatRoom = new ChatRoom(mentoringId, false);
chatRoom = chatRoomRepository.save(chatRoom);

ChatParticipant mentorParticipant = new ChatParticipant(mentorId, chatRoom);
ChatParticipant menteeParticipant = new ChatParticipant(menteeId, chatRoom);
chatParticipantRepository.saveAll(List.of(mentorParticipant, menteeParticipant));

return chatRoom.getId();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.example.solidconnection.mentor.dto;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;

import com.example.solidconnection.mentor.domain.Mentoring;
import com.fasterxml.jackson.annotation.JsonInclude;

public record MentoringConfirmResponse(
long mentoringId
long mentoringId,

@JsonInclude(NON_NULL)
Long chatRoomId
) {

public static MentoringConfirmResponse from(Mentoring mentoring) {
return new MentoringConfirmResponse(mentoring.getId());
public static MentoringConfirmResponse from(Mentoring mentoring, Long chatRoomId) {
return new MentoringConfirmResponse(mentoring.getId(), chatRoomId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_NOT_FOUND;
import static com.example.solidconnection.common.exception.ErrorCode.UNAUTHORIZED_MENTORING;

import com.example.solidconnection.chat.service.ChatService;
import com.example.solidconnection.common.VerifyStatus;
import com.example.solidconnection.common.exception.CustomException;
import com.example.solidconnection.mentor.domain.Mentor;
import com.example.solidconnection.mentor.domain.Mentoring;
import com.example.solidconnection.mentor.dto.MentoringApplyRequest;
import com.example.solidconnection.mentor.dto.MentoringApplyResponse;
import com.example.solidconnection.mentor.dto.MentoringApprovedEvent;
import com.example.solidconnection.mentor.dto.MentoringConfirmRequest;
import com.example.solidconnection.mentor.dto.MentoringConfirmResponse;
import com.example.solidconnection.mentor.repository.MentorRepository;
import com.example.solidconnection.mentor.repository.MentoringRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -27,7 +26,7 @@ public class MentoringCommandService {

private final MentoringRepository mentoringRepository;
private final MentorRepository mentorRepository;
private final ApplicationEventPublisher eventPublisher;
private final ChatService chatService;

@Transactional
public MentoringApplyResponse applyMentoring(long siteUserId, MentoringApplyRequest mentoringApplyRequest) {
Expand All @@ -49,12 +48,13 @@ public MentoringConfirmResponse confirmMentoring(long siteUserId, long mentoring

mentoring.confirm(mentoringConfirmRequest.status());

Long chatRoomId = null;
if (mentoringConfirmRequest.status() == VerifyStatus.APPROVED) {
mentor.increaseMenteeCount();
eventPublisher.publishEvent(MentoringApprovedEvent.of(mentoringId, mentor.getSiteUserId(), mentoring.getMenteeId()));
chatRoomId = chatService.createMentoringChatRoom(mentoringId, mentor.getSiteUserId(), mentoring.getMenteeId());
}

return MentoringConfirmResponse.from(mentoring);
return MentoringConfirmResponse.from(mentoring, chatRoomId);
}

private void validateMentoringNotConfirmed(Mentoring mentoring) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,17 @@ class 멘토링_승인_거절_테스트 {
assertThat(beforeChatRoom).isEmpty();

// when
mentoringCommandService.confirmMentoring(mentorUser1.getId(), mentoring.getId(), request);
MentoringConfirmResponse response = mentoringCommandService.confirmMentoring(mentorUser1.getId(), mentoring.getId(), request);

// then
ChatRoom afterChatRoom = await()
.atMost(Duration.ofSeconds(5))
.pollInterval(Duration.ofMillis(100))
.until(() -> chatRoomRepositoryForTest
.findOneOnOneChatRoomByParticipants(mentorUser1.getId(), menteeUser.getId()),
Optional::isPresent)
.orElseThrow();

ChatRoom afterChatRoom = chatRoomRepositoryForTest.findOneOnOneChatRoomByParticipants(mentorUser1.getId(), menteeUser.getId()).orElseThrow();
List<Long> participantIds = afterChatRoom.getChatParticipants().stream()
.map(ChatParticipant::getSiteUserId)
.toList();
assertAll(
() -> assertThat(afterChatRoom.isGroup()).isFalse(),
() -> assertThat(participantIds).containsExactly(mentorUser1.getId(), menteeUser.getId())
() -> assertThat(participantIds).containsExactly(mentorUser1.getId(), menteeUser.getId()),
() -> assertThat(response.chatRoomId()).isEqualTo(afterChatRoom.getId())
);
}

Expand Down Expand Up @@ -186,19 +180,14 @@ class 멘토링_승인_거절_테스트 {
assertThat(beforeChatRoom).isEmpty();

// when
mentoringCommandService.confirmMentoring(mentorUser1.getId(), mentoring.getId(), request);
MentoringConfirmResponse response = mentoringCommandService.confirmMentoring(mentorUser1.getId(), mentoring.getId(), request);

// then
await()
.pollInterval(Duration.ofMillis(100))
.during(Duration.ofSeconds(1))
.until(() -> chatRoomRepositoryForTest
.findOneOnOneChatRoomByParticipants(mentorUser1.getId(), menteeUser.getId())
.isEmpty());

Optional<ChatRoom> afterChatRoom = chatRoomRepositoryForTest.findOneOnOneChatRoomByParticipants(mentorUser1.getId(), menteeUser.getId());
assertThat(afterChatRoom).isEmpty();

assertAll(
() -> assertThat(response.chatRoomId()).isNull(),
() -> assertThat(afterChatRoom).isEmpty()
);
}

@Test
Expand Down
Loading