Skip to content

Commit

Permalink
fix : 알림 버그 수정
Browse files Browse the repository at this point in the history
- 특정 상황에서 알림이 발생하지 않는 버그 수정
  • Loading branch information
KJBig committed Oct 21, 2024
1 parent 6881d10 commit 58be6a6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
package com.sluv.domain.question.repository.impl;

import static com.sluv.domain.celeb.entity.QCeleb.celeb;
import static com.sluv.domain.celeb.entity.QNewCeleb.newCeleb;
import static com.sluv.domain.comment.entity.QComment.comment;
import static com.sluv.domain.question.entity.QDailyHotQuestion.dailyHotQuestion;
import static com.sluv.domain.question.entity.QQuestion.question;
import static com.sluv.domain.question.entity.QQuestionBuy.questionBuy;
import static com.sluv.domain.question.entity.QQuestionFind.questionFind;
import static com.sluv.domain.question.entity.QQuestionHowabout.questionHowabout;
import static com.sluv.domain.question.entity.QQuestionLike.questionLike;
import static com.sluv.domain.question.entity.QQuestionRecommend.questionRecommend;
import static com.sluv.domain.question.entity.QQuestionRecommendCategory.questionRecommendCategory;

import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.ConstantImpl;
import com.querydsl.core.types.Order;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.EntityPathBase;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.StringTemplate;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.sluv.domain.celeb.entity.Celeb;
import com.sluv.domain.celeb.entity.QCeleb;
import com.sluv.domain.question.entity.Question;
import com.sluv.domain.question.entity.QuestionBuy;
import com.sluv.domain.question.entity.QuestionFind;
import com.sluv.domain.question.entity.QuestionHowabout;
import com.sluv.domain.question.entity.QuestionRecommend;
import com.sluv.domain.question.entity.*;
import com.sluv.domain.question.enums.QuestionStatus;
import com.sluv.domain.user.entity.User;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.support.PageableExecutionUtils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import static com.sluv.domain.celeb.entity.QCeleb.celeb;
import static com.sluv.domain.celeb.entity.QNewCeleb.newCeleb;
import static com.sluv.domain.comment.entity.QComment.comment;
import static com.sluv.domain.question.entity.QDailyHotQuestion.dailyHotQuestion;
import static com.sluv.domain.question.entity.QQuestion.question;
import static com.sluv.domain.question.entity.QQuestionBuy.questionBuy;
import static com.sluv.domain.question.entity.QQuestionFind.questionFind;
import static com.sluv.domain.question.entity.QQuestionHowabout.questionHowabout;
import static com.sluv.domain.question.entity.QQuestionLike.questionLike;
import static com.sluv.domain.question.entity.QQuestionRecommend.questionRecommend;
import static com.sluv.domain.question.entity.QQuestionRecommendCategory.questionRecommendCategory;


@RequiredArgsConstructor
public class QuestionRepositoryImpl implements QuestionRepositoryCustom {
Expand Down Expand Up @@ -538,11 +538,13 @@ public List<Question> getSearchQuestionIds(String word) {
@Override
public List<QuestionBuy> getEndTimeBetweenNow(int voteEndCheckPeriod) {
int periodToMinutes = voteEndCheckPeriod / 1000 / 60;
LocalDateTime now = LocalDateTime.now();
String dateFormat = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
String start = LocalDateTime.now().minusMinutes(periodToMinutes).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
StringTemplate formattedDate = Expressions.stringTemplate("DATE_FORMAT({0}, {1})", questionBuy.voteEndTime, ConstantImpl.create("%Y-%m-%d %H:%i:%s"));

return jpaQueryFactory.selectFrom(questionBuy)
.where(questionBuy.questionStatus.eq(QuestionStatus.ACTIVE)
.and(questionBuy.voteEndTime.between(now.minusMinutes(periodToMinutes), now))
.and(formattedDate.between(start, dateFormat))
)
.fetch();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.sluv.domain.item.entity.ItemImg;
import com.sluv.domain.item.repository.ItemImgRepository;
import com.sluv.domain.item.repository.ItemRepository;
import com.sluv.infra.alarm.service.CommentAlarmService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
Expand All @@ -21,6 +22,7 @@ public class AiModelService {
private final CommentRepository commentRepository;
private final ItemRepository itemRepository;
private final ItemImgRepository itemImgRepository;
private final CommentAlarmService commentAlarmService;


@Transactional
Expand All @@ -31,7 +33,7 @@ public void censorComment(Comment comment) {
if (isMalicious) {
comment.changeStatus(CommentStatus.BLOCKED);
commentRepository.save(comment);
// commentAlarmService.sendAlarmAboutReportByAI(comment.getId(), null);
commentAlarmService.sendAlarmAboutReportByAI(comment.getId(), null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.google.firebase.messaging.Notification;
import com.sluv.domain.alarm.enums.AlarmType;
import com.sluv.domain.user.entity.User;
import com.sluv.domain.user.exception.UserNotFoundException;
import com.sluv.domain.user.repository.UserRepository;
import com.sluv.infra.alarm.firebase.exception.FcmConnectException;
import lombok.RequiredArgsConstructor;
Expand All @@ -27,18 +26,18 @@ public class FcmNotificationService {

public void sendFCMNotification(Long userId, String title, String body, AlarmType alarmType,
HashMap<String, Long> ids) {
User user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new);

if (user.getAlarmStatus() && user.getFcmToken() != null) { // 알람 허용 시
Message message = getMessage(title, body, user, alarmType, ids);

try {
firebaseMessaging.send(message);
} catch (FirebaseMessagingException e) {
log.error(e.getMessage());
throw new FcmConnectException();
}
}
// User user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new);
//
// if (user.getAlarmStatus() && user.getFcmToken() != null) { // 알람 허용 시
// Message message = getMessage(title, body, user, alarmType, ids);
//
// try {
// firebaseMessaging.send(message);
// } catch (FirebaseMessagingException e) {
// log.error(e.getMessage());
// throw new FcmConnectException();
// }
// }
}

public void sendFCMNotificationMulticast(List<Long> userIds, String title, String body, AlarmType alarmType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public void sendAlarmAboutCommentLike(Long senderId, Long commentId) {
@Async("alarmThreadPoolExecutor")
public void sendAlarmAboutComment(Long senderId, Long commentId) {
Comment comment = commentDomainService.findById(commentId);

if (!senderId.equals(comment.getUser().getId())) {
if (!senderId.equals(comment.getQuestion().getUser().getId())) {
User sender = userDomainService.findById(senderId);
String message = AlarmMessage.getMessageWithUserName(sender.getNickname(), AlarmMessage.QUESTION_COMMENT);
sendMessageTypeComment(comment.getQuestion().getUser(), comment, message, sender);
Expand All @@ -57,10 +56,10 @@ public void sendAlarmAboutComment(Long senderId, Long commentId) {
public void sendAlarmAboutSubComment(Long senderId, Long commentId) {
Comment comment = commentDomainService.findById(commentId);

if (!senderId.equals(comment.getUser().getId())) {
if (!senderId.equals(comment.getParent().getUser().getId()) && !senderId.equals(comment.getQuestion().getUser().getId())) {
User sender = userDomainService.findById(senderId);
String message = AlarmMessage.getMessageWithUserName(sender.getNickname(), AlarmMessage.COMMENT_SUB);
sendMessageTypeComment(comment.getUser(), comment, message, sender);
sendMessageTypeComment(comment.getParent().getUser(), comment, message, sender);
}
}

Expand Down

0 comments on commit 58be6a6

Please sign in to comment.