From 366f1bb1812e95f72a6a0b2ef6fd74a1b8f38d5c Mon Sep 17 00:00:00 2001 From: mybloom Date: Tue, 27 Dec 2022 21:18:25 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=93=91=20::=20DeviceTokenRepository?= =?UTF-8?q?=EC=97=90=20deviceToken=20=EC=82=AD=EC=A0=9C=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20deleteByUser=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/domain/repository/DeviceTokenRepository.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/domain/repository/DeviceTokenRepository.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/domain/repository/DeviceTokenRepository.java index dd67b19f..20a4597f 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/domain/repository/DeviceTokenRepository.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/domain/repository/DeviceTokenRepository.java @@ -2,6 +2,7 @@ import io.github.depromeet.knockknockbackend.domain.notification.domain.DeviceToken; +import io.github.depromeet.knockknockbackend.domain.user.domain.User; import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.Query; @@ -26,4 +27,6 @@ List findUserByGroupIdAndNewOption( @Param("groupId") Long groupId, @Param("newOption") Boolean newOption, @Param("nightOption") Boolean nightOption); + + void deleteByUser(User user); } From aeaff0a3564511abc425a92347facc2eae8310c1 Mon Sep 17 00:00:00 2001 From: mybloom Date: Tue, 27 Dec 2022 21:19:27 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=93=91=20::=20DeviceToken=20=EC=9A=A9?= =?UTF-8?q?=20Event=20=EA=B0=9D=EC=B2=B4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/event/DeviceTokenEvent.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/java/io/github/depromeet/knockknockbackend/domain/notification/event/DeviceTokenEvent.java diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/event/DeviceTokenEvent.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/event/DeviceTokenEvent.java new file mode 100644 index 00000000..9cf71b84 --- /dev/null +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/notification/event/DeviceTokenEvent.java @@ -0,0 +1,15 @@ +package io.github.depromeet.knockknockbackend.domain.notification.event; + + +import io.github.depromeet.knockknockbackend.domain.user.domain.User; +import io.github.depromeet.knockknockbackend.global.event.DomainEvent; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public class DeviceTokenEvent implements DomainEvent { + + private final User user; + // private final String deviceId or Fcm Token; +} From 38ecb8c75195c32f642e2582a7471a0c3605792f Mon Sep 17 00:00:00 2001 From: mybloom Date: Tue, 27 Dec 2022 21:18:57 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=93=91=20::=20DeviceToken=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20Event=20Listener=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/DeviceTokenServiceEventHandler.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/io/github/depromeet/knockknockbackend/global/event/DeviceTokenServiceEventHandler.java diff --git a/src/main/java/io/github/depromeet/knockknockbackend/global/event/DeviceTokenServiceEventHandler.java b/src/main/java/io/github/depromeet/knockknockbackend/global/event/DeviceTokenServiceEventHandler.java new file mode 100644 index 00000000..c0ab9a3d --- /dev/null +++ b/src/main/java/io/github/depromeet/knockknockbackend/global/event/DeviceTokenServiceEventHandler.java @@ -0,0 +1,23 @@ +package io.github.depromeet.knockknockbackend.global.event; + + +import io.github.depromeet.knockknockbackend.domain.notification.domain.repository.DeviceTokenRepository; +import io.github.depromeet.knockknockbackend.domain.notification.event.DeviceTokenEvent; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import org.springframework.transaction.event.TransactionPhase; +import org.springframework.transaction.event.TransactionalEventListener; + +@RequiredArgsConstructor +@Component +public class DeviceTokenServiceEventHandler { + + private final DeviceTokenRepository deviceTokenRepository; + + @TransactionalEventListener( + classes = DeviceTokenEvent.class, + phase = TransactionPhase.BEFORE_COMMIT) + public void deleteFcmToken(DeviceTokenEvent event) { + deviceTokenRepository.deleteByUser(event.getUser()); + } +} From 51f733b3590db670cb884ecdbb7316622c887938 Mon Sep 17 00:00:00 2001 From: mybloom Date: Tue, 27 Dec 2022 21:20:10 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=93=91=20::=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=95=84=EC=9B=83=20=EC=8B=9C=20deviceToken=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=A6=AC=EC=8A=A4=EB=84=88=20=EC=8B=A4=ED=96=89=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20User=20=EB=8F=84=EB=A9=94=EC=9D=B8=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=EC=97=90=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../knockknockbackend/domain/user/domain/User.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/user/domain/User.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/user/domain/User.java index c6d0fdbe..78222032 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/user/domain/User.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/user/domain/User.java @@ -3,6 +3,7 @@ import io.github.depromeet.knockknockbackend.domain.credential.event.DeleteUserEvent; import io.github.depromeet.knockknockbackend.domain.credential.event.LogoutUserEvent; +import io.github.depromeet.knockknockbackend.domain.notification.event.DeviceTokenEvent; import io.github.depromeet.knockknockbackend.domain.user.domain.vo.UserInfoVO; import io.github.depromeet.knockknockbackend.domain.user.event.RegisterUserEvent; import io.github.depromeet.knockknockbackend.global.event.Events; @@ -101,7 +102,10 @@ public void registerEvent() { } public void logout() { - LogoutUserEvent logoutUserEvent = LogoutUserEvent.builder().userId(this.id).build(); + LogoutUserEvent logoutUserEvent = LogoutUserEvent.builder().userId(id).build(); Events.raise(logoutUserEvent); + + DeviceTokenEvent deviceTokenEvent = new DeviceTokenEvent(User.of(id)); + Events.raise(deviceTokenEvent); } } From da456f0f37f2aacd60bcdf3c50c28b1494271720 Mon Sep 17 00:00:00 2001 From: mybloom Date: Tue, 27 Dec 2022 22:09:17 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=93=91=20::=20=ED=83=88=ED=87=B4=20?= =?UTF-8?q?=EC=8B=9C=20deviceToken=20=EC=82=AD=EC=A0=9C=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=EB=84=88=20=EC=8B=A4=ED=96=89=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?User.softDeleteUser()=20=EC=97=90=EC=84=9C=20=ED=98=B8=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../knockknockbackend/domain/user/domain/User.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/user/domain/User.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/user/domain/User.java index 78222032..e21bbca9 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/user/domain/User.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/user/domain/User.java @@ -89,6 +89,8 @@ public void softDeleteUser() { this.accountState = AccountState.DELETED; DeleteUserEvent deleteUserEvent = DeleteUserEvent.builder().userId(this.id).build(); Events.raise(deleteUserEvent); + + handleDeleteDeviceToken(); } @PostPersist @@ -105,6 +107,10 @@ public void logout() { LogoutUserEvent logoutUserEvent = LogoutUserEvent.builder().userId(id).build(); Events.raise(logoutUserEvent); + handleDeleteDeviceToken(); + } + + private void handleDeleteDeviceToken() { DeviceTokenEvent deviceTokenEvent = new DeviceTokenEvent(User.of(id)); Events.raise(deviceTokenEvent); } From 52b7e3529fb461af98724cde84cf70198e2d603e 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: Wed, 28 Dec 2022 15:13:28 +0900 Subject: [PATCH 6/6] =?UTF-8?q?:recycle:=20::=20[option]=20=EC=98=B5?= =?UTF-8?q?=EC=85=98=20=EC=97=94=ED=8B=B0=ED=8B=B0=20noarg=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=9E=90=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/credential/service/CredentialService.java | 2 ++ .../knockknockbackend/domain/option/domain/Option.java | 9 ++++++++- .../option/domain/repository/OptionRepository.java | 6 +++++- .../domain/option/service/OptionService.java | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/credential/service/CredentialService.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/credential/service/CredentialService.java index 25067688..48696aea 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/credential/service/CredentialService.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/credential/service/CredentialService.java @@ -64,6 +64,8 @@ public AfterOauthResponse oauthCodeToUser(OauthProvider oauthProvider, String co .email(email) .build(); userRepository.save(newUser); + userOptionService.initializeOption(newUser); + return newUser; }); diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/option/domain/Option.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/option/domain/Option.java index 134fa8f7..61cac1a1 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/option/domain/Option.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/option/domain/Option.java @@ -8,12 +8,14 @@ import javax.persistence.MapsId; import javax.persistence.OneToOne; import javax.persistence.Table; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; @Getter -@Builder @Table(name = "tbl_option") +@NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity public class Option { @@ -30,6 +32,11 @@ public class Option { private boolean nightOption; + @Builder + public Option(User user) { + this.user = user; + } + public void setNewOption(boolean newOption) { this.newOption = newOption; } diff --git a/src/main/java/io/github/depromeet/knockknockbackend/domain/option/domain/repository/OptionRepository.java b/src/main/java/io/github/depromeet/knockknockbackend/domain/option/domain/repository/OptionRepository.java index d818ebb7..5a7a095c 100644 --- a/src/main/java/io/github/depromeet/knockknockbackend/domain/option/domain/repository/OptionRepository.java +++ b/src/main/java/io/github/depromeet/knockknockbackend/domain/option/domain/repository/OptionRepository.java @@ -2,6 +2,10 @@ import io.github.depromeet.knockknockbackend.domain.option.domain.Option; +import java.util.Optional; import org.springframework.data.repository.CrudRepository; -public interface OptionRepository extends CrudRepository {} +public interface OptionRepository extends CrudRepository { + + Optional