Skip to content

Commit

Permalink
YEL-214 [feat] lunch event push alarm
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonjeongs committed Feb 26, 2024
1 parent b025439 commit 926afde
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,4 @@
@Configuration
public class ChunkProcessor {

@Bean
@StepScope
public ItemProcessor<User, User> lunchEventProcessor() {
return user -> new User);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.yello.server.infrastructure.batch;

import com.yello.server.domain.user.entity.User;
import com.yello.server.infrastructure.firebase.service.NotificationService;
import lombok.RequiredArgsConstructor;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.item.ItemWriter;
Expand All @@ -11,12 +12,12 @@
@RequiredArgsConstructor
@Configuration
public class ChunkWriter {
private final NotificationService notificationService;

@Bean
@StepScope
public ItemWriter<User> lunchEventWriter() {
return items -> items.forEach(item -> {

});
return items -> items.forEach(notificationService::sendLunchEventNotification);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ public class StepConfiguration {
private final ChunkProcessor chunkProcessor;
private final ChunkWriter chunkWriter;

@Bean
public Step myStep(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new StepBuilder("myStep", jobRepository)
.tasklet(((contribution, chunkContext) -> RepeatStatus.FINISHED), transactionManager) // or .chunk(chunkSize, transactionManager)
.build();
}

@Bean
public Step lunchEventAlarmStep(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new StepBuilder("lunchEventStep", jobRepository)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public enum NotificationType {
NEW_VOTE,
VOTE_AVAILABLE,
NEW_FRIEND,
RECOMMEND
RECOMMEND,
LUNCH_EVENT
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public static NotificationMessage toYelloNotificationContent(Vote vote) {
.build();
}

public static NotificationMessage toAllUserLunchEventNotificationContent() {
return NotificationMessage.builder()
.title("우리 학교 선착순 30명 열람권 뿌린다!")
.message("지금부터 14시까지\uD83D\uDD25 사라지기 전에 바로 확인해보세요!")
.type(NotificationType.LUNCH_EVENT)
.build();
}

public static NotificationMessage toYelloNotificationCustomContent(
NotificationCustomMessage message) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
import com.yello.server.infrastructure.firebase.dto.request.NotificationCustomMessage;
import com.yello.server.infrastructure.firebase.dto.request.NotificationMessage;
import com.yello.server.infrastructure.firebase.manager.FCMManager;
import java.util.Objects;
import lombok.Builder;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Log4j2
@Builder
@Service
Expand All @@ -29,11 +30,11 @@ public class NotificationFcmService implements NotificationService {
@Override
public void sendRecommendNotification(User user, User target) {
NotificationMessage notificationMessage =
NotificationMessage.toRecommendNotificationContent(user);
NotificationMessage.toRecommendNotificationContent(user);

if (target.getDeviceToken() != null && !Objects.equals(target.getDeviceToken(), "")) {
final Message message =
fcmManager.createMessage(target.getDeviceToken(), notificationMessage);
fcmManager.createMessage(target.getDeviceToken(), notificationMessage);
fcmManager.send(message);
}
}
Expand All @@ -43,13 +44,13 @@ public void sendYelloNotification(Vote vote) {
final User receiver = vote.getReceiver();

NotificationMessage notificationMessage =
NotificationMessage.toYelloNotificationContent(vote);
NotificationMessage.toYelloNotificationContent(vote);

final String path = "/api/v1/vote/" + vote.getId().toString();

if (receiver.getDeviceToken() != null && !Objects.equals(receiver.getDeviceToken(), "")) {
final Message message =
fcmManager.createMessage(receiver.getDeviceToken(), notificationMessage, path);
fcmManager.createMessage(receiver.getDeviceToken(), notificationMessage, path);
fcmManager.send(message);
}
}
Expand All @@ -60,11 +61,11 @@ public void sendFriendNotification(Friend friend) {
final User sender = friend.getUser();

NotificationMessage notificationMessage =
NotificationMessage.toFriendNotificationContent(sender);
NotificationMessage.toFriendNotificationContent(sender);

if (receiver.getDeviceToken() != null && !Objects.equals(receiver.getDeviceToken(), "")) {
final Message message =
fcmManager.createMessage(receiver.getDeviceToken(), notificationMessage);
fcmManager.createMessage(receiver.getDeviceToken(), notificationMessage);
fcmManager.send(message);
}
}
Expand All @@ -74,12 +75,12 @@ public void sendVoteAvailableNotification(Long receiverId) {
final User receiveUser = userRepository.getById(receiverId);

NotificationMessage notificationMessage =
NotificationMessage.toVoteAvailableNotificationContent();
NotificationMessage.toVoteAvailableNotificationContent();

if (receiveUser.getDeviceToken() != null && !Objects.equals(receiveUser.getDeviceToken(),
"")) {
"")) {
final Message message =
fcmManager.createMessage(receiveUser.getDeviceToken(), notificationMessage);
fcmManager.createMessage(receiveUser.getDeviceToken(), notificationMessage);
fcmManager.send(message);
log.info("[rabbitmq] successfully send notification!");
}
Expand All @@ -89,19 +90,19 @@ public void sendVoteAvailableNotification(Long receiverId) {
public void sendCustomNotification(NotificationCustomMessage request) {

request.userIdList().stream()
.forEach(userId -> {
final User receiver = userRepository.getById(userId);
.forEach(userId -> {
final User receiver = userRepository.getById(userId);

NotificationMessage notificationMessage =
NotificationMessage.toYelloNotificationCustomContent(request);
NotificationMessage notificationMessage =
NotificationMessage.toYelloNotificationCustomContent(request);

if (receiver.getDeviceToken() != null && !Objects.equals(receiver.getDeviceToken(),
"")) {
final Message message =
fcmManager.createMessage(receiver.getDeviceToken(), notificationMessage);
fcmManager.send(message);
}
});
if (receiver.getDeviceToken() != null && !Objects.equals(receiver.getDeviceToken(),
"")) {
final Message message =
fcmManager.createMessage(receiver.getDeviceToken(), notificationMessage);
fcmManager.send(message);
}
});

}

Expand All @@ -116,4 +117,20 @@ public EmptyObject adminSendCustomNotification(Long adminId, NotificationCustomM

return EmptyObject.builder().build();
}

@Override
public void sendLunchEventNotification(User user) {
final User receiver = userRepository.getById(user.getId());

NotificationMessage notificationMessage =
NotificationMessage.toAllUserLunchEventNotificationContent();

if (receiver.getDeviceToken() != null && !Objects.equals(receiver.getDeviceToken(),
"")) {
final Message message =
fcmManager.createMessage(receiver.getDeviceToken(), notificationMessage);
fcmManager.send(message);

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.yello.server.global.common.dto.EmptyObject;
import com.yello.server.infrastructure.firebase.dto.request.NotificationCustomMessage;

import java.util.List;

public interface NotificationService {

void sendRecommendNotification(User user, User target);
Expand All @@ -19,4 +21,5 @@ public interface NotificationService {
void sendCustomNotification(NotificationCustomMessage request);

EmptyObject adminSendCustomNotification(Long adminId, NotificationCustomMessage request);
void sendLunchEventNotification(User userList);
}

0 comments on commit 926afde

Please sign in to comment.