Skip to content

Commit

Permalink
YEL-214 [feat] 투표 열람시 보낸사람에게 푸시알림
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonjeongs committed Feb 28, 2024
1 parent f2b6438 commit c895a0b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.yello.server.domain.vote.exception.VoteForbiddenException;
import com.yello.server.domain.vote.exception.VoteNotFoundException;
import com.yello.server.domain.vote.repository.VoteRepository;
import com.yello.server.infrastructure.firebase.service.NotificationService;
import com.yello.server.infrastructure.rabbitmq.service.ProducerService;
import java.time.LocalDateTime;
import java.util.List;
Expand Down Expand Up @@ -73,6 +74,7 @@ public class VoteService {

private final VoteManager voteManager;
private final ProducerService producerService;
private final NotificationService notificationService;

public VoteListResponse findAllVotes(Long userId, Pageable pageable) {
Integer totalCount = voteRepository.countAllByReceiverUserId(userId);
Expand Down Expand Up @@ -104,6 +106,10 @@ public VoteDetailResponse findVoteById(Long voteId, Long userId) {
final Vote vote = voteRepository.getById(voteId);
final User user = userRepository.getById(userId);

if(!vote.getIsRead()) {
notificationService.sendOpenVoteNotification(user);
}

vote.read();
return VoteDetailResponse.of(vote, user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public enum NotificationType {
VOTE_AVAILABLE,
NEW_FRIEND,
RECOMMEND,
LUNCH_EVENT
LUNCH_EVENT,
OPEN_VOTE
}
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 toUserOpenVoteNotificationContent(User user) {
return NotificationMessage.builder()
.title(MessageFormat.format("{0}님이 내가 보낸 쪽지를 확인했어요! ", user.getName()))
.message("\uD83D\uDEA8\uD83D\uDC9A 그린라이트입니다.")
.type(NotificationType.OPEN_VOTE)
.build();
}

public static NotificationMessage toAllUserLunchEventNotificationContent() {
return NotificationMessage.builder()
.title("우리 학교 선착순 30명 열람권 뿌린다!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,16 @@ public void sendLunchEventNotification(User user) {

}
}

@Override
public void sendOpenVoteNotification(User user) {
NotificationMessage notificationMessage =
NotificationMessage.toUserOpenVoteNotificationContent(user);

if (user.getDeviceToken() != null && !Objects.equals(user.getDeviceToken(), "")) {
final Message message =
fcmManager.createMessage(user.getDeviceToken(), notificationMessage);
fcmManager.send(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public interface NotificationService {

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

void sendOpenVoteNotification(User user);
}

0 comments on commit c895a0b

Please sign in to comment.