diff --git a/build.gradle b/build.gradle index 6e4c051..34f6bc4 100644 --- a/build.gradle +++ b/build.gradle @@ -69,7 +69,7 @@ dependencies { implementation("software.amazon.awssdk:s3:2.21.0") // Firebase - implementation 'com.google.firebase:firebase-admin:9.2.0' + implementation 'com.google.firebase:firebase-admin:9.3.0' // Logback Discord Appender implementation('com.github.napstr:logback-discord-appender:1.0.0') diff --git a/src/main/java/org/kkumulkkum/server/advice/GlobalExceptionHandler.java b/src/main/java/org/kkumulkkum/server/advice/GlobalExceptionHandler.java index 7bcbbcc..15329b2 100644 --- a/src/main/java/org/kkumulkkum/server/advice/GlobalExceptionHandler.java +++ b/src/main/java/org/kkumulkkum/server/advice/GlobalExceptionHandler.java @@ -4,6 +4,7 @@ import org.kkumulkkum.server.exception.*; import org.kkumulkkum.server.exception.code.*; import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MissingRequestHeaderException; @@ -109,7 +110,11 @@ public ResponseEntity handleNoPageFoundException(HttpRequestM .body(BusinessErrorCode.METHOD_NOT_ALLOWED); } - @ExceptionHandler(value = {HandlerMethodValidationException.class, MethodArgumentNotValidException.class}) + @ExceptionHandler(value = { + HandlerMethodValidationException.class, + MethodArgumentNotValidException.class, + HttpMessageNotReadableException.class + }) public ResponseEntity handleValidationException(Exception e) { log.warn("GlobalExceptionHandler catch MethodArgumentNotValidException : {}", e.getMessage()); return ResponseEntity diff --git a/src/main/java/org/kkumulkkum/server/external/FcmService.java b/src/main/java/org/kkumulkkum/server/external/FcmService.java index 5589273..2582b2d 100644 --- a/src/main/java/org/kkumulkkum/server/external/FcmService.java +++ b/src/main/java/org/kkumulkkum/server/external/FcmService.java @@ -26,7 +26,7 @@ public void sendBulk( ){ MulticastMessage message = createBulkMessage(fcmTokens, fcmMessageDto); try { - FirebaseMessaging.getInstance().sendMulticast(message); + FirebaseMessaging.getInstance().sendEachForMulticast(message); } catch (FirebaseMessagingException e){ throw new FirebaseException(FirebaseErrorCode.FCM_ERROR); } diff --git a/src/main/java/org/kkumulkkum/server/repository/MemberRepository.java b/src/main/java/org/kkumulkkum/server/repository/MemberRepository.java index d0e8447..a38a5b5 100644 --- a/src/main/java/org/kkumulkkum/server/repository/MemberRepository.java +++ b/src/main/java/org/kkumulkkum/server/repository/MemberRepository.java @@ -35,6 +35,11 @@ SELECT CASE WHEN EXISTS ( Member findByMeetingIdAndUserId(Long meetingId, Long userId); + @Query(""" + SELECT m from Member m + JOIN FETCH m.meeting + WHERE m.user.id = :userId + """) List findByUserId(Long userId); @Query(""" diff --git a/src/main/java/org/kkumulkkum/server/service/auth/AuthService.java b/src/main/java/org/kkumulkkum/server/service/auth/AuthService.java index f0664f7..685b62d 100644 --- a/src/main/java/org/kkumulkkum/server/service/auth/AuthService.java +++ b/src/main/java/org/kkumulkkum/server/service/auth/AuthService.java @@ -19,6 +19,9 @@ import org.kkumulkkum.server.service.member.MemberRemover; import org.kkumulkkum.server.service.member.MemberRetreiver; import org.kkumulkkum.server.service.participant.ParticipantRemover; +import org.kkumulkkum.server.service.participant.ParticipantRetriever; +import org.kkumulkkum.server.service.promise.PromiseRemover; +import org.kkumulkkum.server.service.promise.PromiseRetriever; import org.kkumulkkum.server.service.user.UserRemover; import org.kkumulkkum.server.service.user.UserRetriever; import org.kkumulkkum.server.service.user.UserSaver; @@ -45,6 +48,9 @@ public class AuthService { private final TokenRemover tokenRemover; private final UserInfoRetriever userInfoRetriever; private final MemberRetreiver memberRetreiver; + private final PromiseRetriever promiseRetriever; + private final ParticipantRetriever participantRetriever; + private final PromiseRemover promiseRemover; private final ParticipantRemover participantRemover; private final MemberRemover memberRemover; private final UserInfoRemover userInfoRemover; @@ -148,6 +154,7 @@ private void deleteUser(final User user) { // 각 Member에 대한 Participant 삭제 for(Member member : members) { participantRemover.deleteByMemberId(member.getId()); + removeEmptyPromises(member.getMeeting().getId()); } // Member 데이터 삭제 @@ -158,4 +165,10 @@ private void deleteUser(final User user) { // User 삭제 userRemover.delete(user); } + + private void removeEmptyPromises(final Long meetingId) { + promiseRetriever.findAllByMeetingId(meetingId).stream() + .filter(promise -> participantRetriever.findAllByPromiseId(promise.getId()).isEmpty()) + .forEach(promise -> promiseRemover.deleteById(promise.getId())); + } }