diff --git a/backend/src/main/java/mouda/backend/chat/implement/sender/ChatNotificationSender.java b/backend/src/main/java/mouda/backend/chat/implement/sender/ChatNotificationSender.java index 6d01dc14f..290769b99 100644 --- a/backend/src/main/java/mouda/backend/chat/implement/sender/ChatNotificationSender.java +++ b/backend/src/main/java/mouda/backend/chat/implement/sender/ChatNotificationSender.java @@ -19,7 +19,6 @@ import mouda.backend.darakbang.domain.Darakbang; import mouda.backend.darakbang.implement.DarakbangFinder; import mouda.backend.moim.domain.Moim; -import mouda.backend.moim.implement.finder.ChatRecipientFinder; import mouda.backend.moim.implement.finder.MoimFinder; import mouda.backend.notification.domain.NotificationEvent; import mouda.backend.notification.domain.NotificationType; diff --git a/backend/src/main/java/mouda/backend/moim/implement/finder/ChatRecipientFinder.java b/backend/src/main/java/mouda/backend/chat/implement/sender/ChatRecipientFinder.java similarity index 98% rename from backend/src/main/java/mouda/backend/moim/implement/finder/ChatRecipientFinder.java rename to backend/src/main/java/mouda/backend/chat/implement/sender/ChatRecipientFinder.java index 8ebe56b3a..4d41c0128 100644 --- a/backend/src/main/java/mouda/backend/moim/implement/finder/ChatRecipientFinder.java +++ b/backend/src/main/java/mouda/backend/chat/implement/sender/ChatRecipientFinder.java @@ -1,4 +1,4 @@ -package mouda.backend.moim.implement.finder; +package mouda.backend.chat.implement.sender; import java.util.List; import java.util.stream.Stream; diff --git a/backend/src/main/java/mouda/backend/common/config/data/DataSourceConfiguration.java b/backend/src/main/java/mouda/backend/common/config/data/DataSourceConfiguration.java index 6b9ce635f..b77504c0b 100644 --- a/backend/src/main/java/mouda/backend/common/config/data/DataSourceConfiguration.java +++ b/backend/src/main/java/mouda/backend/common/config/data/DataSourceConfiguration.java @@ -37,7 +37,6 @@ public LocalContainerEntityManagerFactoryBean entityManagerFactory( return builder.dataSource(dataSource) .properties(properties) - .packages("mouda.backend.*.domain") .build(); } diff --git a/backend/src/main/java/mouda/backend/moim/business/ChatService.java b/backend/src/main/java/mouda/backend/moim/business/ChatService.java deleted file mode 100644 index 8ec9fd510..000000000 --- a/backend/src/main/java/mouda/backend/moim/business/ChatService.java +++ /dev/null @@ -1,114 +0,0 @@ -package mouda.backend.moim.business; - -import java.util.List; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import lombok.RequiredArgsConstructor; -import mouda.backend.darakbangmember.domain.DarakbangMember; -import mouda.backend.moim.domain.Chamyo; -import mouda.backend.moim.domain.Chat; -import mouda.backend.moim.domain.ChatRooms; -import mouda.backend.moim.domain.ChatWithAuthor; -import mouda.backend.moim.domain.Chats; -import mouda.backend.moim.domain.Moim; -import mouda.backend.moim.domain.MoimChat; -import mouda.backend.moim.implement.finder.ChamyoFinder; -import mouda.backend.moim.implement.finder.ChatFinder; -import mouda.backend.moim.implement.finder.ChatRoomFinder; -import mouda.backend.moim.implement.finder.MoimFinder; -import mouda.backend.moim.implement.sender.OldChatNotificationSender; -import mouda.backend.moim.implement.validator.ChamyoValidator; -import mouda.backend.moim.implement.writer.ChatWriter; -import mouda.backend.moim.implement.writer.MoimWriter; -import mouda.backend.moim.presentation.request.chat.OldChatCreateRequest; -import mouda.backend.moim.presentation.request.chat.OldDateTimeConfirmRequest; -import mouda.backend.moim.presentation.request.chat.OldLastReadChatRequest; -import mouda.backend.moim.presentation.request.chat.OldPlaceConfirmRequest; -import mouda.backend.moim.presentation.response.chat.OldChatFindUnloadedResponse; -import mouda.backend.moim.presentation.response.chat.OldChatPreviewResponses; -import mouda.backend.notification.domain.NotificationType; - -@Transactional -@Service(value = "oldChatService") -@RequiredArgsConstructor -public class ChatService { - - private final MoimFinder moimFinder; - private final MoimWriter moimWriter; - private final ChatFinder chatFinder; - private final ChatWriter chatWriter; - private final ChamyoValidator chamyoValidator; - private final ChamyoFinder chamyoFinder; - private final ChatRoomFinder chatRoomFinder; - private final OldChatNotificationSender oldChatNotificationSender; - - public void createChat(long darakbangId, OldChatCreateRequest oldChatCreateRequest, DarakbangMember darakbangMember) { - Moim moim = moimFinder.read(oldChatCreateRequest.moimId(), darakbangId); - chamyoValidator.validateMemberChamyoMoim(moim, darakbangMember); - - Chat chat = oldChatCreateRequest.toEntity(moim, darakbangMember); - chatWriter.save(chat); - - oldChatNotificationSender.sendChatNotification(chat, darakbangMember, NotificationType.NEW_CHAT); - } - - @Transactional(readOnly = true) - public OldChatFindUnloadedResponse findUnloadedChats( - long darakbangId, long recentChatId, long moimId, DarakbangMember darakbangMember - ) { - Moim moim = moimFinder.read(moimId, darakbangId); - chamyoValidator.validateMemberChamyoMoim(moim, darakbangMember); - - Chats chats = chatFinder.readAllUnloadedChats(moimId, recentChatId); - List chatWithAuthors = chats.getChatsWithAuthor(darakbangMember); - - return OldChatFindUnloadedResponse.toResponse(chatWithAuthors); - } - - public void confirmPlace( - long darakbangId, OldPlaceConfirmRequest request, DarakbangMember darakbangMember - ) { - Moim moim = moimFinder.read(request.moimId(), darakbangId); - moimWriter.confirmPlace(moim, darakbangMember, request.place()); - - Chat chat = request.toEntity(moim, darakbangMember); - chatWriter.save(chat); - - oldChatNotificationSender.sendChatNotification(chat, darakbangMember, NotificationType.MOIM_PLACE_CONFIRMED); - } - - public void confirmDateTime( - long darakbangId, OldDateTimeConfirmRequest request, DarakbangMember darakbangMember - ) { - Moim moim = moimFinder.read(request.moimId(), darakbangId); - moimWriter.confirmDateTime(moim, darakbangMember, request.date(), request.time()); - - Chat chat = request.toEntity(moim, darakbangMember); - chatWriter.save(chat); - - oldChatNotificationSender.sendChatNotification(chat, darakbangMember, NotificationType.MOIM_TIME_CONFIRMED); - } - - public OldChatPreviewResponses findChatPreview(long darakbangId, DarakbangMember darakbangMember) { - ChatRooms chatRooms = chatRoomFinder.findAllOrderByLastChat(darakbangId, darakbangMember); - List moimChats = chatRooms.getMoimChats(); - - return OldChatPreviewResponses.toResponse(moimChats); - } - - public void createLastChat( - long darakbangId, long moimId, OldLastReadChatRequest oldLastReadChatRequest, DarakbangMember darakbangMember - ) { - Moim moim = moimFinder.read(moimId, darakbangId); - Chamyo chamyo = chamyoFinder.read(moim, darakbangMember); - - chamyo.updateLastChat(oldLastReadChatRequest.lastReadChatId()); - } - - public void openChatRoom(Long darakbangId, Long moimId, DarakbangMember darakbangMember) { - Moim moim = moimFinder.read(moimId, darakbangId); - moimWriter.openChatByMoimer(moim, darakbangMember); - } -} diff --git a/backend/src/main/java/mouda/backend/moim/domain/Chat.java b/backend/src/main/java/mouda/backend/moim/domain/Chat.java deleted file mode 100644 index b79710591..000000000 --- a/backend/src/main/java/mouda/backend/moim/domain/Chat.java +++ /dev/null @@ -1,61 +0,0 @@ -package mouda.backend.moim.domain; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; - -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import mouda.backend.darakbangmember.domain.DarakbangMember; - -@Entity -@Getter -@NoArgsConstructor -public class Chat { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - private String content; - - @ManyToOne - private Moim moim; - - @ManyToOne - private DarakbangMember darakbangMember; - - private LocalDate date; - - private LocalTime time; - - @Enumerated(EnumType.STRING) - private ChatType chatType; - - @Builder - public Chat(String content, Moim moim, DarakbangMember darakbangMember, LocalDate date, LocalTime time, - ChatType chatType) { - this.content = content; - this.moim = moim; - this.darakbangMember = darakbangMember; - this.date = date; - this.time = time; - this.chatType = chatType; - } - - public boolean isMyMessage(long darakbangMemberId) { - return darakbangMemberId == darakbangMember.getId(); - } - - public LocalDateTime getDateTime() { - return LocalDateTime.of(date, time); - } -} diff --git a/backend/src/main/java/mouda/backend/moim/domain/ChatRoom.java b/backend/src/main/java/mouda/backend/moim/domain/ChatRoom.java deleted file mode 100644 index 73770a88a..000000000 --- a/backend/src/main/java/mouda/backend/moim/domain/ChatRoom.java +++ /dev/null @@ -1,50 +0,0 @@ -package mouda.backend.moim.domain; - -import java.time.LocalDateTime; -import java.util.Comparator; -import java.util.List; - -public class ChatRoom implements Comparable { - - private final Chamyo chamyo; - private final List chats; - private final int currentPeople; - - public ChatRoom(Chamyo chamyo, Chat lastChat, int currentPeople) { - this(chamyo, List.of(lastChat), currentPeople); - } - - public ChatRoom(Chamyo chamyo, List chats, int currentPeople) { - this.chamyo = chamyo; - this.chats = chats; - this.currentPeople = currentPeople; - } - - public MoimChat getMoimChat() { - return MoimChat.builder() - .chamyo(chamyo) - .lastContent(getLastChatContent()) - .currentPeople(currentPeople) - .build(); - } - - private LocalDateTime getLastChatDateTime() { - return getLastChat().getDateTime(); - } - - private String getLastChatContent() { - return getLastChat().getContent(); - } - - private Chat getLastChat() { - return chats.get(chats.size() - 1); - } - - @Override - public int compareTo(ChatRoom that) { - Comparator chatRoomComparator = Comparator.comparing(ChatRoom::getLastChatDateTime, - Comparator.nullsLast(Comparator.reverseOrder())) - .thenComparing(chatRoom -> chatRoom.chamyo.getMoim().getId()); - return chatRoomComparator.compare(this, that); - } -} diff --git a/backend/src/main/java/mouda/backend/moim/domain/ChatRooms.java b/backend/src/main/java/mouda/backend/moim/domain/ChatRooms.java deleted file mode 100644 index 7f1bcc239..000000000 --- a/backend/src/main/java/mouda/backend/moim/domain/ChatRooms.java +++ /dev/null @@ -1,18 +0,0 @@ -package mouda.backend.moim.domain; - -import java.util.List; - -public class ChatRooms { - - private final List chatRooms; - - public ChatRooms(List chatRooms) { - this.chatRooms = chatRooms; - } - - public List getMoimChats() { - return chatRooms.stream() - .map(ChatRoom::getMoimChat) - .toList(); - } -} diff --git a/backend/src/main/java/mouda/backend/moim/domain/ChatType.java b/backend/src/main/java/mouda/backend/moim/domain/ChatType.java deleted file mode 100644 index 777f0f6fa..000000000 --- a/backend/src/main/java/mouda/backend/moim/domain/ChatType.java +++ /dev/null @@ -1,6 +0,0 @@ -package mouda.backend.moim.domain; - -public enum ChatType { - - BASIC, PLACE, DATETIME -} diff --git a/backend/src/main/java/mouda/backend/moim/domain/ChatWithAuthor.java b/backend/src/main/java/mouda/backend/moim/domain/ChatWithAuthor.java deleted file mode 100644 index a3b501dec..000000000 --- a/backend/src/main/java/mouda/backend/moim/domain/ChatWithAuthor.java +++ /dev/null @@ -1,15 +0,0 @@ -package mouda.backend.moim.domain; - -import lombok.Getter; - -@Getter -public class ChatWithAuthor { - - private final Chat chat; - private final boolean isMine; - - public ChatWithAuthor(Chat chat, boolean isMine) { - this.chat = chat; - this.isMine = isMine; - } -} diff --git a/backend/src/main/java/mouda/backend/moim/domain/Chats.java b/backend/src/main/java/mouda/backend/moim/domain/Chats.java deleted file mode 100644 index 8bbf683c1..000000000 --- a/backend/src/main/java/mouda/backend/moim/domain/Chats.java +++ /dev/null @@ -1,20 +0,0 @@ -package mouda.backend.moim.domain; - -import java.util.List; - -import mouda.backend.darakbangmember.domain.DarakbangMember; - -public class Chats { - - private final List chats; - - public Chats(List chats) { - this.chats = chats; - } - - public List getChatsWithAuthor(DarakbangMember darakbangMember) { - return chats.stream() - .map(chat -> new ChatWithAuthor(chat, chat.isMyMessage(darakbangMember.getId()))) - .toList(); - } -} diff --git a/backend/src/main/java/mouda/backend/moim/domain/EmptyChat.java b/backend/src/main/java/mouda/backend/moim/domain/EmptyChat.java deleted file mode 100644 index 292bf0859..000000000 --- a/backend/src/main/java/mouda/backend/moim/domain/EmptyChat.java +++ /dev/null @@ -1,27 +0,0 @@ -package mouda.backend.moim.domain; - -import java.time.LocalDateTime; - -public class EmptyChat extends Chat { - - private Long moimId; - - public EmptyChat(long moimId) { - super(); - this.moimId = moimId; - } - - public Long getMoimId() { - return moimId; - } - - @Override - public String getContent() { - return ""; - } - - @Override - public LocalDateTime getDateTime() { - return null; - } -} diff --git a/backend/src/main/java/mouda/backend/moim/domain/MoimChat.java b/backend/src/main/java/mouda/backend/moim/domain/MoimChat.java deleted file mode 100644 index c0f9a3f94..000000000 --- a/backend/src/main/java/mouda/backend/moim/domain/MoimChat.java +++ /dev/null @@ -1,23 +0,0 @@ -package mouda.backend.moim.domain; - -import lombok.Builder; -import lombok.Getter; - -@Getter -public class MoimChat { - - private final Chamyo chamyo; - private final int currentPeople; - private final String lastContent; - - @Builder - public MoimChat( - Chamyo chamyo, - int currentPeople, - String lastContent - ) { - this.chamyo = chamyo; - this.currentPeople = currentPeople; - this.lastContent = lastContent; - } -} diff --git a/backend/src/main/java/mouda/backend/moim/exception/ChatErrorMessage.java b/backend/src/main/java/mouda/backend/moim/exception/ChatErrorMessage.java deleted file mode 100644 index d93b44286..000000000 --- a/backend/src/main/java/mouda/backend/moim/exception/ChatErrorMessage.java +++ /dev/null @@ -1,19 +0,0 @@ -package mouda.backend.moim.exception; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public enum ChatErrorMessage { - - MOIM_NOT_FOUND("모임이 존재하지 않습니다."), - INVALID_RECENT_CHAT_ID("최근 조회된 채팅 아이디를 잘 못 입력하였습니다."), - NOT_PARTICIPANT_TO_SEND("모임에 참여한 회원만 채팅을 보낼 수 있습니다."), - NOT_PARTICIPANT_TO_FIND("모임에 참여한 회원만 채팅을 조회할 수 있습니다."), - MOIMER_CAN_CONFIRM_PLACE("모이머만 모임 장소를 확정할 수 있습니다."), - MOIMER_CAN_CONFIRM_DATETIME("모이머만 날짜와 시간을 확정할 수 있습니다."), - NO_PERMISSION_OPEN_CHAT("채팅은 모이머만 열 수 있습니다"); - - private final String message; -} diff --git a/backend/src/main/java/mouda/backend/moim/exception/ChatException.java b/backend/src/main/java/mouda/backend/moim/exception/ChatException.java deleted file mode 100644 index 9391cff8d..000000000 --- a/backend/src/main/java/mouda/backend/moim/exception/ChatException.java +++ /dev/null @@ -1,12 +0,0 @@ -package mouda.backend.moim.exception; - -import org.springframework.http.HttpStatus; - -import mouda.backend.common.exception.MoudaException; - -public class ChatException extends MoudaException { - - public ChatException(HttpStatus httpStatus, ChatErrorMessage chatErrorMessage) { - super(httpStatus, chatErrorMessage.getMessage()); - } -} diff --git a/backend/src/main/java/mouda/backend/moim/implement/finder/ChatFinder.java b/backend/src/main/java/mouda/backend/moim/implement/finder/ChatFinder.java deleted file mode 100644 index a24effe71..000000000 --- a/backend/src/main/java/mouda/backend/moim/implement/finder/ChatFinder.java +++ /dev/null @@ -1,34 +0,0 @@ -package mouda.backend.moim.implement.finder; - -import java.util.List; - -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Component; - -import lombok.RequiredArgsConstructor; -import mouda.backend.moim.domain.Chat; -import mouda.backend.moim.domain.Chats; -import mouda.backend.moim.domain.EmptyChat; -import mouda.backend.moim.exception.ChatErrorMessage; -import mouda.backend.moim.exception.ChatException; -import mouda.backend.moim.infrastructure.ChatRepository; - -@Component -@RequiredArgsConstructor -public class ChatFinder { - - private final ChatRepository chatRepository; - - public Chats readAllUnloadedChats(long moimId, long recentChatId) { - if (recentChatId < 0) { - throw new ChatException(HttpStatus.BAD_REQUEST, ChatErrorMessage.INVALID_RECENT_CHAT_ID); - } - List chats = chatRepository.findAllUnloadedChats(moimId, recentChatId); - return new Chats(chats); - } - - public Chat readLastChat(long moimId) { - return chatRepository.findFirstByMoimIdOrderByIdDesc(moimId) - .orElse(new EmptyChat(moimId)); - } -} diff --git a/backend/src/main/java/mouda/backend/moim/implement/finder/ChatRoomFinder.java b/backend/src/main/java/mouda/backend/moim/implement/finder/ChatRoomFinder.java deleted file mode 100644 index 73af4fa73..000000000 --- a/backend/src/main/java/mouda/backend/moim/implement/finder/ChatRoomFinder.java +++ /dev/null @@ -1,35 +0,0 @@ -package mouda.backend.moim.implement.finder; - -import java.util.List; - -import org.springframework.stereotype.Component; - -import lombok.RequiredArgsConstructor; -import mouda.backend.darakbangmember.domain.DarakbangMember; -import mouda.backend.moim.domain.Chamyo; -import mouda.backend.moim.domain.Chat; -import mouda.backend.moim.domain.ChatRoom; -import mouda.backend.moim.domain.ChatRooms; - -@Component("oldChatRoomFinder") -@RequiredArgsConstructor -public class ChatRoomFinder { - - private final ChamyoFinder chamyoFinder; - private final ChatFinder chatFinder; - private final MoimFinder moimFinder; - - public ChatRooms findAllOrderByLastChat(long darakbangId, DarakbangMember darakbangMember) { - List chatRooms = chamyoFinder.readAllChatOpened(darakbangId, darakbangMember).stream() - .map(this::createChatRoom) - .sorted() - .toList(); - return new ChatRooms(chatRooms); - } - - private ChatRoom createChatRoom(Chamyo chamyo) { - Chat lastChat = chatFinder.readLastChat(chamyo.getMoim().getId()); - int currentPeople = moimFinder.countCurrentPeople(chamyo.getMoim()); - return new ChatRoom(chamyo, lastChat, currentPeople); - } -} diff --git a/backend/src/main/java/mouda/backend/moim/implement/sender/OldChatNotificationSender.java b/backend/src/main/java/mouda/backend/moim/implement/sender/OldChatNotificationSender.java deleted file mode 100644 index 15e6149cd..000000000 --- a/backend/src/main/java/mouda/backend/moim/implement/sender/OldChatNotificationSender.java +++ /dev/null @@ -1,82 +0,0 @@ -package mouda.backend.moim.implement.sender; - -import java.util.List; - -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Component; - -import mouda.backend.common.config.UrlConfig; -import mouda.backend.darakbangmember.domain.DarakbangMember; -import mouda.backend.moim.domain.Chat; -import mouda.backend.moim.domain.Moim; -import mouda.backend.moim.implement.finder.ChatRecipientFinder; -import mouda.backend.notification.domain.NotificationEvent; -import mouda.backend.notification.domain.NotificationType; -import mouda.backend.notification.domain.Recipient; -import mouda.backend.notification.exception.NotificationErrorMessage; -import mouda.backend.notification.exception.NotificationException; - -@Component -public class OldChatNotificationSender extends AbstractMoimNotificationSender { - - private final ChatRecipientFinder chatRecipientFinder; - private final ApplicationEventPublisher eventPublisher; - - public OldChatNotificationSender(UrlConfig urlConfig, ChatRecipientFinder chatRecipientFinder, - ApplicationEventPublisher eventPublisher) { - super(urlConfig); - this.chatRecipientFinder = chatRecipientFinder; - this.eventPublisher = eventPublisher; - } - - public void sendChatNotification(Chat chat, DarakbangMember sender, NotificationType notificationType) { - Moim moim = chat.getMoim(); - List recipients = chatRecipientFinder.getMoimChatNotificationRecipients(moim.getId(), sender); - NotificationEvent notificationEvent = createNotificationEvent(chat, notificationType, recipients); - - eventPublisher.publishEvent(notificationEvent); - } - - private NotificationEvent createNotificationEvent( - Chat chat, - NotificationType notificationType, - List recipients - ) { - Moim moim = chat.getMoim(); - - return NotificationEvent.chatEvent( - notificationType, - moim.getTitle(), - ChatNotificationMessage.create(chat, notificationType), - getChatRoomUrl(moim.getDarakbangId(), moim.getId()), - recipients, - moim.getDarakbangId(), - moim.getId() - ); - } - - static class ChatNotificationMessage { - - public static String create(Chat chat, NotificationType type) { - if (type.isConfirmedType()) { - return confirmedChatMessage(chat, type); - } - if (type == NotificationType.NEW_CHAT) { - DarakbangMember sender = chat.getDarakbangMember(); - return sender.getNickname() + ": " + chat.getContent(); - } - throw new NotificationException( - HttpStatus.BAD_REQUEST, NotificationErrorMessage.NOT_ALLOWED_NOTIFICATION_TYPE - ); - } - - private static String confirmedChatMessage(Chat chat, NotificationType type) { - String moimName = chat.getMoim().getTitle(); - if (type == NotificationType.MOIM_PLACE_CONFIRMED) { - return moimName + " 모임 장소가 확정되었어요!"; - } - return moimName + " 모임 시간이 확정되었어요!"; - } - } -} diff --git a/backend/src/main/java/mouda/backend/moim/implement/validator/ChatValidator.java b/backend/src/main/java/mouda/backend/moim/implement/validator/ChatValidator.java deleted file mode 100644 index 8d92cac6d..000000000 --- a/backend/src/main/java/mouda/backend/moim/implement/validator/ChatValidator.java +++ /dev/null @@ -1,10 +0,0 @@ -package mouda.backend.moim.implement.validator; - -import org.springframework.stereotype.Component; - -import lombok.RequiredArgsConstructor; - -@Component -@RequiredArgsConstructor -public class ChatValidator { -} diff --git a/backend/src/main/java/mouda/backend/moim/implement/writer/ChatWriter.java b/backend/src/main/java/mouda/backend/moim/implement/writer/ChatWriter.java deleted file mode 100644 index d20c2a752..000000000 --- a/backend/src/main/java/mouda/backend/moim/implement/writer/ChatWriter.java +++ /dev/null @@ -1,18 +0,0 @@ -package mouda.backend.moim.implement.writer; - -import org.springframework.stereotype.Component; - -import lombok.RequiredArgsConstructor; -import mouda.backend.moim.domain.Chat; -import mouda.backend.moim.infrastructure.ChatRepository; - -@Component("oldChatWriter") -@RequiredArgsConstructor -public class ChatWriter { - - private final ChatRepository chatRepository; - - public Chat save(Chat chat) { - return chatRepository.save(chat); - } -} diff --git a/backend/src/main/java/mouda/backend/moim/infrastructure/ChatRepository.java b/backend/src/main/java/mouda/backend/moim/infrastructure/ChatRepository.java deleted file mode 100644 index a49b57cf3..000000000 --- a/backend/src/main/java/mouda/backend/moim/infrastructure/ChatRepository.java +++ /dev/null @@ -1,20 +0,0 @@ -package mouda.backend.moim.infrastructure; - -import java.util.List; -import java.util.Optional; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; -import org.springframework.stereotype.Repository; - -import mouda.backend.moim.domain.Chat; - -@Repository(value = "oldChatRepository") -public interface ChatRepository extends JpaRepository { - - @Query("SELECT c FROM Chat c WHERE c.moim.id = :moimId AND c.id > :chatId") - List findAllUnloadedChats(@Param("moimId") long moimId, @Param("chatId") long chatId); - - Optional findFirstByMoimIdOrderByIdDesc(long moimId); -} diff --git a/backend/src/main/java/mouda/backend/moim/presentation/controller/ChatController.java b/backend/src/main/java/mouda/backend/moim/presentation/controller/ChatController.java deleted file mode 100644 index 3ed0671f4..000000000 --- a/backend/src/main/java/mouda/backend/moim/presentation/controller/ChatController.java +++ /dev/null @@ -1,141 +0,0 @@ -package mouda.backend.moim.presentation.controller; - -import java.util.List; - -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PatchMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import jakarta.validation.Valid; -import lombok.RequiredArgsConstructor; -import mouda.backend.aop.logging.ExceptRequestLogging; -import mouda.backend.chat.business.ChatRoomService; -import mouda.backend.chat.business.ChatService; -import mouda.backend.chat.domain.ChatRoomType; -import mouda.backend.chat.presentation.request.ChatCreateRequest; -import mouda.backend.chat.presentation.request.DateTimeConfirmRequest; -import mouda.backend.chat.presentation.request.LastReadChatRequest; -import mouda.backend.chat.presentation.request.PlaceConfirmRequest; -import mouda.backend.chat.presentation.response.ChatFindUnloadedResponse; -import mouda.backend.chat.presentation.response.ChatPreviewResponses; -import mouda.backend.common.config.argumentresolver.LoginDarakbangMember; -import mouda.backend.common.response.RestResponse; -import mouda.backend.darakbangmember.domain.DarakbangMember; -import mouda.backend.moim.presentation.controller.swagger.ChatSwagger; -import mouda.backend.moim.presentation.request.chat.OldChatCreateRequest; -import mouda.backend.moim.presentation.request.chat.OldDateTimeConfirmRequest; -import mouda.backend.moim.presentation.request.chat.OldLastReadChatRequest; -import mouda.backend.moim.presentation.request.chat.OldPlaceConfirmRequest; -import mouda.backend.moim.presentation.response.chat.ChatPreviewResponse; -import mouda.backend.moim.presentation.response.chat.OldChatPreviewResponses; - -@Deprecated -@RestController("oldChatController") -@RequestMapping("/v1/darakbang/{darakbangId}/chat") -@RequiredArgsConstructor -public class ChatController implements ChatSwagger { - - private final ChatService chatService; - private final ChatRoomService chatRoomService; - - @Override - @PostMapping - public ResponseEntity createChat( - @PathVariable Long darakbangId, - @LoginDarakbangMember DarakbangMember darakbangMember, - @Valid @RequestBody OldChatCreateRequest oldChatCreateRequest - ) { - ChatCreateRequest chatCreateRequest = new ChatCreateRequest(oldChatCreateRequest.content()); - chatService.createChat(darakbangId, oldChatCreateRequest.moimId(), chatCreateRequest, darakbangMember); - - return ResponseEntity.ok().build(); - } - - @Override - @ExceptRequestLogging - @GetMapping - public ResponseEntity> findUnloadedChats( - @PathVariable Long darakbangId, - @LoginDarakbangMember DarakbangMember darakbangMember, - @RequestParam("recentChatId") Long recentChatId, - @RequestParam("moimId") Long moimId - ) { - ChatFindUnloadedResponse unloadedChats = chatService - .findUnloadedChats(darakbangId, recentChatId, moimId, darakbangMember); - - return ResponseEntity.ok(new RestResponse<>(unloadedChats)); - } - - @Override - @GetMapping("/preview") - @ExceptRequestLogging - public ResponseEntity> findChatPreviews( - @PathVariable Long darakbangId, - @LoginDarakbangMember DarakbangMember darakbangMember - ) { - ChatPreviewResponses chatPreviewResponses = chatRoomService.findChatPreview(darakbangMember, ChatRoomType.MOIM); - - List previewResponses = chatPreviewResponses.previews().stream() - .map(chatPreviewResponse -> new ChatPreviewResponse(chatPreviewResponse.chatRoomId(), chatPreviewResponse.title(), chatPreviewResponse.participations().size(), - chatPreviewResponse.isStarted(), - chatPreviewResponse.lastContent(), chatPreviewResponse.lastReadChatId())).toList(); - OldChatPreviewResponses oldChatPreviewResponses = new OldChatPreviewResponses(previewResponses); - return ResponseEntity.ok(new RestResponse<>(oldChatPreviewResponses)); - } - - @Override - @PostMapping("/last") - public ResponseEntity createLastReadChatId( - @PathVariable Long darakbangId, - @LoginDarakbangMember DarakbangMember darakbangMember, - @RequestBody OldLastReadChatRequest oldLastReadChatRequest - ) { - LastReadChatRequest lastReadChatRequest = new LastReadChatRequest(oldLastReadChatRequest.lastReadChatId()); - chatService.updateLastReadChat(darakbangId, oldLastReadChatRequest.moimId(), lastReadChatRequest, darakbangMember); - - return ResponseEntity.ok().build(); - } - - @Override - @PostMapping("/datetime") - public ResponseEntity confirmDateTime( - @PathVariable Long darakbangId, - @LoginDarakbangMember DarakbangMember darakbangMember, - @RequestBody OldDateTimeConfirmRequest oldDateTimeConfirmRequest - ) { - DateTimeConfirmRequest dateTimeConfirmRequest = new DateTimeConfirmRequest(oldDateTimeConfirmRequest.date(), oldDateTimeConfirmRequest.time()); - chatService.confirmDateTime(darakbangId, oldDateTimeConfirmRequest.moimId(), dateTimeConfirmRequest, darakbangMember); - - return ResponseEntity.ok().build(); - } - - @Override - @PostMapping("/place") - public ResponseEntity confirmPlace( - @PathVariable Long darakbangId, - @LoginDarakbangMember DarakbangMember darakbangMember, - @RequestBody OldPlaceConfirmRequest oldPlaceConfirmRequest - ) { - PlaceConfirmRequest placeConfirmRequest = new PlaceConfirmRequest(oldPlaceConfirmRequest.place()); - chatService.confirmPlace(darakbangId, oldPlaceConfirmRequest.moimId(), placeConfirmRequest, darakbangMember); - - return ResponseEntity.ok().build(); - } - - @PatchMapping("/open") - public ResponseEntity openChatRoom( - @PathVariable Long darakbangId, - @LoginDarakbangMember DarakbangMember darakbangMember, - @RequestParam("moimId") Long moimId - ) { - chatRoomService.openChatRoom(darakbangId, moimId, darakbangMember); - - return ResponseEntity.ok().build(); - } -} diff --git a/backend/src/main/java/mouda/backend/moim/presentation/controller/swagger/ChatSwagger.java b/backend/src/main/java/mouda/backend/moim/presentation/controller/swagger/ChatSwagger.java deleted file mode 100644 index c6f938eb2..000000000 --- a/backend/src/main/java/mouda/backend/moim/presentation/controller/swagger/ChatSwagger.java +++ /dev/null @@ -1,92 +0,0 @@ -package mouda.backend.moim.presentation.controller.swagger; - -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import mouda.backend.chat.presentation.response.ChatFindUnloadedResponse; -import mouda.backend.common.config.argumentresolver.LoginDarakbangMember; -import mouda.backend.common.response.RestResponse; -import mouda.backend.darakbangmember.domain.DarakbangMember; -import mouda.backend.moim.presentation.request.chat.OldChatCreateRequest; -import mouda.backend.moim.presentation.request.chat.OldDateTimeConfirmRequest; -import mouda.backend.moim.presentation.request.chat.OldLastReadChatRequest; -import mouda.backend.moim.presentation.request.chat.OldPlaceConfirmRequest; -import mouda.backend.moim.presentation.response.chat.OldChatPreviewResponses; - -public interface ChatSwagger { - - @Operation(summary = "채팅 생성", description = "한 건의 채팅 메시지를 보낸다.") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "채팅 생성 성공!") - }) - ResponseEntity createChat( - @PathVariable Long darakbangId, - @LoginDarakbangMember DarakbangMember member, - @RequestBody OldChatCreateRequest oldChatCreateRequest - ); - - @Operation(summary = "채팅 조회", description = "아직 조회되지 않은 채팅 내역을 조회한다.") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "채팅 조회 성공!") - }) - ResponseEntity> findUnloadedChats( - @PathVariable Long darakbangId, - @LoginDarakbangMember DarakbangMember member, - @RequestParam Long recentChatId, - @RequestParam Long moimId - ); - - @Operation(summary = "장소 확정", description = "작성자가 장소를 확정하는 채팅을 전송합니다.") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "장소 확정 성공!") - }) - ResponseEntity confirmPlace( - @PathVariable Long darakbangId, - @LoginDarakbangMember DarakbangMember member, - @RequestBody OldPlaceConfirmRequest oldPlaceConfirmRequest - ); - - @Operation(summary = "날짜 시간 확정", description = "작성자가 날짜와 시간을 확정하는 채팅을 전송합니다.") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "날짜 시간 확정 성공!") - }) - ResponseEntity confirmDateTime( - @PathVariable Long darakbangId, - @LoginDarakbangMember DarakbangMember member, - @RequestBody OldDateTimeConfirmRequest oldDateTimeConfirmRequest - ); - - @Operation(summary = "채팅방 목록 조회", description = "채팅방 목록을 조회한다.") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "채팅방 조회 성공!") - }) - ResponseEntity> findChatPreviews( - @PathVariable Long darakbangId, - @LoginDarakbangMember DarakbangMember member - ); - - @Operation(summary = "마지막 읽은 채팅 저장", description = "마지막 읽은 채팅을 저장한다.") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "마지막 채팅 저장 성공!") - }) - ResponseEntity createLastReadChatId( - @PathVariable Long darakbangId, - @LoginDarakbangMember DarakbangMember member, - @RequestBody OldLastReadChatRequest oldLastReadChatRequest - ); - - @Operation(summary = "채팅방 열기", description = "채팅방을 연다!") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "채팅방 열기 성공!") - }) - ResponseEntity openChatRoom( - @PathVariable Long darakbangId, - @LoginDarakbangMember DarakbangMember member, - @RequestParam("moimId") Long moimId - ); -} diff --git a/backend/src/main/java/mouda/backend/moim/presentation/request/chat/OldChatCreateRequest.java b/backend/src/main/java/mouda/backend/moim/presentation/request/chat/OldChatCreateRequest.java deleted file mode 100644 index 9cffa42e5..000000000 --- a/backend/src/main/java/mouda/backend/moim/presentation/request/chat/OldChatCreateRequest.java +++ /dev/null @@ -1,30 +0,0 @@ -package mouda.backend.moim.presentation.request.chat; - -import java.time.LocalDate; -import java.time.LocalTime; - -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; -import mouda.backend.darakbangmember.domain.DarakbangMember; -import mouda.backend.moim.domain.Chat; -import mouda.backend.moim.domain.ChatType; -import mouda.backend.moim.domain.Moim; - -public record OldChatCreateRequest( - @NotNull - Long moimId, - - @NotBlank - String content -) { - public Chat toEntity(Moim moim, DarakbangMember darakbangMember) { - return Chat.builder() - .content(content) - .date(LocalDate.now()) - .time(LocalTime.now()) - .darakbangMember(darakbangMember) - .moim(moim) - .chatType(ChatType.BASIC) - .build(); - } -} diff --git a/backend/src/main/java/mouda/backend/moim/presentation/request/chat/OldDateTimeConfirmRequest.java b/backend/src/main/java/mouda/backend/moim/presentation/request/chat/OldDateTimeConfirmRequest.java deleted file mode 100644 index 255521c0f..000000000 --- a/backend/src/main/java/mouda/backend/moim/presentation/request/chat/OldDateTimeConfirmRequest.java +++ /dev/null @@ -1,32 +0,0 @@ -package mouda.backend.moim.presentation.request.chat; - -import java.time.LocalDate; -import java.time.LocalTime; - -import jakarta.validation.constraints.NotNull; -import mouda.backend.darakbangmember.domain.DarakbangMember; -import mouda.backend.moim.domain.Chat; -import mouda.backend.moim.domain.ChatType; -import mouda.backend.moim.domain.Moim; - -public record OldDateTimeConfirmRequest( - @NotNull - Long moimId, - - @NotNull - LocalDate date, - - @NotNull - LocalTime time -) { - public Chat toEntity(Moim moim, DarakbangMember darakbangMember) { - return Chat.builder() - .content(date.toString() + " " + time.toString()) - .moim(moim) - .date(LocalDate.now()) - .time(LocalTime.now()) - .darakbangMember(darakbangMember) - .chatType(ChatType.DATETIME) - .build(); - } -} diff --git a/backend/src/main/java/mouda/backend/moim/presentation/request/chat/OldLastReadChatRequest.java b/backend/src/main/java/mouda/backend/moim/presentation/request/chat/OldLastReadChatRequest.java deleted file mode 100644 index 7344ba2dd..000000000 --- a/backend/src/main/java/mouda/backend/moim/presentation/request/chat/OldLastReadChatRequest.java +++ /dev/null @@ -1,12 +0,0 @@ -package mouda.backend.moim.presentation.request.chat; - -import jakarta.validation.constraints.NotNull; - -public record OldLastReadChatRequest( - @NotNull - Long moimId, - - @NotNull - Long lastReadChatId -) { -} diff --git a/backend/src/main/java/mouda/backend/moim/presentation/request/chat/OldPlaceConfirmRequest.java b/backend/src/main/java/mouda/backend/moim/presentation/request/chat/OldPlaceConfirmRequest.java deleted file mode 100644 index 2e7cb5a47..000000000 --- a/backend/src/main/java/mouda/backend/moim/presentation/request/chat/OldPlaceConfirmRequest.java +++ /dev/null @@ -1,30 +0,0 @@ -package mouda.backend.moim.presentation.request.chat; - -import java.time.LocalDate; -import java.time.LocalTime; - -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; -import mouda.backend.darakbangmember.domain.DarakbangMember; -import mouda.backend.moim.domain.Chat; -import mouda.backend.moim.domain.ChatType; -import mouda.backend.moim.domain.Moim; - -public record OldPlaceConfirmRequest( - @NotNull - Long moimId, - - @NotBlank - String place -) { - public Chat toEntity(Moim moim, DarakbangMember darakbangMember) { - return Chat.builder() - .content(place) - .moim(moim) - .date(LocalDate.now()) - .time(LocalTime.now()) - .darakbangMember(darakbangMember) - .chatType(ChatType.PLACE) - .build(); - } -} diff --git a/backend/src/main/java/mouda/backend/moim/presentation/response/chat/ChatFindDetailResponse.java b/backend/src/main/java/mouda/backend/moim/presentation/response/chat/ChatFindDetailResponse.java deleted file mode 100644 index 4e5edc2a7..000000000 --- a/backend/src/main/java/mouda/backend/moim/presentation/response/chat/ChatFindDetailResponse.java +++ /dev/null @@ -1,33 +0,0 @@ -package mouda.backend.moim.presentation.response.chat; - -import java.time.LocalDate; -import java.time.LocalTime; - -import lombok.Builder; -import mouda.backend.moim.domain.Chat; -import mouda.backend.moim.domain.ChatType; -import mouda.backend.moim.domain.ChatWithAuthor; - -@Builder -public record ChatFindDetailResponse( - long chatId, - String content, - boolean isMyMessage, - String nickname, - LocalDate date, - LocalTime time, - ChatType chatType -) { - public static ChatFindDetailResponse toResponse(ChatWithAuthor chatWithAuthor) { - Chat chat = chatWithAuthor.getChat(); - return ChatFindDetailResponse.builder() - .chatId(chat.getId()) - .content(chat.getContent()) - .isMyMessage(chatWithAuthor.isMine()) - .nickname(chat.getDarakbangMember().getNickname()) - .date(chat.getDate()) - .time(chat.getTime()) - .chatType(chat.getChatType()) - .build(); - } -} diff --git a/backend/src/main/java/mouda/backend/moim/presentation/response/chat/ChatPreviewResponse.java b/backend/src/main/java/mouda/backend/moim/presentation/response/chat/ChatPreviewResponse.java deleted file mode 100644 index ac16313b0..000000000 --- a/backend/src/main/java/mouda/backend/moim/presentation/response/chat/ChatPreviewResponse.java +++ /dev/null @@ -1,31 +0,0 @@ -package mouda.backend.moim.presentation.response.chat; - -import lombok.Builder; -import mouda.backend.moim.domain.Chamyo; -import mouda.backend.moim.domain.Moim; -import mouda.backend.moim.domain.MoimChat; - -@Builder -public record ChatPreviewResponse( - Long moimId, - String title, - int currentPeople, - boolean isStarted, - String lastContent, - long lastReadChatId -) { - - public static ChatPreviewResponse toResponse(MoimChat moimChat) { - Chamyo chamyo = moimChat.getChamyo(); - Moim moim = chamyo.getMoim(); - - return ChatPreviewResponse.builder() - .moimId(moim.getId()) - .title(moim.getTitle()) - .currentPeople(moimChat.getCurrentPeople()) - .isStarted(moim.isPastMoim()) - .lastContent(moimChat.getLastContent()) - .lastReadChatId(chamyo.getLastReadChatId()) - .build(); - } -} diff --git a/backend/src/main/java/mouda/backend/moim/presentation/response/chat/OldChatFindUnloadedResponse.java b/backend/src/main/java/mouda/backend/moim/presentation/response/chat/OldChatFindUnloadedResponse.java deleted file mode 100644 index 433819e27..000000000 --- a/backend/src/main/java/mouda/backend/moim/presentation/response/chat/OldChatFindUnloadedResponse.java +++ /dev/null @@ -1,16 +0,0 @@ -package mouda.backend.moim.presentation.response.chat; - -import java.util.List; - -import mouda.backend.moim.domain.ChatWithAuthor; - -public record OldChatFindUnloadedResponse( - List chats -) { - public static OldChatFindUnloadedResponse toResponse(List chatWithAuthors) { - List responses = chatWithAuthors.stream() - .map(ChatFindDetailResponse::toResponse) - .toList(); - return new OldChatFindUnloadedResponse(responses); - } -} diff --git a/backend/src/main/java/mouda/backend/moim/presentation/response/chat/OldChatPreviewResponses.java b/backend/src/main/java/mouda/backend/moim/presentation/response/chat/OldChatPreviewResponses.java deleted file mode 100644 index 0a733183d..000000000 --- a/backend/src/main/java/mouda/backend/moim/presentation/response/chat/OldChatPreviewResponses.java +++ /dev/null @@ -1,16 +0,0 @@ -package mouda.backend.moim.presentation.response.chat; - -import java.util.List; - -import mouda.backend.moim.domain.MoimChat; - -public record OldChatPreviewResponses( - List chatPreviewResponses -) { - public static OldChatPreviewResponses toResponse(List moimChats) { - List chatPreviews = moimChats.stream() - .map(ChatPreviewResponse::toResponse) - .toList(); - return new OldChatPreviewResponses(chatPreviews); - } -} diff --git a/backend/src/test/java/mouda/backend/moim/implement/finder/ChatRecipientFinderTest.java b/backend/src/test/java/mouda/backend/chat/implement/ChatRecipientFinderTest.java similarity index 93% rename from backend/src/test/java/mouda/backend/moim/implement/finder/ChatRecipientFinderTest.java rename to backend/src/test/java/mouda/backend/chat/implement/ChatRecipientFinderTest.java index 2fdbd6fa2..83bdc6419 100644 --- a/backend/src/test/java/mouda/backend/moim/implement/finder/ChatRecipientFinderTest.java +++ b/backend/src/test/java/mouda/backend/chat/implement/ChatRecipientFinderTest.java @@ -1,4 +1,4 @@ -package mouda.backend.moim.implement.finder; +package mouda.backend.chat.implement; import static org.assertj.core.api.Assertions.*; @@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import mouda.backend.chat.implement.sender.ChatRecipientFinder; import mouda.backend.common.fixture.DarakbangSetUp; import mouda.backend.common.fixture.MoimFixture; import mouda.backend.moim.domain.Moim; diff --git a/backend/src/test/java/mouda/backend/common/fixture/ChatFixture.java b/backend/src/test/java/mouda/backend/common/fixture/ChatFixture.java deleted file mode 100644 index 3b7c5e82e..000000000 --- a/backend/src/test/java/mouda/backend/common/fixture/ChatFixture.java +++ /dev/null @@ -1,23 +0,0 @@ -package mouda.backend.common.fixture; - -import java.time.LocalDate; -import java.time.LocalTime; - -import mouda.backend.darakbangmember.domain.DarakbangMember; -import mouda.backend.moim.domain.Chat; -import mouda.backend.moim.domain.ChatType; -import mouda.backend.moim.domain.Moim; - -public class ChatFixture { - - public static Chat getChatWithMemberAtMoim(DarakbangMember darakbangMember, Moim moim) { - return Chat.builder() - .time(LocalTime.now()) - .date(LocalDate.now()) - .content("안녕하쎄요") - .darakbangMember(darakbangMember) - .moim(moim) - .chatType(ChatType.BASIC) - .build(); - } -}