Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] FCM 토큰으로 조회하기 로직 변경 #59

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions src/main/java/sopt/org/umbbaServer/domain/qna/dao/QnADao.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,4 @@ public Optional<List<QnA>> findQnASByUserId(Long userId) {
}
}

// 부모자식 관계 아이디로 오늘의 Question 조회하기
public Optional<QnA> findQuestionByParentchildId(Long parentchildId) {

String jpql = "SELECT q FROM Parentchild pc " +
"JOIN pc.qnaList q " +
"WHERE pc.id = :id " +
"AND pc.count = q.id" +
"ORDER BY q.id DESC "; // TODO 오늘의 질문 인덱스 (카운트) 필드로 조건 달기 변경

try {
TypedQuery<QnA> query = em.createQuery(jpql, QnA.class);

log.info("query 실행 성공: {}", query);
QnA qnA = query
.setParameter("id", parentchildId)
.setFirstResult(0)
.setMaxResults(1)
.getSingleResult();
log.info("query 실행 결과: {}", qnA.toString());

return Optional.ofNullable(qnA);
} catch (NoResultException e) {

return Optional.empty();
}
}

}
19 changes: 5 additions & 14 deletions src/main/java/sopt/org/umbbaServer/global/util/fcm/FCMService.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,14 @@ public String makeMessage(FCMPushRequestDto request) throws JsonProcessingExcept
// 따로 만들어둔 메세지 템플릿 이용해서 전송할 때 사용하는 알람 [Topic 구독]
String makeMessage(FCMPushRequestDto request, Long userId) throws FirebaseMessagingException, JsonProcessingException {

Optional<User> user = userRepository.findByFcmToken(request.getTargetToken());

if (user.isEmpty()) {
user = userRepository.findById(userId);
user.orElseThrow(
() -> new CustomException(ErrorType.INVALID_USER)
);
user.get().updateFcmToken(request.getTargetToken());

if (user.get().getSocialPlatform().equals(SocialPlatform.WITHDRAW)) {
throw new CustomException(ErrorType.WITHDRAW_USER);
}
}
User user = userRepository.findById(userId).orElseThrow(
() -> new CustomException(ErrorType.INVALID_USER)
);


FCMMessage fcmMessage = FCMMessage.builder()
.message(FCMMessage.Message.builder()
.token(user.get().getFcmToken())
.token(user.getFcmToken())
// .topic(topic) // 토픽 구동에서 반드시 필요한 설정 (token 지정 x)
.notification(FCMMessage.Notification.builder()
.title(request.getTitle())
Expand Down