From 905cd1292e79028d49f18e5ab4123000099bcf99 Mon Sep 17 00:00:00 2001 From: Eunjin3395 Date: Fri, 13 Sep 2024 01:33:13 +0900 Subject: [PATCH 1/3] =?UTF-8?q?:recycle:=20[Refactor]=20=EC=95=8C=EB=A6=BC?= =?UTF-8?q?=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gamegoo/domain/notification/QNotification.java | 3 ++- .../java/com/gamegoo/domain/notification/Notification.java | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/generated/com/gamegoo/domain/notification/QNotification.java b/src/main/generated/com/gamegoo/domain/notification/QNotification.java index c22f84be..568db8c9 100644 --- a/src/main/generated/com/gamegoo/domain/notification/QNotification.java +++ b/src/main/generated/com/gamegoo/domain/notification/QNotification.java @@ -37,7 +37,7 @@ public class QNotification extends EntityPathBase { public final QNotificationType notificationType; - public final NumberPath sourceId = createNumber("sourceId", Long.class); + public final com.gamegoo.domain.member.QMember sourceMember; //inherited public final DateTimePath updatedAt = _super.updatedAt; @@ -62,6 +62,7 @@ public QNotification(Class type, PathMetadata metadata, super(type, metadata, inits); this.member = inits.isInitialized("member") ? new com.gamegoo.domain.member.QMember(forProperty("member")) : null; this.notificationType = inits.isInitialized("notificationType") ? new QNotificationType(forProperty("notificationType")) : null; + this.sourceMember = inits.isInitialized("sourceMember") ? new com.gamegoo.domain.member.QMember(forProperty("sourceMember")) : null; } } diff --git a/src/main/java/com/gamegoo/domain/notification/Notification.java b/src/main/java/com/gamegoo/domain/notification/Notification.java index 85a981bc..d4e2d049 100644 --- a/src/main/java/com/gamegoo/domain/notification/Notification.java +++ b/src/main/java/com/gamegoo/domain/notification/Notification.java @@ -34,7 +34,10 @@ public class Notification extends BaseDateTimeEntity { @Column(nullable = false) private boolean isRead; - private Long sourceId; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "source_member_id") + private Member sourceMember; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id", nullable = false) From 0d738078c28dc959387d8b19e4b69baf0afa5c8f Mon Sep 17 00:00:00 2001 From: Eunjin3395 Date: Fri, 13 Sep 2024 01:34:11 +0900 Subject: [PATCH 2/3] =?UTF-8?q?:recycle:=20[Refactor]=20=EC=95=8C=EB=A6=BC?= =?UTF-8?q?=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EB=AA=A8=EB=93=88=ED=99=94=20=EB=B0=8F=20sourceId=20->=20sourc?= =?UTF-8?q?eMember=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gamegoo/service/manner/MannerService.java | 16 +++---- .../gamegoo/service/member/FriendService.java | 8 ++-- .../notification/NotificationService.java | 42 ++++++++++++------- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/gamegoo/service/manner/MannerService.java b/src/main/java/com/gamegoo/service/manner/MannerService.java index 3ae2ec38..ddc5d773 100644 --- a/src/main/java/com/gamegoo/service/manner/MannerService.java +++ b/src/main/java/com/gamegoo/service/manner/MannerService.java @@ -105,9 +105,10 @@ public MannerRating insertManner(MannerRequest.mannerInsertDTO request, Long mem // 매너평가 등록됨 알림 전송 // 등록된 매너 평가 키워드 string 생성 - String mannerKeywordString = mannerRatingKeywordList.stream() - .map(MannerKeyword::getContents) - .collect(Collectors.joining(", ")); + String mannerKeywordString = mannerRatingKeywordList.get(0).getContents(); + if (mannerRatingKeywordList.size() > 1) { + mannerKeywordString += " 외 " + (mannerRatingKeywordList.size() - 1) + "개의"; + } Notification ratedNotification = notificationService.createNotification( NotificationTypeTitle.MANNER_KEYWORD_RATED, @@ -198,11 +199,12 @@ public MannerRating insertBadManner(MannerRequest.mannerInsertDTO request, Long mannerRatingKeywordRepository.save(mannerRatingKeyword); }); - // 매너평가 등록됨 알림 전송 + // 비매너평가 등록됨 알림 전송 // 등록된 매너 평가 키워드 string 생성 - String mannerKeywordString = mannerRatingKeywordList.stream() - .map(MannerKeyword::getContents) - .collect(Collectors.joining(", ")); + String mannerKeywordString = mannerRatingKeywordList.get(0).getContents(); + if (mannerRatingKeywordList.size() > 1) { + mannerKeywordString += " 외 " + (mannerRatingKeywordList.size() - 1) + "개의"; + } Notification ratedNotification = notificationService.createNotification( NotificationTypeTitle.MANNER_KEYWORD_RATED, diff --git a/src/main/java/com/gamegoo/service/member/FriendService.java b/src/main/java/com/gamegoo/service/member/FriendService.java index fcba4435..8ff2bf7e 100644 --- a/src/main/java/com/gamegoo/service/member/FriendService.java +++ b/src/main/java/com/gamegoo/service/member/FriendService.java @@ -143,11 +143,11 @@ public void sendFriendRequest(Long memberId, Long targetMemberId) { // 친구 요청 알림 생성 // member -> targetMember notificationService.createNotification(NotificationTypeTitle.FRIEND_REQUEST_SEND, - targetMember.getGameName(), null, member); + null, targetMember, member); // targetMember -> member notificationService.createNotification(NotificationTypeTitle.FRIEND_REQUEST_RECEIVED, - member.getGameName(), member.getId(), targetMember); + null, member, targetMember); } /** @@ -226,7 +226,7 @@ public void acceptFriendRequest(Long memberId, Long targetMemberId) { // targetMember에게 친구 요청 수락 알림 생성 notificationService.createNotification(NotificationTypeTitle.FRIEND_REQUEST_ACCEPTED, - member.getGameName(), null, targetMember); + member.getGameName(), member, targetMember); } /** @@ -259,7 +259,7 @@ public void rejectFriendRequest(Long memberId, Long targetMemberId) { // targetMember에게 친구 요청 거절 알림 생성 notificationService.createNotification(NotificationTypeTitle.FRIEND_REQUEST_REJECTED, - member.getGameName(), null, targetMember); + member.getGameName(), member, targetMember); } /** diff --git a/src/main/java/com/gamegoo/service/notification/NotificationService.java b/src/main/java/com/gamegoo/service/notification/NotificationService.java index b21da34b..3d08690c 100644 --- a/src/main/java/com/gamegoo/service/notification/NotificationService.java +++ b/src/main/java/com/gamegoo/service/notification/NotificationService.java @@ -35,27 +35,33 @@ public class NotificationService { * 새로운 알림 생성 및 저장 메소드 * * @param notificationTypeTitle - * @param content 각 알림에 포함되어어야 할 정보 (사용자 닉네임, 매너레벨 단계, 키둬드) - * @param sourceId 이동해야할 url의 고유 id 파라미터, FRIEND_REQUEST_RECEIVED에서만 필요 + * @param content 각 알림에 포함되어어야 할 정보 (매너레벨 단계, 키워드) + * @param sourceMember 알림 source 회원 * @param member 알림을 받을 대상 회원 * @return */ public Notification createNotification(NotificationTypeTitle notificationTypeTitle, - String content, Long sourceId, Member member) { + String content, Member sourceMember, Member member) { - NotificationType notificationType = notificationTypeRepository.findNotificationTypeByTitle( - notificationTypeTitle) - .orElseThrow(() -> new NotificationHandler(ErrorStatus.NOTIFICATION_TYPE_NOT_FOUND)); + NotificationType notificationType = findNotificationType(notificationTypeTitle); + String notificationContent = generateNotificationContent(notificationType, content, + sourceMember); + + return saveNotification(notificationType, notificationContent, sourceMember, member); + } - String notificationContent = switch (notificationTypeTitle) { + private String generateNotificationContent(NotificationType notificationType, String content, + Member sourceMember) { + return switch (notificationType.getTitle()) { + // 알림 타입별로 분기 처리 case FRIEND_REQUEST_SEND, FRIEND_REQUEST_ACCEPTED, FRIEND_REQUEST_REJECTED -> - content + notificationType.getContent(); + notificationType.getContent(); case FRIEND_REQUEST_RECEIVED -> { - if (sourceId == null) { + if (sourceMember == null) { throw new NotificationHandler(ErrorStatus.NOTIFICATION_METHOD_BAD_REQUEST); } - yield content + notificationType.getContent(); + yield notificationType.getContent(); } case MANNER_LEVEL_UP, MANNER_LEVEL_DOWN, MANNER_KEYWORD_RATED -> @@ -67,14 +73,15 @@ public Notification createNotification(NotificationTypeTitle notificationTypeTit int i = random.nextInt(1000) + 1; yield notificationType.getContent() + i; } - - default -> throw new NotificationHandler(ErrorStatus.NOTIFICATION_TYPE_NOT_FOUND); }; + } + private Notification saveNotification(NotificationType type, String content, + Member sourceMember, Member member) { Notification notification = Notification.builder() - .notificationType(notificationType) - .content(notificationContent) - .sourceId(sourceId) + .notificationType(type) + .content(content) + .sourceMember(sourceMember) .isRead(false) .build(); notification.setMember(member); @@ -155,4 +162,9 @@ public long countUnreadNotification(Long memberId) { .filter(notification -> !notification.isRead()) .count(); } + + private NotificationType findNotificationType(NotificationTypeTitle title) { + return notificationTypeRepository.findNotificationTypeByTitle(title) + .orElseThrow(() -> new NotificationHandler(ErrorStatus.NOTIFICATION_TYPE_NOT_FOUND)); + } } From 17027da8f0a7447e9533c4271035f5e1d70dee60 Mon Sep 17 00:00:00 2001 From: Eunjin3395 Date: Fri, 13 Sep 2024 01:34:47 +0900 Subject: [PATCH 3/3] =?UTF-8?q?:recycle:=20[Refactor]=20notificationDTO=20?= =?UTF-8?q?sourceMember=20=EB=B3=80=EA=B2=BD=20=EB=B0=98=EC=98=81=20?= =?UTF-8?q?=EB=B0=8F=20=ED=83=88=ED=87=B4=ED=95=9C=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=ED=91=9C=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converter/NotificationConverter.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gamegoo/converter/NotificationConverter.java b/src/main/java/com/gamegoo/converter/NotificationConverter.java index daef9f47..84e2e91a 100644 --- a/src/main/java/com/gamegoo/converter/NotificationConverter.java +++ b/src/main/java/com/gamegoo/converter/NotificationConverter.java @@ -48,17 +48,29 @@ public static NotificationResponse.notificationDTO toNotificationDTO( StringBuilder urlBuilder = new StringBuilder( notification.getNotificationType().getSourceUrl()); - if (notification.getSourceId() != null) { - urlBuilder.append(notification.getSourceId()); + if (notification.getSourceMember() != null) { + urlBuilder.append(notification.getSourceMember().getId()); } pageUrl = urlBuilder.toString(); } + String content = notification.getContent(); + + // sourceMember 닉네임 표시 + if (notification.getSourceMember() != null) { + if (notification.getSourceMember().getBlind()) { // sourceMember가 탈퇴한 회원인 경우 + content = "(탈퇴한 사용자)" + content; + } else { + content = notification.getSourceMember().getGameName() + content; + } + + } + return NotificationResponse.notificationDTO.builder() .notificationId(notification.getId()) .notificationType(notification.getNotificationType().getId().intValue()) - .content(notification.getContent()) + .content(content) .pageUrl(pageUrl) .read(notification.isRead()) .createdAt(notification.getCreatedAt().withNano(0))