Skip to content

Commit

Permalink
fix: 알림 응답
Browse files Browse the repository at this point in the history
  • Loading branch information
SangWoon123 committed Aug 31, 2024
1 parent c2039d2 commit ed9edf0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class NotificationDTO {
// 식별 ID
private Long scheduleId;
private String userCode;
private String title;
private String message;
private String url;
private NotificationType notificationType;
Expand All @@ -26,6 +27,7 @@ public class NotificationDTO {
public static NotificationDTO createPersonalSchedule(String receiverCode, PersonalScheduleResponse response) {
return NotificationDTO.builder()
.scheduleId(response.id())
.title(response.title())
.userCode(receiverCode)
.message(response.content())
.url("/api/v1/schedule/" + response.id())
Expand All @@ -51,6 +53,7 @@ public static NotificationDTO createDailySchedule(String receiverCode, String me
public static NotificationDTO createGroupSchedule(String receiverCode, Schedule response) {
return NotificationDTO.builder()
.scheduleId(response.getId())
.title(response.getTitle())
.userCode(receiverCode)
.message(response.getContent())
.url("/api/v1/schedule/" + response.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public class Notification extends BaseEntity {

private String userCode;

@Column(name = "scheduleCount")
@Column(name = "title")
private String title;

@Column(name = "message")
private String message;

@Column(name = "group_name")
Expand All @@ -43,8 +46,9 @@ public class Notification extends BaseEntity {
private boolean isRead = false;

@Builder
public Notification(String userCode, String message, String groupName, String url, NotificationType notificationType, LocalDate scheduleDate, boolean isRead) {
public Notification(String userCode,String title, String message, String groupName, String url, NotificationType notificationType, LocalDate scheduleDate, boolean isRead) {
this.userCode = userCode;
this.title=title;
this.message = message;
this.groupName = groupName;
this.url = url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@

import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.Message;
import com.tukorea.planding.domain.group.entity.GroupRoom;
import com.tukorea.planding.domain.notify.dto.alarm.DailyNotificationDto;
import com.tukorea.planding.domain.notify.dto.alarm.NotificationDTO;
import com.tukorea.planding.domain.notify.entity.NotificationType;
import com.tukorea.planding.domain.schedule.entity.Schedule;
import com.tukorea.planding.domain.user.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import static com.tukorea.planding.domain.schedule.entity.QSchedule.schedule;

@Service
@Slf4j
@RequiredArgsConstructor
Expand All @@ -28,6 +24,7 @@ public void personalPublish(NotificationDTO notificationDTO) {
Message message = Message.builder()
.setToken(fcmToken)
.putData("scheduleId", String.valueOf(notificationDTO.getScheduleId()))
.putData("title",notificationDTO.getTitle())
.putData("message", notificationDTO.getMessage())
.putData("date", notificationDTO.getDate())
.putData("url", notificationDTO.getUrl())
Expand All @@ -52,6 +49,7 @@ public void groupPublish(NotificationDTO notificationDTO) {
Message message = Message.builder()
.setToken(fcmToken)
.putData("scheduleId", String.valueOf(notificationDTO.getScheduleId()))
.putData("title",notificationDTO.getTitle())
.putData("message", notificationDTO.getMessage())
.putData("date", notificationDTO.getDate())
.putData("url", notificationDTO.getUrl())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void sendNotification(NotificationDTO request) {
.groupName(request.getGroupName())
.notificationType(NotificationType.GROUP_SCHEDULE)
.scheduleDate(LocalDate.parse(request.getDate()))
.title(request.getTitle())
.message(request.getMessage())
.url(request.getUrl())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void sendNotification(NotificationDTO request) {

Notification notification = Notification.builder()
.userCode(request.getUserCode())
.title(request.getTitle())
.notificationType(NotificationType.PERSONAL_SCHEDULE)
.scheduleDate(LocalDate.parse(request.getDate()))
.message(request.getMessage())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.tukorea.planding.domain.notify.service.sse;

import com.tukorea.planding.domain.notify.dto.NotificationDTO;
import com.tukorea.planding.domain.notify.dto.alarm.NotificationDTO;
import com.tukorea.planding.domain.notify.repository.EmitterRepositoryImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -23,12 +23,14 @@ public SseEmitter createEmitter(String emitterKey) {
}

public void deleteEmitter(String emitterKey) {
log.info("emitter 삭제: {}",emitterKey);
emitterRepository.deleteById(emitterKey);
}

public void sendNotificationToClient(String emitterKey, NotificationDTO notificationDto) {
public void sendNotificationToClient(String emitterKey, NotificationDTO notificationDTO) {
log.info("sendNotificationToClient 동작 {}",emitterKey);
emitterRepository.findById(emitterKey)
.ifPresent(emitter -> send(notificationDto, emitterKey, emitter));
.ifPresent(emitter -> send(notificationDTO, emitterKey, emitter));
}

public void send(Object data, String emitterKey, SseEmitter sseEmitter) {
Expand Down

0 comments on commit ed9edf0

Please sign in to comment.