From 0a440b1fd05a3ad7997662117e3e3841ffe15e7c Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 14:12:12 +0900 Subject: [PATCH 01/21] =?UTF-8?q?=F0=9F=93=91=20::=20NOTIFICATION=5FFCM=5F?= =?UTF-8?q?TOKEN=5FINVALID=20=EC=97=90=EB=9F=AC=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - FCM_TOKEN_INVALID 시 사용 --- .../knockknockbackend/global/error/exception/ErrorCode.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/global/error/exception/ErrorCode.java b/src/main/java/io/github/depromeet/knockknockbackend/global/error/exception/ErrorCode.java index e24d7277..0a17dabd 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/global/error/exception/ErrorCode.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/global/error/exception/ErrorCode.java @@ -56,14 +56,15 @@ public enum ErrorCode { REACTION_FORBIDDEN( HttpStatus.FORBIDDEN.value(), "REACTION-403-1", "the user cannot change the reaction"), + NOTIFICATION_FCM_TOKEN_INVALID( + HttpStatus.BAD_REQUEST.value(), "NOTIFICATION-400-1", "FCM token invalid"), NOTIFICATION_FORBIDDEN( HttpStatus.FORBIDDEN.value(), "NOTIFICATION-403-1", "The user has no access to the notification"), NOTIFICATION_NOT_FOUND( HttpStatus.NOT_FOUND.value(), "NOTIFICATION-404-1", "Notification Not Found"), - NOTIFICATION_FCM_FAIL_SEND( - HttpStatus.INTERNAL_SERVER_ERROR.value(), "NOTIFICATION-500-1", "FCM ERROR"), + RESERVATION_FORBIDDEN( HttpStatus.FORBIDDEN.value(), From 5c35e2656067d6aa983692e5f0270febd2c0ce11 Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 14:13:10 +0900 Subject: [PATCH 02/21] =?UTF-8?q?=F0=9F=93=91=20::=20NOTIFICATION=5FFCM=5F?= =?UTF-8?q?TOKEN=5FINVALID=20=EC=97=90=EB=9F=AC=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - FCM_TOKEN_INVALID 시 사용 - 커스텀 익셉션 이름 에러코드에 맞춰서 변경 --- .../exception/FcmResponseException.java | 13 ------------- .../exception/NotificationInvalidFcmToken.java | 13 +++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) delete mode 100644 src/main/java/io/github/depromeet/knockknockbackend/domain/notification/exception/FcmResponseException.java create mode 100644 src/main/java/io/github/depromeet/knockknockbackend/domain/notification/exception/NotificationInvalidFcmToken.java diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/exception/FcmResponseException.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/exception/FcmResponseException.java deleted file mode 100644 index b2d78007..00000000 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/exception/FcmResponseException.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.github.depromeet.knockknockbackend.domain.notification.exception; - - -import io.github.depromeet.knockknockbackend.global.error.exception.ErrorCode; -import io.github.depromeet.knockknockbackend.global.error.exception.KnockException; - -public class FcmResponseException extends KnockException { - public static final KnockException EXCEPTION = new FcmResponseException(); - - private FcmResponseException() { - super(ErrorCode.NOTIFICATION_FCM_FAIL_SEND); - } -} diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/exception/NotificationInvalidFcmToken.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/exception/NotificationInvalidFcmToken.java new file mode 100644 index 00000000..b3857ef1 --- /dev/null +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/exception/NotificationInvalidFcmToken.java @@ -0,0 +1,13 @@ +package io.github.depromeet.knockknockbackend.domain.notification.exception; + + +import io.github.depromeet.knockknockbackend.global.error.exception.ErrorCode; +import io.github.depromeet.knockknockbackend.global.error.exception.KnockException; + +public class NotificationInvalidFcmToken extends KnockException { + public static final KnockException EXCEPTION = new NotificationInvalidFcmToken(); + + private NotificationInvalidFcmToken() { + super(ErrorCode.NOTIFICATION_FCM_TOKEN_INVALID); + } +} From 7aa9b9cc960915198321d91e4b3e93dfb850912b Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 14:13:56 +0900 Subject: [PATCH 03/21] =?UTF-8?q?=E2=99=BB=20::=20sendGroupMessage?= =?UTF-8?q?=EC=97=90=20=20=EC=9D=91=EB=8B=B5=20=EB=A1=9C=EA=B7=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=EA=B0=92=20ApiFuture=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructor/fcm/FcmService.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/infrastructor/fcm/FcmService.java b/src/main/java/io/github/depromeet/knockknockbackend/infrastructor/fcm/FcmService.java index ee6e097f..7a987615 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/infrastructor/fcm/FcmService.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/infrastructor/fcm/FcmService.java @@ -1,12 +1,8 @@ package io.github.depromeet.knockknockbackend.infrastructor.fcm; -import com.google.firebase.messaging.ApnsConfig; -import com.google.firebase.messaging.Aps; -import com.google.firebase.messaging.FirebaseMessaging; -import com.google.firebase.messaging.Message; -import com.google.firebase.messaging.MulticastMessage; -import com.google.firebase.messaging.Notification; +import com.google.api.core.ApiFuture; +import com.google.firebase.messaging.*; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -15,7 +11,7 @@ @Service public class FcmService { - public void sendGroupMessage( + public ApiFuture sendGroupMessage( List tokenList, String title, String content, String imageUrl) { MulticastMessage multicast = MulticastMessage.builder() @@ -32,7 +28,7 @@ public void sendGroupMessage( .build()) .build(); - FirebaseMessaging.getInstance().sendMulticastAsync(multicast); + return FirebaseMessaging.getInstance().sendMulticastAsync(multicast); } public void sendMessage(String token, String content) { From bcd1e8949e6e2393d33fe33c9c60118cab3b802f Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 14:15:56 +0900 Subject: [PATCH 04/21] =?UTF-8?q?=F0=9F=93=91=20::=20Fcm=20Response=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8=20=ED=9B=84=20=EC=9C=A0=ED=9A=A8=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EC=9D=80=20fcm=20token=EC=9E=88=EC=9D=84?= =?UTF-8?q?=20=EA=B2=BD=EC=9A=B0=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - deviceToken에서 해당 토큰을 삭제 - log.error 에러 로그 남김 --- .../service/NotificationUtilsImpl.java | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java index 586f5721..d6810635 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java @@ -1,26 +1,40 @@ package io.github.depromeet.knockknockbackend.domain.notification.service; +import com.google.api.core.ApiFuture; +import com.google.firebase.messaging.BatchResponse; +import com.google.firebase.messaging.MessagingErrorCode; +import com.google.firebase.messaging.SendResponse; import io.github.depromeet.knockknockbackend.domain.group.domain.Group; import io.github.depromeet.knockknockbackend.domain.notification.domain.DeviceToken; import io.github.depromeet.knockknockbackend.domain.notification.domain.NightCondition; import io.github.depromeet.knockknockbackend.domain.notification.domain.Notification; +import io.github.depromeet.knockknockbackend.domain.notification.domain.repository.DeviceTokenRepository; import io.github.depromeet.knockknockbackend.domain.notification.domain.repository.NotificationRepository; +import io.github.depromeet.knockknockbackend.domain.notification.exception.FcmTokenInvalidException; import io.github.depromeet.knockknockbackend.domain.notification.exception.NotificationNotFoundException; import io.github.depromeet.knockknockbackend.domain.user.domain.User; import io.github.depromeet.knockknockbackend.infrastructor.fcm.FcmService; import java.time.LocalDateTime; import java.util.List; +import java.util.Optional; +import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; +import java.util.stream.IntStream; + import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +@Slf4j @RequiredArgsConstructor @Component public class NotificationUtilsImpl implements NotificationUtils { private final FcmService fcmService; private final NotificationRepository notificationRepository; + private final DeviceTokenRepository deviceTokenRepository; + @Override public Notification queryNotificationById(Long notificationId) { @@ -53,7 +67,8 @@ public void sendNotification( if (tokens.isEmpty()) { return; } - fcmService.sendGroupMessage(tokens, title, content, imageUrl); + ApiFuture batchResponseApiFuture = fcmService.sendGroupMessage(tokens, title, content, imageUrl); + checkFcmResponse(deviceTokens, tokens, batchResponseApiFuture); } private List getDeviceTokens(Long groupId, Long sendUserId) { @@ -83,4 +98,37 @@ private void recordNotification( deviceTokens, title, content, imageUrl, group, sendUser, reservedAt); notificationRepository.save(notification); } + + private void checkFcmResponse(List deviceTokens, List tokens, ApiFuture batchResponseApiFuture) { + try { + List responses = batchResponseApiFuture.get().getResponses(); + IntStream.iterate(0, i -> i + 1) + .limit(responses.size()) + .filter(i -> responses.get(i).getException() != null) + .filter(i -> responses.get(i).getException().getMessagingErrorCode().equals(MessagingErrorCode.INVALID_ARGUMENT)) + .forEach(i -> { + String errorToken = tokens.get(i); + String errorMessage = responses.get(i).getException().getMessage(); + MessagingErrorCode errorCode = responses.get(i).getException().getMessagingErrorCode(); + + Optional errorDeviceToken = deviceTokens.stream() + .filter(deviceToken -> deviceToken.getToken().equals(errorToken)) + .findAny(); + Long IdOfErrorDeviceToken = errorDeviceToken + .map(DeviceToken::getId) + .orElse(null); + Long userIdOfErrorDeviceToken = errorDeviceToken.map(DeviceToken::getUserId) + .orElse(null); + deviceTokenRepository.deleteById(IdOfErrorDeviceToken); + + log.error("**[validateFcmToken] errorUserId: {}, message: {}, messagingErrorCode: {}, errorToken: {}", + userIdOfErrorDeviceToken, + errorMessage, + errorCode, + errorToken); + }); + } catch (InterruptedException | ExecutionException e) { + throw FcmTokenInvalidException.EXCEPTION; + } + } } From b9f0f83f5e710f6bb57a49a1cb8b4471ebe0bd07 Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 14:20:46 +0900 Subject: [PATCH 05/21] =?UTF-8?q?=E2=99=BB=20::=20spotless=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/NotificationUtilsImpl.java | 67 ++++++++++++------- .../global/error/exception/ErrorCode.java | 1 - 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java index d6810635..da3eac97 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java @@ -21,7 +21,6 @@ import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; import java.util.stream.IntStream; - import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -35,7 +34,6 @@ public class NotificationUtilsImpl implements NotificationUtils { private final NotificationRepository notificationRepository; private final DeviceTokenRepository deviceTokenRepository; - @Override public Notification queryNotificationById(Long notificationId) { return notificationRepository @@ -67,7 +65,8 @@ public void sendNotification( if (tokens.isEmpty()) { return; } - ApiFuture batchResponseApiFuture = fcmService.sendGroupMessage(tokens, title, content, imageUrl); + ApiFuture batchResponseApiFuture = + fcmService.sendGroupMessage(tokens, title, content, imageUrl); checkFcmResponse(deviceTokens, tokens, batchResponseApiFuture); } @@ -99,34 +98,50 @@ private void recordNotification( notificationRepository.save(notification); } - private void checkFcmResponse(List deviceTokens, List tokens, ApiFuture batchResponseApiFuture) { + private void checkFcmResponse( + List deviceTokens, + List tokens, + ApiFuture batchResponseApiFuture) { try { List responses = batchResponseApiFuture.get().getResponses(); IntStream.iterate(0, i -> i + 1) .limit(responses.size()) .filter(i -> responses.get(i).getException() != null) - .filter(i -> responses.get(i).getException().getMessagingErrorCode().equals(MessagingErrorCode.INVALID_ARGUMENT)) - .forEach(i -> { - String errorToken = tokens.get(i); - String errorMessage = responses.get(i).getException().getMessage(); - MessagingErrorCode errorCode = responses.get(i).getException().getMessagingErrorCode(); - - Optional errorDeviceToken = deviceTokens.stream() - .filter(deviceToken -> deviceToken.getToken().equals(errorToken)) - .findAny(); - Long IdOfErrorDeviceToken = errorDeviceToken - .map(DeviceToken::getId) - .orElse(null); - Long userIdOfErrorDeviceToken = errorDeviceToken.map(DeviceToken::getUserId) - .orElse(null); - deviceTokenRepository.deleteById(IdOfErrorDeviceToken); - - log.error("**[validateFcmToken] errorUserId: {}, message: {}, messagingErrorCode: {}, errorToken: {}", - userIdOfErrorDeviceToken, - errorMessage, - errorCode, - errorToken); - }); + .filter( + i -> + responses + .get(i) + .getException() + .getMessagingErrorCode() + .equals(MessagingErrorCode.INVALID_ARGUMENT)) + .forEach( + i -> { + String errorToken = tokens.get(i); + String errorMessage = responses.get(i).getException().getMessage(); + MessagingErrorCode errorCode = + responses.get(i).getException().getMessagingErrorCode(); + + Optional errorDeviceToken = + deviceTokens.stream() + .filter( + deviceToken -> + deviceToken + .getToken() + .equals(errorToken)) + .findAny(); + Long IdOfErrorDeviceToken = + errorDeviceToken.map(DeviceToken::getId).orElse(null); + Long userIdOfErrorDeviceToken = + errorDeviceToken.map(DeviceToken::getUserId).orElse(null); + deviceTokenRepository.deleteById(IdOfErrorDeviceToken); + + log.error( + "**[validateFcmToken] errorUserId: {}, message: {}, messagingErrorCode: {}, errorToken: {}", + userIdOfErrorDeviceToken, + errorMessage, + errorCode, + errorToken); + }); } catch (InterruptedException | ExecutionException e) { throw FcmTokenInvalidException.EXCEPTION; } diff --git a/src/main/java/io/github/depromeet/knockknockbackend/global/error/exception/ErrorCode.java b/src/main/java/io/github/depromeet/knockknockbackend/global/error/exception/ErrorCode.java index 0a17dabd..a7f8a2dd 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/global/error/exception/ErrorCode.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/global/error/exception/ErrorCode.java @@ -65,7 +65,6 @@ public enum ErrorCode { NOTIFICATION_NOT_FOUND( HttpStatus.NOT_FOUND.value(), "NOTIFICATION-404-1", "Notification Not Found"), - RESERVATION_FORBIDDEN( HttpStatus.FORBIDDEN.value(), "RESERVATION-403-1", From 838fd86ea3d3aa1893e48aff6d977dd43a4b798f Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 14:52:10 +0900 Subject: [PATCH 06/21] =?UTF-8?q?=F0=9F=93=91=20::=20ReactionNotExistExcep?= =?UTF-8?q?tion=EC=97=90=20=EB=8C=80=ED=95=9C=20ErrorCode=EC=99=80=20?= =?UTF-8?q?=EC=BB=A4=EC=8A=A4=ED=85=80=20=EC=9D=B5=EC=85=89=EC=85=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/ReactionNotExistException.java | 13 +++++++++++++ .../global/error/exception/ErrorCode.java | 4 ++++ 2 files changed, 17 insertions(+) create mode 100644 src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/exception/ReactionNotExistException.java diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/exception/ReactionNotExistException.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/exception/ReactionNotExistException.java new file mode 100644 index 00000000..b93ecddd --- /dev/null +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/exception/ReactionNotExistException.java @@ -0,0 +1,13 @@ +package io.github.depromeet.knockknockbackend.domain.reaction.exception; + + +import io.github.depromeet.knockknockbackend.global.error.exception.ErrorCode; +import io.github.depromeet.knockknockbackend.global.error.exception.KnockException; + +public class ReactionNotExistException extends KnockException { + public static final KnockException EXCEPTION = new ReactionNotExistException(); + + private ReactionNotExistException() { + super(ErrorCode.REACTION_NOT_EXIST); + } +} diff --git a/src/main/java/io/github/depromeet/knockknockbackend/global/error/exception/ErrorCode.java b/src/main/java/io/github/depromeet/knockknockbackend/global/error/exception/ErrorCode.java index a7f8a2dd..76f27c07 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/global/error/exception/ErrorCode.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/global/error/exception/ErrorCode.java @@ -53,6 +53,10 @@ public enum ErrorCode { HttpStatus.BAD_REQUEST.value(), "REACTION-400-1", "reaction of the notification is already exist"), + REACTION_NOT_EXIST( + HttpStatus.BAD_REQUEST.value(), + "REACTION-400-2", + "reaction of the notification is not exist"), REACTION_FORBIDDEN( HttpStatus.FORBIDDEN.value(), "REACTION-403-1", "the user cannot change the reaction"), From a9369366210b95b04dde001f10190deca34038ca Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 14:52:41 +0900 Subject: [PATCH 07/21] =?UTF-8?q?=F0=9F=93=91=20::=20NotificationReaction?= =?UTF-8?q?=EC=97=90=20getUserId()=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/reaction/domain/NotificationReaction.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/domain/NotificationReaction.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/domain/NotificationReaction.java index 815f7b0d..b411b382 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/domain/NotificationReaction.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/domain/NotificationReaction.java @@ -46,6 +46,10 @@ public class NotificationReaction extends BaseTimeEntity { @ManyToOne(fetch = FetchType.LAZY) private User user; + public Long getUserId() { + return user.getId(); + } + public static NotificationReaction of(Long id, Reaction reaction) { return NotificationReaction.builder().id(id).reaction(reaction).build(); } From 5dbd28f7b36ccb63b7aae97581ec775ccf482487 Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 14:53:37 +0900 Subject: [PATCH 08/21] =?UTF-8?q?=E2=99=BB=20::=20=EB=A6=AC=EC=95=A1?= =?UTF-8?q?=EC=85=98=20=EC=88=98=EC=A0=95/=EC=82=AD=EC=A0=9C=20=EC=8B=9C?= =?UTF-8?q?=20=EC=9E=90=EC=8B=A0=EC=9D=98=20notificationReaction=EC=9D=B8?= =?UTF-8?q?=EC=A7=80=20=ED=99=95=EC=9D=B8=EC=8B=9C,=20=EA=B8=B0=20notifica?= =?UTF-8?q?tionReaction=20=EC=A1=B4=EC=9E=AC=EC=97=AC=EB=B6=80=20=EB=A8=BC?= =?UTF-8?q?=EC=A0=80=20=ED=8C=90=EB=8B=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reaction/service/ReactionService.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/service/ReactionService.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/service/ReactionService.java index 7f83ea10..0e59380e 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/service/ReactionService.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/service/ReactionService.java @@ -7,6 +7,7 @@ import io.github.depromeet.knockknockbackend.domain.reaction.domain.repository.NotificationReactionRepository; import io.github.depromeet.knockknockbackend.domain.reaction.exception.ReactionAlreadyExistException; import io.github.depromeet.knockknockbackend.domain.reaction.exception.ReactionForbiddenException; +import io.github.depromeet.knockknockbackend.domain.reaction.exception.ReactionNotExistException; import io.github.depromeet.knockknockbackend.domain.reaction.presentation.dto.request.RegisterReactionRequest; import io.github.depromeet.knockknockbackend.global.utils.security.SecurityUtils; import io.github.depromeet.knockknockbackend.global.utils.user.UserUtils; @@ -49,15 +50,16 @@ public void deleteReaction(Long notificationReactionId) { } private void validateMyReactionTheNotification(Long notificationReactionId) { - notificationReactionRepository + NotificationReaction notificationReaction = + queryNotificationReactionId(notificationReactionId); + if (!notificationReaction.getUserId().equals(SecurityUtils.getCurrentUserId())) { + throw ReactionForbiddenException.EXCEPTION; + } + } + + private NotificationReaction queryNotificationReactionId(Long notificationReactionId) { + return notificationReactionRepository .findById(notificationReactionId) - .ifPresent( - notificationReaction -> { - if (!notificationReaction - .getUser() - .getId() - .equals(SecurityUtils.getCurrentUserId())) - throw ReactionForbiddenException.EXCEPTION; - }); + .orElseThrow(() -> ReactionNotExistException.EXCEPTION); } } From 25f7521541aa8ae138dcde90b936f3ddff4f5aa9 Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 15:02:52 +0900 Subject: [PATCH 09/21] =?UTF-8?q?=F0=9F=93=91=20::=20NotificationReaction?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=EC=97=90=20changeReaction()=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/reaction/domain/NotificationReaction.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/domain/NotificationReaction.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/domain/NotificationReaction.java index b411b382..10d2ac97 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/domain/NotificationReaction.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/domain/NotificationReaction.java @@ -50,6 +50,10 @@ public Long getUserId() { return user.getId(); } + public void changeReaction(Reaction reaction) { + this.reaction = reaction; + } + public static NotificationReaction of(Long id, Reaction reaction) { return NotificationReaction.builder().id(id).reaction(reaction).build(); } From 7ab16d4273fca0ad8624177b35a5108c48309153 Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 15:03:56 +0900 Subject: [PATCH 10/21] =?UTF-8?q?=E2=99=BB=20::=20changeReaction=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - notificationReactionRepository.save 대신 엔티티의 메서드 notificationReaction.changeReaction() 호출하여 리액션 변경 --- .../reaction/service/ReactionService.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/service/ReactionService.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/service/ReactionService.java index 0e59380e..c30f3135 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/service/ReactionService.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/service/ReactionService.java @@ -35,23 +35,24 @@ public void registerReaction(RegisterReactionRequest request) { } } + @Transactional public void changeReaction(Long notificationReactionId, RegisterReactionRequest request) { - validateMyReactionTheNotification(notificationReactionId); + NotificationReaction notificationReaction = + queryNotificationReactionId(notificationReactionId); + validateMyReactionTheNotification(notificationReaction); - notificationReactionRepository.save( - NotificationReaction.of( - notificationReactionId, Reaction.of(request.getReactionId()))); + notificationReaction.changeReaction(Reaction.of(request.getReactionId())); } @Transactional public void deleteReaction(Long notificationReactionId) { - validateMyReactionTheNotification(notificationReactionId); + NotificationReaction notificationReaction = + queryNotificationReactionId(notificationReactionId); + validateMyReactionTheNotification(notificationReaction); notificationReactionRepository.deleteById(notificationReactionId); } - private void validateMyReactionTheNotification(Long notificationReactionId) { - NotificationReaction notificationReaction = - queryNotificationReactionId(notificationReactionId); + private void validateMyReactionTheNotification(NotificationReaction notificationReaction) { if (!notificationReaction.getUserId().equals(SecurityUtils.getCurrentUserId())) { throw ReactionForbiddenException.EXCEPTION; } From 0f01f01b38b46e5bce1ad5cba3376784e200a2d3 Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 15:05:29 +0900 Subject: [PATCH 11/21] =?UTF-8?q?=E2=99=BB=20::=20queryNotificationReactio?= =?UTF-8?q?n()=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/reaction/service/ReactionService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/service/ReactionService.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/service/ReactionService.java index c30f3135..9c72edca 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/service/ReactionService.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/reaction/service/ReactionService.java @@ -38,7 +38,7 @@ public void registerReaction(RegisterReactionRequest request) { @Transactional public void changeReaction(Long notificationReactionId, RegisterReactionRequest request) { NotificationReaction notificationReaction = - queryNotificationReactionId(notificationReactionId); + queryNotificationReaction(notificationReactionId); validateMyReactionTheNotification(notificationReaction); notificationReaction.changeReaction(Reaction.of(request.getReactionId())); @@ -47,7 +47,7 @@ public void changeReaction(Long notificationReactionId, RegisterReactionRequest @Transactional public void deleteReaction(Long notificationReactionId) { NotificationReaction notificationReaction = - queryNotificationReactionId(notificationReactionId); + queryNotificationReaction(notificationReactionId); validateMyReactionTheNotification(notificationReaction); notificationReactionRepository.deleteById(notificationReactionId); } @@ -58,7 +58,7 @@ private void validateMyReactionTheNotification(NotificationReaction notification } } - private NotificationReaction queryNotificationReactionId(Long notificationReactionId) { + private NotificationReaction queryNotificationReaction(Long notificationReactionId) { return notificationReactionRepository .findById(notificationReactionId) .orElseThrow(() -> ReactionNotExistException.EXCEPTION); From cda59f2776109f64cf2f0e7a65982dac5758fccb Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 15:45:05 +0900 Subject: [PATCH 12/21] =?UTF-8?q?=F0=9F=93=91=20::=20NOTIFICATION=5FFCM=5F?= =?UTF-8?q?SERVER=5FERROR=20=EC=97=90=EB=9F=AC=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - FcmServerException 커스텀 익셉션추가 - FcmTokenInvalidException 커스텀 익셉션 커밋 추가 --- .../notification/exception/FcmServerException.java | 13 +++++++++++++ .../exception/FcmTokenInvalidException.java | 13 +++++++++++++ .../global/error/exception/ErrorCode.java | 2 ++ 3 files changed, 28 insertions(+) create mode 100644 src/main/java/io/github/depromeet/knockknockbackend/domain/notification/exception/FcmServerException.java create mode 100644 src/main/java/io/github/depromeet/knockknockbackend/domain/notification/exception/FcmTokenInvalidException.java diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/exception/FcmServerException.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/exception/FcmServerException.java new file mode 100644 index 00000000..d574525a --- /dev/null +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/exception/FcmServerException.java @@ -0,0 +1,13 @@ +package io.github.depromeet.knockknockbackend.domain.notification.exception; + + +import io.github.depromeet.knockknockbackend.global.error.exception.ErrorCode; +import io.github.depromeet.knockknockbackend.global.error.exception.KnockException; + +public class FcmServerException extends KnockException { + public static final KnockException EXCEPTION = new FcmServerException(); + + private FcmServerException() { + super(ErrorCode.NOTIFICATION_FCM_SERVER_ERROR); + } +} diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/exception/FcmTokenInvalidException.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/exception/FcmTokenInvalidException.java new file mode 100644 index 00000000..f3ce8e3a --- /dev/null +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/exception/FcmTokenInvalidException.java @@ -0,0 +1,13 @@ +package io.github.depromeet.knockknockbackend.domain.notification.exception; + + +import io.github.depromeet.knockknockbackend.global.error.exception.ErrorCode; +import io.github.depromeet.knockknockbackend.global.error.exception.KnockException; + +public class FcmTokenInvalidException extends KnockException { + public static final KnockException EXCEPTION = new FcmTokenInvalidException(); + + private FcmTokenInvalidException() { + super(ErrorCode.NOTIFICATION_FCM_TOKEN_INVALID); + } +} diff --git a/src/main/java/io/github/depromeet/knockknockbackend/global/error/exception/ErrorCode.java b/src/main/java/io/github/depromeet/knockknockbackend/global/error/exception/ErrorCode.java index a7f8a2dd..4292f077 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/global/error/exception/ErrorCode.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/global/error/exception/ErrorCode.java @@ -64,6 +64,8 @@ public enum ErrorCode { "The user has no access to the notification"), NOTIFICATION_NOT_FOUND( HttpStatus.NOT_FOUND.value(), "NOTIFICATION-404-1", "Notification Not Found"), + NOTIFICATION_FCM_SERVER_ERROR( + HttpStatus.INTERNAL_SERVER_ERROR.value(), "NOTIFICATION-500-1", "FCM server error"), RESERVATION_FORBIDDEN( HttpStatus.FORBIDDEN.value(), From 104309bbad77483555ca4c58c4a783cec85b7e15 Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 15:46:39 +0900 Subject: [PATCH 13/21] =?UTF-8?q?=E2=99=BB=20::=20=20FcmService.sendGroupM?= =?UTF-8?q?essage=20->=20sendGroupMessageAsync=20=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../knockknockbackend/infrastructor/fcm/FcmService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/infrastructor/fcm/FcmService.java b/src/main/java/io/github/depromeet/knockknockbackend/infrastructor/fcm/FcmService.java index 7a987615..408c995d 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/infrastructor/fcm/FcmService.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/infrastructor/fcm/FcmService.java @@ -11,7 +11,7 @@ @Service public class FcmService { - public ApiFuture sendGroupMessage( + public ApiFuture sendGroupMessageAsync( List tokenList, String title, String content, String imageUrl) { MulticastMessage multicast = MulticastMessage.builder() From 14137e61a18c87ddbfd999be9092880a8178568e Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 15:47:45 +0900 Subject: [PATCH 14/21] =?UTF-8?q?=E2=99=BB=20::=20=20sendMessageSync()=20F?= =?UTF-8?q?irebaseMessagingException=20=EB=B0=9C=EC=83=9D=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructor/fcm/FcmService.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/infrastructor/fcm/FcmService.java b/src/main/java/io/github/depromeet/knockknockbackend/infrastructor/fcm/FcmService.java index 408c995d..20c47243 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/infrastructor/fcm/FcmService.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/infrastructor/fcm/FcmService.java @@ -2,11 +2,16 @@ import com.google.api.core.ApiFuture; +import com.google.firebase.ErrorCode; import com.google.firebase.messaging.*; +import io.github.depromeet.knockknockbackend.domain.notification.exception.FcmServerException; +import io.github.depromeet.knockknockbackend.domain.notification.exception.FcmTokenInvalidException; import java.util.List; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +@Slf4j @RequiredArgsConstructor @Service public class FcmService { @@ -31,7 +36,7 @@ public ApiFuture sendGroupMessageAsync( return FirebaseMessaging.getInstance().sendMulticastAsync(multicast); } - public void sendMessage(String token, String content) { + public void sendMessageSync(String token, String content) { Message message = Message.builder() .setToken(token) @@ -41,6 +46,18 @@ public void sendMessage(String token, String content) { .setAps(Aps.builder().setSound("default").build()) .build()) .build(); - FirebaseMessaging.getInstance().sendAsync(message); + try { + FirebaseMessaging.getInstance().send(message); + } catch (FirebaseMessagingException e) { + ErrorCode errorCode = e.getErrorCode(); + log.error( + "**[sendMessageSync] errorCode: {}, errorMessage: {}, messagingErrorCode: {}", + errorCode, + e.getMessage()); + if (errorCode.equals(ErrorCode.INVALID_ARGUMENT)) { + throw FcmTokenInvalidException.EXCEPTION; + } + throw FcmServerException.EXCEPTION; + } } } From 7f6509791b21f8e103496b597029c90c830f9e03 Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 15:48:24 +0900 Subject: [PATCH 15/21] =?UTF-8?q?=E2=99=BB=20::=20=20FcmService=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/notification/service/NotificationUtilsImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java index da3eac97..2dc71ec5 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java @@ -66,7 +66,7 @@ public void sendNotification( return; } ApiFuture batchResponseApiFuture = - fcmService.sendGroupMessage(tokens, title, content, imageUrl); + fcmService.sendGroupMessageAsync(tokens, title, content, imageUrl); checkFcmResponse(deviceTokens, tokens, batchResponseApiFuture); } From 8dfb9d2cc2be502e6bed5d9758795de49f7ccdc5 Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 15:48:45 +0900 Subject: [PATCH 16/21] =?UTF-8?q?=E2=99=BB=20::=20=20fcm=20error=20?= =?UTF-8?q?=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/notification/service/NotificationUtilsImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java index 2dc71ec5..1775ce9e 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java @@ -136,7 +136,7 @@ private void checkFcmResponse( deviceTokenRepository.deleteById(IdOfErrorDeviceToken); log.error( - "**[validateFcmToken] errorUserId: {}, message: {}, messagingErrorCode: {}, errorToken: {}", + "**[sendGroupMessageAsync] errorUserId: {}, errorMessage: {}, errorCode: {}, errorToken: {}", userIdOfErrorDeviceToken, errorMessage, errorCode, From 19133d8016597d79432860f14755c8bea06cb870 Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 15:49:15 +0900 Subject: [PATCH 17/21] =?UTF-8?q?=E2=99=BB=20::=20FcmService=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/notification/service/NotificationService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationService.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationService.java index 8da985b7..80157852 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationService.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationService.java @@ -47,8 +47,8 @@ public class NotificationService { private final DeviceTokenRepository deviceTokenRepository; private final NotificationReactionRepository notificationReactionRepository; private final ReservationRepository reservationRepository; - private final NotificationExperienceRepository notificationExperienceRepository; private final GroupUserRepository groupUserRepository; + private final NotificationExperienceRepository notificationExperienceRepository; @Transactional(readOnly = true) public QueryNotificationListLatestResponse queryListLatest() { @@ -186,7 +186,8 @@ public void sendInstance(SendInstanceRequest request) { } public void sendInstanceToMeBeforeSignUp(SendInstanceToMeBeforeSignUpRequest request) { - fcmService.sendMessage(request.getToken(), request.getContent()); + fcmService.sendMessageSync(request.getToken(), request.getContent()); + notificationExperienceRepository.save( NotificationExperience.of(request.getToken(), request.getContent())); } From 4ba673e39ebf502bbca4b31dd5c7c5eaba55ee50 Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 16:10:30 +0900 Subject: [PATCH 18/21] =?UTF-8?q?=E2=99=BB=20::=20FcmService.sendMessageSy?= =?UTF-8?q?nc()=20catch=20=EC=B2=98=EB=A6=AC=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=ED=98=B8=EC=B6=9C=ED=95=98=EB=8A=94=20=EB=B6=80=EB=B6=84?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=B2=98=EB=A6=AC=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructor/fcm/FcmService.java | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/infrastructor/fcm/FcmService.java b/src/main/java/io/github/depromeet/knockknockbackend/infrastructor/fcm/FcmService.java index 20c47243..a5c37324 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/infrastructor/fcm/FcmService.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/infrastructor/fcm/FcmService.java @@ -2,16 +2,11 @@ import com.google.api.core.ApiFuture; -import com.google.firebase.ErrorCode; import com.google.firebase.messaging.*; -import io.github.depromeet.knockknockbackend.domain.notification.exception.FcmServerException; -import io.github.depromeet.knockknockbackend.domain.notification.exception.FcmTokenInvalidException; import java.util.List; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -@Slf4j @RequiredArgsConstructor @Service public class FcmService { @@ -36,7 +31,7 @@ public ApiFuture sendGroupMessageAsync( return FirebaseMessaging.getInstance().sendMulticastAsync(multicast); } - public void sendMessageSync(String token, String content) { + public void sendMessageSync(String token, String content) throws FirebaseMessagingException { Message message = Message.builder() .setToken(token) @@ -46,18 +41,7 @@ public void sendMessageSync(String token, String content) { .setAps(Aps.builder().setSound("default").build()) .build()) .build(); - try { - FirebaseMessaging.getInstance().send(message); - } catch (FirebaseMessagingException e) { - ErrorCode errorCode = e.getErrorCode(); - log.error( - "**[sendMessageSync] errorCode: {}, errorMessage: {}, messagingErrorCode: {}", - errorCode, - e.getMessage()); - if (errorCode.equals(ErrorCode.INVALID_ARGUMENT)) { - throw FcmTokenInvalidException.EXCEPTION; - } - throw FcmServerException.EXCEPTION; - } + + FirebaseMessaging.getInstance().send(message); } } From 3ba95226eec69ecae11e79a5cc4b2c4c7cf33c32 Mon Sep 17 00:00:00 2001 From: mybloom Date: Fri, 13 Jan 2023 16:11:45 +0900 Subject: [PATCH 19/21] =?UTF-8?q?=E2=99=BB=20::=20sendInstanceToMeBeforeSi?= =?UTF-8?q?gnUp()=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=EC=9D=84=20NotificationUtil=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - sendExperienceNotification 에 catch 로직 추가 --- .../service/NotificationService.java | 7 +----- .../service/NotificationUtils.java | 2 ++ .../service/NotificationUtilsImpl.java | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationService.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationService.java index 80157852..2bde6b3d 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationService.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationService.java @@ -10,7 +10,6 @@ import io.github.depromeet.knockknockbackend.domain.notification.domain.*; import io.github.depromeet.knockknockbackend.domain.notification.domain.Notification; import io.github.depromeet.knockknockbackend.domain.notification.domain.repository.DeviceTokenRepository; -import io.github.depromeet.knockknockbackend.domain.notification.domain.repository.NotificationExperienceRepository; import io.github.depromeet.knockknockbackend.domain.notification.domain.repository.NotificationRepository; import io.github.depromeet.knockknockbackend.domain.notification.domain.repository.ReservationRepository; import io.github.depromeet.knockknockbackend.domain.notification.domain.vo.NotificationReactionCountInfoVo; @@ -48,7 +47,6 @@ public class NotificationService { private final NotificationReactionRepository notificationReactionRepository; private final ReservationRepository reservationRepository; private final GroupUserRepository groupUserRepository; - private final NotificationExperienceRepository notificationExperienceRepository; @Transactional(readOnly = true) public QueryNotificationListLatestResponse queryListLatest() { @@ -186,10 +184,7 @@ public void sendInstance(SendInstanceRequest request) { } public void sendInstanceToMeBeforeSignUp(SendInstanceToMeBeforeSignUpRequest request) { - fcmService.sendMessageSync(request.getToken(), request.getContent()); - - notificationExperienceRepository.save( - NotificationExperience.of(request.getToken(), request.getContent())); + notificationUtils.sendExperienceNotification(request.getToken(), request.getContent()); } public void deleteByNotificationId(Long notificationId) { diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtils.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtils.java index cdd6d668..e4d7a04e 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtils.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtils.java @@ -14,4 +14,6 @@ void sendNotification( String content, String imageUrl, LocalDateTime reservedAt); + + void sendExperienceNotification(String token, String content); } diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java index 1775ce9e..3ed52e18 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.java @@ -2,15 +2,20 @@ import com.google.api.core.ApiFuture; +import com.google.firebase.ErrorCode; import com.google.firebase.messaging.BatchResponse; +import com.google.firebase.messaging.FirebaseMessagingException; import com.google.firebase.messaging.MessagingErrorCode; import com.google.firebase.messaging.SendResponse; import io.github.depromeet.knockknockbackend.domain.group.domain.Group; import io.github.depromeet.knockknockbackend.domain.notification.domain.DeviceToken; import io.github.depromeet.knockknockbackend.domain.notification.domain.NightCondition; import io.github.depromeet.knockknockbackend.domain.notification.domain.Notification; +import io.github.depromeet.knockknockbackend.domain.notification.domain.NotificationExperience; import io.github.depromeet.knockknockbackend.domain.notification.domain.repository.DeviceTokenRepository; +import io.github.depromeet.knockknockbackend.domain.notification.domain.repository.NotificationExperienceRepository; import io.github.depromeet.knockknockbackend.domain.notification.domain.repository.NotificationRepository; +import io.github.depromeet.knockknockbackend.domain.notification.exception.FcmServerException; import io.github.depromeet.knockknockbackend.domain.notification.exception.FcmTokenInvalidException; import io.github.depromeet.knockknockbackend.domain.notification.exception.NotificationNotFoundException; import io.github.depromeet.knockknockbackend.domain.user.domain.User; @@ -33,6 +38,7 @@ public class NotificationUtilsImpl implements NotificationUtils { private final FcmService fcmService; private final NotificationRepository notificationRepository; private final DeviceTokenRepository deviceTokenRepository; + private final NotificationExperienceRepository notificationExperienceRepository; @Override public Notification queryNotificationById(Long notificationId) { @@ -70,6 +76,25 @@ public void sendNotification( checkFcmResponse(deviceTokens, tokens, batchResponseApiFuture); } + @Override + public void sendExperienceNotification(String token, String content) { + try { + fcmService.sendMessageSync(token, content); + } catch (FirebaseMessagingException e) { + ErrorCode errorCode = e.getErrorCode(); + log.error( + "**[sendMessageSync] errorCode: {}, errorMessage: {}", + errorCode, + e.getMessage()); + if (errorCode.equals(ErrorCode.INVALID_ARGUMENT)) { + throw FcmTokenInvalidException.EXCEPTION; + } + throw FcmServerException.EXCEPTION; + } + + notificationExperienceRepository.save(NotificationExperience.of(token, content)); + } + private List getDeviceTokens(Long groupId, Long sendUserId) { Boolean nightOption = null; if (NightCondition.isNight()) { From bf5d7e888dd83313e13026ef5d18bdef4cdc92bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8E=E1=85=A1=E1=86=AB=E1=84=8C?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Fri, 13 Jan 2023 21:24:56 +0900 Subject: [PATCH 20/21] =?UTF-8?q?=F0=9F=93=9D=20::=20Readme=20=ED=8B=80=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 254 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 140 insertions(+), 114 deletions(-) diff --git a/README.md b/README.md index 4589a677..db2ff49f 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,119 @@ -# KnockKnock-Backend - -디프만 12기 칠면조 KnockKnock Backend입니다. - -# KnockKnock 프로젝트를 시작하기전 - -## 목차 - -* [개발 프로세스](https://github.com/TEAM-XQUARE/README.md#개발-프로세스) -* [이슈규칙](https://github.com/TEAM-XQUARE/README.md#이슈-규칙) -* [커밋규칙](https://github.com/TEAM-XQUARE/README.md#커밋-규칙) -* [브랜치규칙](https://github.com/TEAM-XQUARE/README.md#브랜치-규칙) -* [버전규칙](https://github.com/TEAM-XQUARE/README.md#버전-규칙) -* [Lisence](https://github.com/team-xquare/README.md/blob/main/README.md#license) - - +

+

푸시알림 커스텀 서비스, Knocknock

+

+ +

+ +--- + +![Group 48095933](https://user-images.githubusercontent.com/13329304/212319564-fb9dc5ec-31e9-4e47-8034-cd5148cddb6b.png) + +--- + +### :computer: 개발자 선생님들 :computer: + + + + + + + + + + + + + + + + + +
백엔드, 팀장백엔드백엔드
이서준이찬진배정은
+ +
+ leeseojune53 +
+ +
+ ImNM +
+ +
+ mybloom +
+ + + + + + + + + + + + + + + + + + + + +
AOS 팀장AOSAOSAOS
황규일이영준조준장최현정
+ +
+ Gyuil-Hwnag +
+ +
+ leeyjwinter +
+ +
+ junjange +
+ +
+ hyunjung-choi +
+ +### :art: 하늘같은 디자인 선생님들 :art: + + + + + + + + + + + + + + + + + +
디자인디자인디자인
김나영박수연진승희
+ +
+ 김나영 +
+ +
+ 박수연 +
+ +
+ 진승희 +
+ +--- + +# KnockKnock 백엔드 팀의 규칙 ## 개발 프로세스 @@ -28,69 +128,34 @@ > 6. merge 후 feature branch 제거 > 7. issue close - - -## 이슈 규칙 - -> 한 기능 당 하나의 issue 생성을 원칙으로 합니다. -> -> 생성한 issue 성격이 맞는 label을 선택하여 추가한다. - -``` [Domain] Subject - - Subject - -``` - -위는 모든 이슈 메세지의 형식이다. - -### Labels - -> 새 리포지토리를 생성하면 issue label을 위같이 설정한다. - -| Label | Description | Color Code | 의미 | -| ------------- | ------------------------------------------ | ---------- | ------------------------------------------------------------ | -| 버그 | Something isn't working | #d73a4a | 예기치 않은 문제 또는 의도하지 않은 동작(버그)을 나타냅니다. | -| 기능 추가 | New feature or request | #a2eeef | 새로운 기능 요청을 나타냅니다. | -| DOCS | Improvements or additions to documentation | #cfd3d7 | 문서를 개선하거나 추가 할 필요가 있음을 나타냅니다. | -| Chore | | #0075ca | 자잘한 수정들을 나타냅니다. | -| 리펙토링 | Refactoring is needed | #008672 | 리펙토링이 필요함을 나타냅니다. | -| 프로젝트 설정 | Project setting is needed | #555303 | 프로젝트 설정이 필요함을 나타냅니다. | -| 테스트 추가 | Request a new test | #CD7F57 | 새로운 테스트 요청을 나타냅니다. | - - - ## 커밋 규칙 -> 프론트엔드라면 아래 링크를 확인해주세요! -* [프론트엔드](https://github.com/team-xquare/README.md/tree/main/frontend) ### 커밋메세지 > 다음은 커밋메세지의 형식입니다. -``` - CommitType :: (#issue number) Subject - ``` -### Commit Type - - > 다음은 커밋타입 형식입니다. + CommitType :: (#issue number) Subject -|CommitType|설명| -|------|----------------------| -|📑 ::|파일 생성 및 구조 변경| -|⚡️ ::|기능 업데이트| -|⚰️ ::|기능 삭제| -|🐛 ::|버그 수정| -|♻️ ::|코드 리펙토링| -|📝 ::|문서 작성 및 수정| -|⚙️ ::|프로젝트 세팅| -|🧪 ::|테스트 코드 추가| -|🚀 ::|새 버전 릴리즈 ( 커밋은 아니지만😏| -|🔀 ::|Merge or PR| +``` +### Commit Type +> 다음은 커밋타입 형식입니다. + +| CommitType | 설명 | +| ---------- | ---------------------------------- | +| 📑 :: | 파일 생성 및 구조 변경 | +| ⚡️ :: | 기능 업데이트 | +| ⚰️ :: | 기능 삭제 | +| 🐛 :: | 버그 수정 | +| ♻️ :: | 코드 리펙토링 | +| 📝 :: | 문서 작성 및 수정 | +| ⚙️ :: | 프로젝트 세팅 | +| 🧪 :: | 테스트 코드 추가 | +| 🚀 :: | 새 버전 릴리즈 ( 커밋은 아니지만😏 | +| 🔀 :: | Merge or PR | ### issue number @@ -108,9 +173,9 @@ > 커밋메세지 형식의 Subject 부분에 기재 -* 50자를 넘기지 않게 명령형으로 작성한다. -* 한국어로 작성한다. -* ```어떻게``` 보단 ```무엇을```, ```왜``` 에 초점을 두고 작성한다. +- 50자를 넘기지 않게 명령형으로 작성한다. +- 한국어로 작성한다. +- `어떻게` 보단 `무엇을`, `왜` 에 초점을 두고 작성한다. ```bash @@ -125,18 +190,19 @@ ``` 🐛 :: [MainPage] 헤더가 안보이는 버그 수정 ``` + ``` 🐛 :: (#19)[FeedServiceImpl] 피드 버그 로직 수정 ``` + ``` 🚀 :: v1.0.0 ``` + ``` 📝 :: README 파일 수정 ``` - - ### 브랜치 규칙 > 기본적으로 GitFlow를 따릅니다 @@ -144,45 +210,5 @@ ### Feature Branch ```markdown - -Feature/{issue number}_{todo} - -``` - - - -### 버전 규칙 - -![버전 규칙](https://user-images.githubusercontent.com/67373938/119933978-0ac15300-bfc0-11eb-99cd-0198b1ee6f2d.png) - -> 모든 버전은 01.00.00에서 시작한다. - -```jsx - -"01.01.09" 생략시 "1.1.9" - -"01.01.10" 생략시 "1.1.10" - +Feature/{issue number}\_{todo} ``` - -### Major Version - -- 1로 시작한다. -- 증가 시 나머지 버전 정보 초기화 -- 전체를 뒤엎었을때 변화한다. - -### Minor Version - -- 00으로 시작한다 -- 없던 기능의 추가나 기존 기능의 수정 등의 변화가 발생했을때 이 수치를 올린다. - -### Patches - -+ 00으로 시작한다. - -- 자잘한 버그나 내부적 코드 보완 등의 변화가 발생했을때 이 수치를 올린다. - - -## License -> 해당 문서에 대한 라이센스는 대덕소프트웨어 마이스터 고등학교의 SEMICOLON; & XQUARE팀에 있습니다. -> 해당 문서는 출처만 남겨주신다면, 자유롭게 이용하실 수 있습니다! From 0794f2b76e16fbfa1e8293686da8bbdb72fc7d66 Mon Sep 17 00:00:00 2001 From: Leeseojune Date: Fri, 13 Jan 2023 22:19:26 +0900 Subject: [PATCH 21/21] =?UTF-8?q?=F0=9F=90=9B=20::=20Relation=20Entity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/relation/domain/Relation.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/relation/domain/Relation.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/relation/domain/Relation.java index d831f98e..346ad80b 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/relation/domain/Relation.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/relation/domain/Relation.java @@ -5,19 +5,25 @@ import io.github.depromeet.knockknockbackend.domain.user.domain.vo.UserInfoVO; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; @Getter +@NoArgsConstructor @Table(name = "tbl_relation") @Entity public class Relation { - @Id private Long id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; private boolean isFriend;