Skip to content

Commit

Permalink
๐Ÿš€ :: v0.1.5-1
Browse files Browse the repository at this point in the history
๐Ÿš€ :: v0.1.5-1
  • Loading branch information
ImNM authored Dec 28, 2022
2 parents c8f4bf1 + d5ba4ef commit 79c02ac
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public AfterOauthResponse oauthCodeToUser(OauthProvider oauthProvider, String co
.email(email)
.build();
userRepository.save(newUser);
userOptionService.initializeOption(newUser);

return newUser;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,4 +27,6 @@ List<DeviceToken> findUserByGroupIdAndNewOption(
@Param("groupId") Long groupId,
@Param("newOption") Boolean newOption,
@Param("nightOption") Boolean nightOption);

void deleteByUser(User user);
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option, Long> {}
public interface OptionRepository extends CrudRepository<Option, Long> {

Optional<Option> findByUserId(Long currentUserId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void initializeOption(User user) {

private Option queryOption() {
return optionRepository
.findById(SecurityUtils.getCurrentUserId())
.findByUserId(SecurityUtils.getCurrentUserId())
.orElseThrow(() -> OptionNotFoundException.EXCEPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,6 +89,8 @@ public void softDeleteUser() {
this.accountState = AccountState.DELETED;
DeleteUserEvent deleteUserEvent = DeleteUserEvent.builder().userId(this.id).build();
Events.raise(deleteUserEvent);

handleDeleteDeviceToken();
}

@PostPersist
Expand All @@ -101,7 +104,14 @@ public void registerEvent() {
}

public void logout() {
LogoutUserEvent logoutUserEvent = LogoutUserEvent.builder().userId(this.id).build();
LogoutUserEvent logoutUserEvent = LogoutUserEvent.builder().userId(id).build();
Events.raise(logoutUserEvent);

handleDeleteDeviceToken();
}

private void handleDeleteDeviceToken() {
DeviceTokenEvent deviceTokenEvent = new DeviceTokenEvent(User.of(id));
Events.raise(deviceTokenEvent);
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 79c02ac

Please sign in to comment.