From 1d64320796531b7d513c5c87d4927bc662499889 Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Sun, 26 May 2024 21:53:25 +0900 Subject: [PATCH 01/20] =?UTF-8?q?feat:=20=EC=95=8C=EB=A6=BC=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20DTO,=20=EC=B6=94=EC=83=81=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EB=A1=9C=20=EC=A0=84=ED=99=98(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 알림 응답에 공통으로 포함되는 데이터 정의 - 해당 클래스를 상속 받아 부가적인 데이터를 포함한 알림 응답 DTO 구현 --- .../dto/response/NotificationResponse.java | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/be/src/main/java/yeonba/be/notification/dto/response/NotificationResponse.java b/be/src/main/java/yeonba/be/notification/dto/response/NotificationResponse.java index a67469b4..59e760c7 100644 --- a/be/src/main/java/yeonba/be/notification/dto/response/NotificationResponse.java +++ b/be/src/main/java/yeonba/be/notification/dto/response/NotificationResponse.java @@ -4,20 +4,18 @@ import java.time.LocalDateTime; import lombok.AllArgsConstructor; import lombok.Getter; -import yeonba.be.notification.entity.Notification; -import yeonba.be.user.entity.User; @Getter @AllArgsConstructor -public class NotificationResponse { +public abstract class NotificationResponse { @Schema( type = "string", description = """ 알림 타입, 다음 종류 존재 - ARROW_RECEIVED (화살 수신) - - CHAT_REQUESTED (채팅 요청 수신) - - CHAT_REQUEST_ACCEPTED (요청한 채팅 수락됨)""", + - CHATTING_REQUESTED (채팅 요청 수신) + - CHATTING_REQUEST_ACCEPTED (요청한 채팅 수락됨)""", example = "ARROW_RECEIVED") private String notificationType; @@ -50,18 +48,4 @@ public class NotificationResponse { description = "알림 생성 일시", example = "2024-04-10 10:12:00.112233") private LocalDateTime createdAt; - - public static NotificationResponse from(Notification notification) { - - User sender = notification.getSender(); - - return new NotificationResponse( - notification.getType().name(), - notification.getContent(), - sender.getId(), - sender.getRepresentativeProfilePhoto(), - sender.getNickname(), - notification.getCreatedAt() - ); - } } From 3c98bb88bd2946f789dcee98bdc68da8fc0c83bd Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Sun, 26 May 2024 21:54:11 +0900 Subject: [PATCH 02/20] =?UTF-8?q?feat:=20=EB=8B=A8=EC=88=9C=20=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20=EC=9D=91=EB=8B=B5=20DTO=20=EC=B6=94=EA=B0=80(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/SimpleNotificationResponse.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 be/src/main/java/yeonba/be/notification/dto/response/SimpleNotificationResponse.java diff --git a/be/src/main/java/yeonba/be/notification/dto/response/SimpleNotificationResponse.java b/be/src/main/java/yeonba/be/notification/dto/response/SimpleNotificationResponse.java new file mode 100644 index 00000000..56070684 --- /dev/null +++ b/be/src/main/java/yeonba/be/notification/dto/response/SimpleNotificationResponse.java @@ -0,0 +1,34 @@ +package yeonba.be.notification.dto.response; + +import java.time.LocalDateTime; +import yeonba.be.notification.entity.Notification; +import yeonba.be.user.entity.User; + +public class SimpleNotificationResponse extends NotificationResponse { + + public SimpleNotificationResponse( + String notificationType, + String content, + long senderId, + String senderProfilePhotoUrl, + String senderNickname, + LocalDateTime createdAt) { + + super(notificationType, content, senderId, senderProfilePhotoUrl, senderNickname, + createdAt); + } + + public static SimpleNotificationResponse from(Notification notification) { + + User sender = notification.getSender(); + + return new SimpleNotificationResponse( + notification.getType().name(), + notification.getContent(), + sender.getId(), + sender.getRepresentativeProfilePhoto(), + sender.getNickname(), + notification.getCreatedAt() + ); + } +} From 35f56210f9b049ae2fe8eca445fa0ea953567f9a Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Sun, 26 May 2024 21:56:57 +0900 Subject: [PATCH 03/20] =?UTF-8?q?feat:=20=EC=B1=84=ED=8C=85=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20=EC=95=8C=EB=A6=BC=20=EC=9D=91=EB=8B=B5=20DTO=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 채팅 요청 알림의 경우 채팅을 요청한 사용자와의 채팅 가능 여부 포함 --- ...ChattingRequestedNotificationResponse.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 be/src/main/java/yeonba/be/notification/dto/response/ChattingRequestedNotificationResponse.java diff --git a/be/src/main/java/yeonba/be/notification/dto/response/ChattingRequestedNotificationResponse.java b/be/src/main/java/yeonba/be/notification/dto/response/ChattingRequestedNotificationResponse.java new file mode 100644 index 00000000..06f89eb8 --- /dev/null +++ b/be/src/main/java/yeonba/be/notification/dto/response/ChattingRequestedNotificationResponse.java @@ -0,0 +1,49 @@ +package yeonba.be.notification.dto.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import java.time.LocalDateTime; +import lombok.Getter; +import yeonba.be.notification.entity.Notification; +import yeonba.be.user.entity.User; + +@Getter +public class ChattingRequestedNotificationResponse extends NotificationResponse { + + @Schema( + type = "boolean", + description = "채팅 가능 여부", + example = "false") + @JsonProperty("canChat") + private boolean canChat; + + public ChattingRequestedNotificationResponse( + String notificationType, + String content, + long senderId, + String senderProfilePhotoUrl, + String senderNickname, + LocalDateTime createdAt, + boolean canChat) { + + super(notificationType, content, senderId, senderProfilePhotoUrl, senderNickname, + createdAt); + this.canChat = canChat; + } + + public static ChattingRequestedNotificationResponse from(Notification notification, + boolean chattingPossible) { + + User sender = notification.getSender(); + + return new ChattingRequestedNotificationResponse( + notification.getType().name(), + notification.getContent(), + sender.getId(), + sender.getRepresentativeProfilePhoto(), + sender.getNickname(), + notification.getCreatedAt(), + chattingPossible + ); + } +} From e909bb531a8c4c0e537a3b95e504c233caafc4fd Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Sun, 26 May 2024 21:59:10 +0900 Subject: [PATCH 04/20] =?UTF-8?q?feat:=20=EC=9D=91=EB=8B=B5=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=A9=94=EC=84=9C=EB=93=9C,=20=EC=99=B8=EB=B6=80?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=95=8C=EB=A6=BC=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A0=84=EB=8B=AC=EB=B0=9B=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/NotificationPageResponse.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/be/src/main/java/yeonba/be/notification/dto/response/NotificationPageResponse.java b/be/src/main/java/yeonba/be/notification/dto/response/NotificationPageResponse.java index 222b1767..b07a1e0d 100644 --- a/be/src/main/java/yeonba/be/notification/dto/response/NotificationPageResponse.java +++ b/be/src/main/java/yeonba/be/notification/dto/response/NotificationPageResponse.java @@ -43,14 +43,11 @@ public class NotificationPageResponse { @JsonProperty("isLast") private boolean last; - public static NotificationPageResponse from(Page page) { - - List content = page.getContent().stream() - .map(NotificationResponse::from) - .toList(); + public static NotificationPageResponse from(Page page, + List notifications) { return new NotificationPageResponse( - content, + notifications, page.getTotalPages(), page.getTotalElements(), page.isFirst(), From a1424c08b4dfc71b6009c9c7fba38e51c9ae1046 Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Sun, 26 May 2024 21:59:49 +0900 Subject: [PATCH 05/20] =?UTF-8?q?feat:=20=EC=B1=84=ED=8C=85=EB=B0=A9=20?= =?UTF-8?q?=EC=A1=B4=EC=9E=AC=20=EC=97=AC=EB=B6=80=20=ED=99=95=EC=9D=B8=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=A0=95=EC=9D=98(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chatting/repository/chatroom/ChatRoomRepositoryCustom.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepositoryCustom.java b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepositoryCustom.java index 96508a79..843e81ba 100644 --- a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepositoryCustom.java +++ b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepositoryCustom.java @@ -7,4 +7,6 @@ public interface ChatRoomRepositoryCustom { List findAllByUserAndActiveIsTrue(User user); + + boolean existsBy(List users); } From 63267b452b1c33de37e91ed28f15460d85ad3d23 Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Sun, 26 May 2024 22:01:31 +0900 Subject: [PATCH 06/20] =?UTF-8?q?feat:=20=EC=B1=84=ED=8C=85=EB=B0=A9=20?= =?UTF-8?q?=EC=A1=B4=EC=9E=AC=20=EC=97=AC=EB=B6=80=20=ED=99=95=EC=9D=B8=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/chatroom/ChatRoomQuery.java | 5 +++++ .../chatroom/ChatRoomRepositoryImpl.java | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomQuery.java b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomQuery.java index 681b0339..84e8cbd9 100644 --- a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomQuery.java +++ b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomQuery.java @@ -31,4 +31,9 @@ public ChatRoom findBy(User sender, User receiver) { return chatRoomRepository.findBySenderAndReceiver(sender, receiver) .orElseThrow(() -> new GeneralException(NOT_FOUND_CHAT_ROOM)); } + + public boolean existsBy(List users) { + + return chatRoomRepository.existsBy(users); + } } diff --git a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepositoryImpl.java b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepositoryImpl.java index cfe23cbe..4fbdd992 100644 --- a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepositoryImpl.java +++ b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepositoryImpl.java @@ -5,6 +5,7 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import java.util.List; +import java.util.Objects; import lombok.RequiredArgsConstructor; import yeonba.be.chatting.entity.ChatRoom; import yeonba.be.user.entity.User; @@ -24,4 +25,20 @@ public List findAllByUserAndActiveIsTrue(User user) { ) .fetch(); } + + @Override + public boolean existsBy(List users) { + + User sender = users.get(0); + User receiver = users.get(1); + + Integer result = queryFactory.selectOne().from(chatRoom) + .where( + chatRoom.sender.eq(sender).and(chatRoom.receiver.eq(receiver)) + .or(chatRoom.receiver.eq(sender).and(chatRoom.sender.eq(receiver))) + ) + .fetchFirst(); + + return Objects.nonNull(result); + } } From 53b24c42e6f7cde765a5eb58dfd3b45f320448da Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Sun, 26 May 2024 22:03:03 +0900 Subject: [PATCH 07/20] =?UTF-8?q?feat:=20=EC=95=8C=EB=A6=BC=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=EC=8B=9C,=20=EC=95=8C=EB=A6=BC?= =?UTF-8?q?=20=EC=9D=91=EB=8B=B5=20DTO=20=EB=A7=A4=ED=95=91=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 알림의 종류에 따라 응답의 형태가 달라짐 - 비즈니스 로직에서 알림 유형을 확인하여 적절한 DTO로 엔티티를 매핑하도록 로직 추가 --- .../service/NotificationService.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/be/src/main/java/yeonba/be/notification/service/NotificationService.java b/be/src/main/java/yeonba/be/notification/service/NotificationService.java index 8be4023e..ba21d0d4 100644 --- a/be/src/main/java/yeonba/be/notification/service/NotificationService.java +++ b/be/src/main/java/yeonba/be/notification/service/NotificationService.java @@ -9,11 +9,15 @@ import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import yeonba.be.chatting.repository.chatroom.ChatRoomQuery; import yeonba.be.exception.GeneralException; import yeonba.be.exception.NotificationException; import yeonba.be.notification.dto.request.NotificationPageRequest; +import yeonba.be.notification.dto.response.ChattingRequestedNotificationResponse; import yeonba.be.notification.dto.response.NotificationPageResponse; +import yeonba.be.notification.dto.response.NotificationResponse; import yeonba.be.notification.dto.response.NotificationUnreadExistResponse; +import yeonba.be.notification.dto.response.SimpleNotificationResponse; import yeonba.be.notification.entity.Notification; import yeonba.be.notification.entity.NotificationPermission; import yeonba.be.notification.enums.NotificationType; @@ -32,6 +36,7 @@ public class NotificationService { private final UserQuery userQuery; private final NotificationQuery notificationQuery; private final NotificationPermissionQuery notificationPermissionQuery; + private final ChatRoomQuery chatRoomQuery; private final NotificationCommand notificationCommand; private final NotificationPermissionCommand notificationPermissionCommand; @@ -52,9 +57,10 @@ public NotificationPageResponse getRecentlyReceivedNotificationsBy( User receiver = userQuery.findById(receiverId); Page page = notificationQuery.findRecentlyReceivedNotificationsBy(receiver, pageRequest); + List notifications = page.getContent(); // 가장 최근에 받은 알림 ID 도출 - long mostRecentNotificationId = page.getContent().stream() + long mostRecentNotificationId = notifications.stream() .mapToLong(Notification::getId) .max() .orElse(Long.MAX_VALUE); @@ -62,7 +68,24 @@ public NotificationPageResponse getRecentlyReceivedNotificationsBy( // 가장 최근에 받은 알림 포함 이전 알림 전부 읽음 처리 notificationCommand.readNotificationsUpToIdBy(receiverId, mostRecentNotificationId); - return NotificationPageResponse.from(page); + List response = notifications.stream() + .map(this::toNotificationResponse) + .toList(); + + return NotificationPageResponse.from(page, response); + } + + private NotificationResponse toNotificationResponse(Notification notification) { + + if (notification.getType().isChattingRequest()) { + + List users = List.of(notification.getSender(), notification.getReceiver()); + boolean canChat = !chatRoomQuery.existsBy(users); + + return ChattingRequestedNotificationResponse.from(notification, canChat); + } + + return SimpleNotificationResponse.from(notification); } @Transactional From 3072fd89069b0fcf0a6b35da009d164b817485e6 Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Mon, 27 May 2024 14:42:33 +0900 Subject: [PATCH 08/20] =?UTF-8?q?feat:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=95=8C=EB=A6=BC=20=EB=B3=B4=EB=82=B8=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=20=EB=8B=89=EB=84=A4=EC=9E=84=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/ChattingRequestedNotificationResponse.java | 9 +++------ .../notification/dto/response/NotificationResponse.java | 6 ------ .../dto/response/SimpleNotificationResponse.java | 5 +---- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/be/src/main/java/yeonba/be/notification/dto/response/ChattingRequestedNotificationResponse.java b/be/src/main/java/yeonba/be/notification/dto/response/ChattingRequestedNotificationResponse.java index 06f89eb8..901f775f 100644 --- a/be/src/main/java/yeonba/be/notification/dto/response/ChattingRequestedNotificationResponse.java +++ b/be/src/main/java/yeonba/be/notification/dto/response/ChattingRequestedNotificationResponse.java @@ -22,17 +22,15 @@ public ChattingRequestedNotificationResponse( String content, long senderId, String senderProfilePhotoUrl, - String senderNickname, LocalDateTime createdAt, boolean canChat) { - super(notificationType, content, senderId, senderProfilePhotoUrl, senderNickname, - createdAt); + super(notificationType, content, senderId, senderProfilePhotoUrl, createdAt); this.canChat = canChat; } public static ChattingRequestedNotificationResponse from(Notification notification, - boolean chattingPossible) { + boolean canChat) { User sender = notification.getSender(); @@ -41,9 +39,8 @@ public static ChattingRequestedNotificationResponse from(Notification notificati notification.getContent(), sender.getId(), sender.getRepresentativeProfilePhoto(), - sender.getNickname(), notification.getCreatedAt(), - chattingPossible + canChat ); } } diff --git a/be/src/main/java/yeonba/be/notification/dto/response/NotificationResponse.java b/be/src/main/java/yeonba/be/notification/dto/response/NotificationResponse.java index 59e760c7..904f2907 100644 --- a/be/src/main/java/yeonba/be/notification/dto/response/NotificationResponse.java +++ b/be/src/main/java/yeonba/be/notification/dto/response/NotificationResponse.java @@ -37,12 +37,6 @@ public abstract class NotificationResponse { example = "profile-photo/1-0") private String senderProfilePhotoUrl; - @Schema( - type = "string", - description = "알림 보낸 사용자 별명", - example = "안민재") - private String senderNickname; - @Schema( type = "string", description = "알림 생성 일시", diff --git a/be/src/main/java/yeonba/be/notification/dto/response/SimpleNotificationResponse.java b/be/src/main/java/yeonba/be/notification/dto/response/SimpleNotificationResponse.java index 56070684..fea9b1bc 100644 --- a/be/src/main/java/yeonba/be/notification/dto/response/SimpleNotificationResponse.java +++ b/be/src/main/java/yeonba/be/notification/dto/response/SimpleNotificationResponse.java @@ -11,11 +11,9 @@ public SimpleNotificationResponse( String content, long senderId, String senderProfilePhotoUrl, - String senderNickname, LocalDateTime createdAt) { - super(notificationType, content, senderId, senderProfilePhotoUrl, senderNickname, - createdAt); + super(notificationType, content, senderId, senderProfilePhotoUrl, createdAt); } public static SimpleNotificationResponse from(Notification notification) { @@ -27,7 +25,6 @@ public static SimpleNotificationResponse from(Notification notification) { notification.getContent(), sender.getId(), sender.getRepresentativeProfilePhoto(), - sender.getNickname(), notification.getCreatedAt() ); } From 6327c7ab7c5063b39d166432fa077ef0807db1fb Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Wed, 29 May 2024 15:43:23 +0900 Subject: [PATCH 09/20] =?UTF-8?q?feat:=20=EC=B1=84=ED=8C=85=20=EC=88=98?= =?UTF-8?q?=EB=9D=BD=20=EC=95=8C=EB=A6=BC=20=EC=97=AC=EB=B6=80=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/yeonba/be/notification/enums/NotificationType.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/be/src/main/java/yeonba/be/notification/enums/NotificationType.java b/be/src/main/java/yeonba/be/notification/enums/NotificationType.java index 150ea41a..cad627a9 100644 --- a/be/src/main/java/yeonba/be/notification/enums/NotificationType.java +++ b/be/src/main/java/yeonba/be/notification/enums/NotificationType.java @@ -23,4 +23,9 @@ public boolean isChattingRequest() { return this == CHATTING_REQUESTED; } + + public boolean isChattingAccept() { + + return this == CHATTING_REQUEST_ACCEPTED; + } } From 6c366d6a4a011ae0e63fefaa69ebdbf0eb6c2b85 Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Wed, 29 May 2024 15:44:47 +0900 Subject: [PATCH 10/20] =?UTF-8?q?feat:=20=EC=B1=84=ED=8C=85=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20=EC=95=8C=EB=A6=BC=20=EC=9D=91=EB=8B=B5=20DTO=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 채팅이 가능한 사용자에게만 요청할 수 있으므로 채팅 가능 여부 삭제 - 알림 ID 응답에 포함 --- ...ChattingRequestedNotificationResponse.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/be/src/main/java/yeonba/be/notification/dto/response/ChattingRequestedNotificationResponse.java b/be/src/main/java/yeonba/be/notification/dto/response/ChattingRequestedNotificationResponse.java index 901f775f..d4dfc8a1 100644 --- a/be/src/main/java/yeonba/be/notification/dto/response/ChattingRequestedNotificationResponse.java +++ b/be/src/main/java/yeonba/be/notification/dto/response/ChattingRequestedNotificationResponse.java @@ -1,6 +1,5 @@ package yeonba.be.notification.dto.response; -import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; import java.time.LocalDateTime; import lombok.Getter; @@ -11,11 +10,10 @@ public class ChattingRequestedNotificationResponse extends NotificationResponse { @Schema( - type = "boolean", - description = "채팅 가능 여부", - example = "false") - @JsonProperty("canChat") - private boolean canChat; + type = "number", + description = "알림 ID", + example = "1") + private long notificationId; public ChattingRequestedNotificationResponse( String notificationType, @@ -23,14 +21,13 @@ public ChattingRequestedNotificationResponse( long senderId, String senderProfilePhotoUrl, LocalDateTime createdAt, - boolean canChat) { + long notificationId) { super(notificationType, content, senderId, senderProfilePhotoUrl, createdAt); - this.canChat = canChat; + this.notificationId = notificationId; } - public static ChattingRequestedNotificationResponse from(Notification notification, - boolean canChat) { + public static ChattingRequestedNotificationResponse from(Notification notification) { User sender = notification.getSender(); @@ -40,7 +37,7 @@ public static ChattingRequestedNotificationResponse from(Notification notificati sender.getId(), sender.getRepresentativeProfilePhoto(), notification.getCreatedAt(), - canChat + notification.getId() ); } } From 7a7324d7b8a31d5f97400e1407f2ea918824c854 Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Wed, 29 May 2024 15:49:14 +0900 Subject: [PATCH 11/20] =?UTF-8?q?feat:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=B1=84=ED=8C=85=EB=B0=A9=20=EC=A1=B4=EC=9E=AC=20?= =?UTF-8?q?=EC=97=AC=EB=B6=80=20=ED=99=95=EC=9D=B8=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/chatroom/ChatRoomQuery.java | 5 ----- .../chatroom/ChatRoomRepositoryCustom.java | 2 -- .../chatroom/ChatRoomRepositoryImpl.java | 17 ----------------- 3 files changed, 24 deletions(-) diff --git a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomQuery.java b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomQuery.java index 84e8cbd9..681b0339 100644 --- a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomQuery.java +++ b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomQuery.java @@ -31,9 +31,4 @@ public ChatRoom findBy(User sender, User receiver) { return chatRoomRepository.findBySenderAndReceiver(sender, receiver) .orElseThrow(() -> new GeneralException(NOT_FOUND_CHAT_ROOM)); } - - public boolean existsBy(List users) { - - return chatRoomRepository.existsBy(users); - } } diff --git a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepositoryCustom.java b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepositoryCustom.java index 843e81ba..96508a79 100644 --- a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepositoryCustom.java +++ b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepositoryCustom.java @@ -7,6 +7,4 @@ public interface ChatRoomRepositoryCustom { List findAllByUserAndActiveIsTrue(User user); - - boolean existsBy(List users); } diff --git a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepositoryImpl.java b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepositoryImpl.java index 4fbdd992..cfe23cbe 100644 --- a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepositoryImpl.java +++ b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepositoryImpl.java @@ -5,7 +5,6 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import java.util.List; -import java.util.Objects; import lombok.RequiredArgsConstructor; import yeonba.be.chatting.entity.ChatRoom; import yeonba.be.user.entity.User; @@ -25,20 +24,4 @@ public List findAllByUserAndActiveIsTrue(User user) { ) .fetch(); } - - @Override - public boolean existsBy(List users) { - - User sender = users.get(0); - User receiver = users.get(1); - - Integer result = queryFactory.selectOne().from(chatRoom) - .where( - chatRoom.sender.eq(sender).and(chatRoom.receiver.eq(receiver)) - .or(chatRoom.receiver.eq(sender).and(chatRoom.sender.eq(receiver))) - ) - .fetchFirst(); - - return Objects.nonNull(result); - } } From 21763bb9ccfb647be0730dfcbe9a679b5ba8eb69 Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Wed, 29 May 2024 15:50:24 +0900 Subject: [PATCH 12/20] =?UTF-8?q?feat:=20=EC=95=8C=EB=A6=BC=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20DTO=20=EB=A7=A4=ED=95=91=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 타입에 따라 알맞은 응답 데이터를 제공하도록 매핑 로직 수정 --- .../service/NotificationService.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/be/src/main/java/yeonba/be/notification/service/NotificationService.java b/be/src/main/java/yeonba/be/notification/service/NotificationService.java index ba21d0d4..4bcca3f0 100644 --- a/be/src/main/java/yeonba/be/notification/service/NotificationService.java +++ b/be/src/main/java/yeonba/be/notification/service/NotificationService.java @@ -9,10 +9,12 @@ import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import yeonba.be.chatting.entity.ChatRoom; import yeonba.be.chatting.repository.chatroom.ChatRoomQuery; import yeonba.be.exception.GeneralException; import yeonba.be.exception.NotificationException; import yeonba.be.notification.dto.request.NotificationPageRequest; +import yeonba.be.notification.dto.response.ChattingAcceptedNotificationResponse; import yeonba.be.notification.dto.response.ChattingRequestedNotificationResponse; import yeonba.be.notification.dto.response.NotificationPageResponse; import yeonba.be.notification.dto.response.NotificationResponse; @@ -77,12 +79,19 @@ public NotificationPageResponse getRecentlyReceivedNotificationsBy( private NotificationResponse toNotificationResponse(Notification notification) { - if (notification.getType().isChattingRequest()) { + NotificationType type = notification.getType(); - List users = List.of(notification.getSender(), notification.getReceiver()); - boolean canChat = !chatRoomQuery.existsBy(users); + if (type.isChattingAccept()) { - return ChattingRequestedNotificationResponse.from(notification, canChat); + ChatRoom chatRoom = chatRoomQuery.findBy(notification.getReceiver(), + notification.getSender()); + + return ChattingAcceptedNotificationResponse.from(notification, chatRoom.getId()); + } + + if (type.isChattingRequest()) { + + return ChattingRequestedNotificationResponse.from(notification); } return SimpleNotificationResponse.from(notification); From 1f61a493bea08beb5a80475a9f2dba78cff1db64 Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Wed, 29 May 2024 15:51:36 +0900 Subject: [PATCH 13/20] =?UTF-8?q?feat:=20=EC=B1=84=ED=8C=85=20=EC=88=98?= =?UTF-8?q?=EB=9D=BD=20=EC=95=8C=EB=A6=BC=20=EC=9D=91=EB=8B=B5=20DTO=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 채팅 수락 알림을 통해 채팅방을 접근할 수 있어야함 - 응답 데이터에 채팅방 ID 포함 --- .../ChattingAcceptedNotificationResponse.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 be/src/main/java/yeonba/be/notification/dto/response/ChattingAcceptedNotificationResponse.java diff --git a/be/src/main/java/yeonba/be/notification/dto/response/ChattingAcceptedNotificationResponse.java b/be/src/main/java/yeonba/be/notification/dto/response/ChattingAcceptedNotificationResponse.java new file mode 100644 index 00000000..883f78bc --- /dev/null +++ b/be/src/main/java/yeonba/be/notification/dto/response/ChattingAcceptedNotificationResponse.java @@ -0,0 +1,44 @@ +package yeonba.be.notification.dto.response; + +import io.swagger.v3.oas.annotations.media.Schema; +import java.time.LocalDateTime; +import lombok.Getter; +import yeonba.be.notification.entity.Notification; +import yeonba.be.user.entity.User; + +@Getter +public class ChattingAcceptedNotificationResponse extends NotificationResponse { + + @Schema( + type = "number", + description = "채팅방 ID", + example = "1") + private long chatRoomId; + + public ChattingAcceptedNotificationResponse( + String notificationType, + String content, + long senderId, + String senderProfilePhotoUrl, + LocalDateTime createdAt, + long chatRoomId) { + + super(notificationType, content, senderId, senderProfilePhotoUrl, createdAt); + this.chatRoomId = chatRoomId; + } + + public static ChattingAcceptedNotificationResponse from(Notification notification, + long chatRoomId) { + + User sender = notification.getSender(); + + return new ChattingAcceptedNotificationResponse( + notification.getType().name(), + notification.getContent(), + sender.getId(), + sender.getRepresentativeProfilePhoto(), + notification.getCreatedAt(), + chatRoomId + ); + } +} From 27da8f1392a1c7e64dd4e4c7b1fceba603d9a8ea Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Wed, 29 May 2024 16:03:45 +0900 Subject: [PATCH 14/20] =?UTF-8?q?feat:=20=EB=8B=A4=EB=A5=B8=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=20=ED=94=84=EB=A1=9C=ED=95=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=8B=9C,=20=EC=B1=84=ED=8C=85=20=EA=B0=80=EB=8A=A5?= =?UTF-8?q?=20=EC=97=AC=EB=B6=80=20=ED=8F=AC=ED=95=A8(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../be/user/dto/response/UserProfileResponse.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/be/src/main/java/yeonba/be/user/dto/response/UserProfileResponse.java b/be/src/main/java/yeonba/be/user/dto/response/UserProfileResponse.java index b5cb8a3a..3125bb06 100644 --- a/be/src/main/java/yeonba/be/user/dto/response/UserProfileResponse.java +++ b/be/src/main/java/yeonba/be/user/dto/response/UserProfileResponse.java @@ -1,5 +1,6 @@ package yeonba.be.user.dto.response; +import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; import lombok.AllArgsConstructor; @@ -112,8 +113,15 @@ public class UserProfileResponse { example = "false") private boolean isAlreadySentArrow; + @Schema( + type = "boolean", + description = "채팅 요청 가능 여부", + example = "false") + @JsonProperty("canChat") + private boolean canChat; + public static UserProfileResponse from( - User user, UserPreference userPreference, boolean isAlreadySentArrow) { + User user, UserPreference userPreference, boolean isAlreadySentArrow, boolean canChat) { return new UserProfileResponse( user.getProfilePhotoUrls(), @@ -132,7 +140,8 @@ public static UserProfileResponse from( userPreference.getHeightUpperBound(), userPreference.getMbti(), userPreference.getBodyType(), - isAlreadySentArrow + isAlreadySentArrow, + canChat ); } } From 01fc6776c967f53a6fe04dcde4cd3916d44a4762 Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Wed, 29 May 2024 16:04:46 +0900 Subject: [PATCH 15/20] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EA=B8=B0=EB=B0=98=20=EC=B1=84=ED=8C=85=EB=B0=A9=20=EC=A1=B4?= =?UTF-8?q?=EC=9E=AC=20=EC=97=AC=EB=B6=80=20=ED=99=95=EC=9D=B8=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../be/chatting/repository/chatroom/ChatRoomQuery.java | 5 +++++ .../be/chatting/repository/chatroom/ChatRoomRepository.java | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomQuery.java b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomQuery.java index 681b0339..c954b908 100644 --- a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomQuery.java +++ b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomQuery.java @@ -31,4 +31,9 @@ public ChatRoom findBy(User sender, User receiver) { return chatRoomRepository.findBySenderAndReceiver(sender, receiver) .orElseThrow(() -> new GeneralException(NOT_FOUND_CHAT_ROOM)); } + + public boolean existsBy(User sender, User receiver) { + + return chatRoomRepository.existsBySenderAndReceiver(sender, receiver); + } } diff --git a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepository.java b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepository.java index 449890fc..07fa0d79 100644 --- a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepository.java +++ b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepository.java @@ -7,7 +7,10 @@ import yeonba.be.user.entity.User; @Repository -public interface ChatRoomRepository extends JpaRepository, ChatRoomRepositoryCustom { +public interface ChatRoomRepository extends JpaRepository, + ChatRoomRepositoryCustom { Optional findBySenderAndReceiver(User sender, User receiver); + + boolean existsBySenderAndReceiver(User sender, User receiver); } From 02a35ac63c78d70bb4e0695e4c62024db37ee9f2 Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Wed, 29 May 2024 16:06:32 +0900 Subject: [PATCH 16/20] =?UTF-8?q?feat:=20=EB=8B=A4=EB=A5=B8=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=20=ED=94=84=EB=A1=9C=ED=95=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=8B=9C=20=EC=B1=84=ED=8C=85=20=EA=B0=80=EB=8A=A5=20?= =?UTF-8?q?=EC=97=AC=EB=B6=80=20=EC=9D=91=EB=8B=B5=EC=97=90=20=ED=8F=AC?= =?UTF-8?q?=ED=95=A8(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 다른 사용자 프로필 조회시 조회하는 사용자, 조회되는 사용자간 채팅방 존재 여부 확인 - 채팅방이 존재할 경우 채팅이 불가능, 존재하지 않을 경우 채팅 가능 --- be/src/main/java/yeonba/be/user/service/UserService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/be/src/main/java/yeonba/be/user/service/UserService.java b/be/src/main/java/yeonba/be/user/service/UserService.java index 7c28d3b8..961c4fae 100644 --- a/be/src/main/java/yeonba/be/user/service/UserService.java +++ b/be/src/main/java/yeonba/be/user/service/UserService.java @@ -14,6 +14,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import yeonba.be.arrow.repository.ArrowQuery; +import yeonba.be.chatting.repository.chatroom.ChatRoomQuery; import yeonba.be.exception.GeneralException; import yeonba.be.exception.JoinException; import yeonba.be.exception.UserException; @@ -61,6 +62,7 @@ public class UserService { private final AnimalQuery animalQuery; private final AreaQuery areaQuery; private final ArrowQuery arrowQuery; + private final ChatRoomQuery chatRoomQuery; private final UserQuery userQuery; private final UserPreferenceQuery userPreferenceQuery; private final UserRecommendationQuery userRecommendationQuery; @@ -77,8 +79,11 @@ public UserProfileResponse getTargetUserProfile(long userId, long targetUserId) User targetUser = userQuery.findById(targetUserId); UserPreference targetUserPreference = userPreferenceQuery.findByUser(targetUser); boolean isAlreadySentArrow = arrowQuery.isArrowTransactionExist(user, targetUser); + boolean chatRoomExist = + chatRoomQuery.existsBy(user, targetUser) || chatRoomQuery.existsBy(targetUser, user); - return UserProfileResponse.from(targetUser, targetUserPreference, isAlreadySentArrow); + return UserProfileResponse.from(targetUser, targetUserPreference, isAlreadySentArrow, + !chatRoomExist); } public User saveUser(UserJoinRequest request) { @@ -242,7 +247,7 @@ public UserQueryPageResponse findUsersBySearchCondition(long userId, UserSearchRequest request) { int page = 0; - if(Objects.nonNull(request) && Objects.nonNull(request.getPage())) { + if (Objects.nonNull(request) && Objects.nonNull(request.getPage())) { page = request.getPage(); // 검색 나이/키 하한 <= 상한 여부 검증 From a46584d4abf796498034e035426599ef85010335 Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Wed, 29 May 2024 16:37:19 +0900 Subject: [PATCH 17/20] =?UTF-8?q?feat:=20=EC=B1=84=ED=8C=85=EB=B0=A9=20?= =?UTF-8?q?=EC=A1=B4=EC=9E=AC=20=EC=97=AC=EB=B6=80=20=ED=99=95=EC=9D=B8=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yeonba/be/chatting/repository/chatroom/ChatRoomQuery.java | 2 +- .../be/chatting/repository/chatroom/ChatRoomRepository.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomQuery.java b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomQuery.java index c954b908..564937e7 100644 --- a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomQuery.java +++ b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomQuery.java @@ -34,6 +34,6 @@ public ChatRoom findBy(User sender, User receiver) { public boolean existsBy(User sender, User receiver) { - return chatRoomRepository.existsBySenderAndReceiver(sender, receiver); + return chatRoomRepository.existsBySenderAndReceiverAndActiveIsTrue(sender, receiver); } } diff --git a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepository.java b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepository.java index 07fa0d79..fbd8aa43 100644 --- a/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepository.java +++ b/be/src/main/java/yeonba/be/chatting/repository/chatroom/ChatRoomRepository.java @@ -12,5 +12,5 @@ public interface ChatRoomRepository extends JpaRepository, Optional findBySenderAndReceiver(User sender, User receiver); - boolean existsBySenderAndReceiver(User sender, User receiver); + boolean existsBySenderAndReceiverAndActiveIsTrue(User sender, User receiver); } From 07fda296f9f15c3ffec021c3bfb4b9735ac31de5 Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Wed, 29 May 2024 16:37:45 +0900 Subject: [PATCH 18/20] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=20=EC=B1=84?= =?UTF-8?q?=ED=8C=85=20=EC=A4=91=EC=9D=B8=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B6=94=EA=B0=80(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- be/src/main/java/yeonba/be/exception/ChatException.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/be/src/main/java/yeonba/be/exception/ChatException.java b/be/src/main/java/yeonba/be/exception/ChatException.java index 3bb5783b..cc7a5b4c 100644 --- a/be/src/main/java/yeonba/be/exception/ChatException.java +++ b/be/src/main/java/yeonba/be/exception/ChatException.java @@ -10,7 +10,11 @@ public enum ChatException implements BaseException { NOT_FOUND_CHAT_ROOM( HttpStatus.BAD_REQUEST, - "요청된 채팅방이 없습니다."); + "요청된 채팅방이 없습니다."), + + ALREADY_CHAT_USER( + HttpStatus.BAD_REQUEST, + "이미 채팅 중인 사용자입니다."); private final HttpStatus httpStatus; private final String reason; From a3161b2b5cd62dc09e83a06f98ee42a5abab0a32 Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Wed, 29 May 2024 16:39:21 +0900 Subject: [PATCH 19/20] =?UTF-8?q?feat:=20=EC=B1=84=ED=8C=85=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=EC=8B=9C=20=EC=9D=B4=EB=AF=B8=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EC=A4=91=EC=9D=B8=20=EC=82=AC=EC=9A=A9=EC=9E=90=EC=9D=B8=20?= =?UTF-8?q?=EC=A7=80=20=EA=B2=80=EC=A6=9D(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/yeonba/be/chatting/service/ChatService.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/be/src/main/java/yeonba/be/chatting/service/ChatService.java b/be/src/main/java/yeonba/be/chatting/service/ChatService.java index f56ad3f9..62bd9cad 100644 --- a/be/src/main/java/yeonba/be/chatting/service/ChatService.java +++ b/be/src/main/java/yeonba/be/chatting/service/ChatService.java @@ -19,7 +19,6 @@ import yeonba.be.chatting.repository.chatmessage.ChatMessageQuery; import yeonba.be.chatting.repository.chatroom.ChatRoomCommand; import yeonba.be.chatting.repository.chatroom.ChatRoomQuery; -import yeonba.be.chatting.repository.chatroom.ChatRoomRepository; import yeonba.be.exception.BlockException; import yeonba.be.exception.ChatException; import yeonba.be.exception.GeneralException; @@ -125,6 +124,13 @@ public void requestChat(long senderId, long receiverId) { throw new GeneralException(BlockException.ALREADY_BLOCKED_USER); } + // 이미 채팅 중인 사용자인 지 검증 + boolean chatRoomExist = + chatRoomQuery.existsBy(sender, receiver) || chatRoomQuery.existsBy(receiver, sender); + if (!chatRoomExist) { + throw new GeneralException(ChatException.ALREADY_CHAT_USER); + } + // 비활성화된 채팅방 생성 chatRoomCommand.createChatRoom(new ChatRoom(sender, receiver)); From 9b678d2a7eae44e62e2c8cff47eb9bfd865e3576 Mon Sep 17 00:00:00 2001 From: Minjae-An Date: Wed, 29 May 2024 16:47:01 +0900 Subject: [PATCH 20/20] =?UTF-8?q?feat:=20=EC=9E=98=EB=AA=BB=EB=90=9C=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95(#9?= =?UTF-8?q?8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- be/src/main/java/yeonba/be/chatting/service/ChatService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/be/src/main/java/yeonba/be/chatting/service/ChatService.java b/be/src/main/java/yeonba/be/chatting/service/ChatService.java index 62bd9cad..028798f8 100644 --- a/be/src/main/java/yeonba/be/chatting/service/ChatService.java +++ b/be/src/main/java/yeonba/be/chatting/service/ChatService.java @@ -127,7 +127,7 @@ public void requestChat(long senderId, long receiverId) { // 이미 채팅 중인 사용자인 지 검증 boolean chatRoomExist = chatRoomQuery.existsBy(sender, receiver) || chatRoomQuery.existsBy(receiver, sender); - if (!chatRoomExist) { + if (chatRoomExist) { throw new GeneralException(ChatException.ALREADY_CHAT_USER); }