Skip to content

Commit

Permalink
πŸ”— :: (#818) μ•Œλ¦Ό 둜직 μˆ˜μ •
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyoil2 authored Nov 4, 2024
2 parents ba7ef45 + 7d2524a commit b7ba719
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import team.retum.jobis.domain.notification.spi.QueryTopicSubscriptionPort;
import team.retum.jobis.domain.user.model.User;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

@RequiredArgsConstructor
@UseCase
Expand All @@ -23,11 +26,20 @@ public class SubscribeAllTopicsByToggleUseCase {

public void execute() {
User user = securityPort.getCurrentUser();
boolean isSubscribed = Arrays.stream(Topic.values())
.anyMatch(topic -> queryTopicSubscriptionPort.getByDeviceTokenAndTopic(user.getToken(), topic).isPresent());

if (isSubscribed) {
Arrays.stream(Topic.values()).forEach(topic -> {
List<Topic> topics = Arrays.asList(Topic.values());
boolean hasSubscribed = false;

for (Topic topic : topics) {
Optional<TopicSubscription> subscription = queryTopicSubscriptionPort.getByDeviceTokenAndTopic(user.getToken(), topic);
if (subscription.isPresent() && subscription.get().isSubscribed()) {
hasSubscribed = true;
break;
}
}

if (hasSubscribed) {
topics.forEach(topic -> {
commandNotificationPort.unsubscribeTopic(user.getToken(), topic);
commandTopicSubscriptionPort.save(
TopicSubscription.builder()
Expand All @@ -38,7 +50,7 @@ public void execute() {
);
});
} else {
Arrays.stream(Topic.values()).forEach(topic -> {
topics.forEach(topic -> {
commandNotificationPort.subscribeTopic(user.getToken(), topic);
commandTopicSubscriptionPort.save(
TopicSubscription.builder()
Expand All @@ -50,4 +62,4 @@ public void execute() {
});
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class TopicSubscriptionEntity {
@Id
@NotNull
@Enumerated(EnumType.STRING)
@Column(columnDefinition = "VARCHAR(26)")
@Column(columnDefinition = "VARCHAR(28)")
private Topic topic;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table tbl_topic_subscription modify column topic varchar(28)

0 comments on commit b7ba719

Please sign in to comment.