Skip to content

Commit

Permalink
fix: "안쓰는 class 삭제 및 알림 Enum 간소화 처리"
Browse files Browse the repository at this point in the history
  • Loading branch information
seonwoo-jung committed Jun 5, 2024
1 parent e1a2879 commit a4868bd
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import org.springframework.transaction.event.TransactionalEventListener;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;

import static com.tobe.healthy.common.LessonTimeFormatter.lessonStartDateTimeFormatter;
import static com.tobe.healthy.config.error.ErrorCode.SCHEDULE_NOT_FOUND;
import static com.tobe.healthy.course.domain.entity.CourseHistoryType.RESERVATION;
import static com.tobe.healthy.notification.domain.entity.NotificationType.WAITING;
Expand All @@ -32,7 +32,6 @@
@RequiredArgsConstructor
public class CustomEventListener {

private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M월 d일(E) h시");
private final int ONE_LESSON = 1;

private final CourseService courseService;
Expand All @@ -47,7 +46,7 @@ public class CustomEventListener {
public void handleEvent(CustomEvent event) {
switch (event.getType()) {
case SCHEDULE_CANCEL -> changeWaitingToCompleted((Long) event.getResult());
case SCHEDULE_NOTIFICATION, LESSON_HISTORY_NOTIFICATION -> sendNotification((CommandSendNotification) event.getResult());
case NOTIFICATION -> sendNotification((CommandSendNotification) event.getResult());
}
}

Expand All @@ -72,7 +71,7 @@ public void changeWaitingToCompleted(Long scheduleId) {

CommandSendNotification request = new CommandSendNotification(
WAITING.getDescription(),
String.format("%s 대기 중이던 예약이 확정되었어요!", LocalDateTime.of(schedule.getLessonDt(), schedule.getLessonStartTime()).format(formatter)),
String.format("%s 대기 중이던 예약이 확정되었어요!", LocalDateTime.of(schedule.getLessonDt(), schedule.getLessonStartTime()).format(lessonStartDateTimeFormatter())),
List.of(schedule.getApplicant().getId()),

Check warning on line 75 in src/main/java/com/tobe/healthy/common/event/CustomEventListener.java

View workflow job for this annotation

GitHub Actions / qodana

Nullability and data flow problems

Method invocation `getId` may produce `NullPointerException`

Check warning on line 75 in src/main/java/com/tobe/healthy/common/event/CustomEventListener.java

View workflow job for this annotation

GitHub Actions / qodana

Nullability and data flow problems

Method invocation `getId` may produce `NullPointerException`
WAITING,
null
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/tobe/healthy/common/event/EventType.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
public enum EventType {

SCHEDULE_CANCEL("트레이너 또는 학생이 수업을 취소한 경우"),
SCHEDULE_NOTIFICATION("학생이 수업을 신청한 경우 알림 전송"),
LESSON_HISTORY_NOTIFICATION("수업일지에 댓글/답글을 등록했을 때 알림 전송");
NOTIFICATION("사용자에게 알림 전송");

private final String description;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import java.time.format.DateTimeFormatter;
import java.util.List;

import static com.tobe.healthy.common.event.EventType.NOTIFICATION;
import static com.tobe.healthy.common.event.EventType.SCHEDULE_CANCEL;
import static com.tobe.healthy.common.event.EventType.SCHEDULE_NOTIFICATION;
import static com.tobe.healthy.config.error.ErrorCode.*;
import static com.tobe.healthy.notification.domain.entity.NotificationType.CANCEL;
import static com.tobe.healthy.notification.domain.entity.NotificationType.RESERVE;
Expand Down Expand Up @@ -60,7 +60,7 @@ public ScheduleIdInfo reserveSchedule(Long scheduleId, Long memberId) {
null
);

notificationPublisher.publish(notification, SCHEDULE_NOTIFICATION);
notificationPublisher.publish(notification, NOTIFICATION);

return ScheduleIdInfo.create(schedule, getScheduleTimeText(schedule.getLessonStartTime()));
}
Expand All @@ -81,7 +81,7 @@ public ScheduleIdInfo cancelMemberSchedule(Long scheduleId, Long memberId) {
null
);

notificationPublisher.publish(notification, SCHEDULE_NOTIFICATION);
notificationPublisher.publish(notification, NOTIFICATION);

ScheduleIdInfo idInfo = ScheduleIdInfo.create(schedule, getScheduleTimeText(schedule.getLessonStartTime()));
schedule.cancelMemberSchedule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ object LessonTimeFormatter {
val formatter = DateTimeFormatter.ofPattern("MM월 dd일 E요일", Locale.KOREAN)
return lessonDt?.format(formatter)
}
}

@JvmStatic
fun lessonStartDateTimeFormatter(): DateTimeFormatter {
return DateTimeFormatter.ofPattern("M월 d일(E) h시")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.tobe.healthy.common.FileUpload.FILE_TEMP_UPLOAD_TIMEOUT
import com.tobe.healthy.common.Utils.createFileName
import com.tobe.healthy.common.Utils.createObjectMetadata
import com.tobe.healthy.common.event.CustomEventPublisher
import com.tobe.healthy.common.event.EventType.LESSON_HISTORY_NOTIFICATION
import com.tobe.healthy.common.event.EventType.NOTIFICATION
import com.tobe.healthy.common.redis.RedisKeyPrefix.TEMP_FILE_URI
import com.tobe.healthy.common.redis.RedisService
import com.tobe.healthy.config.error.CustomException
Expand Down Expand Up @@ -77,7 +77,7 @@ class LessonHistoryCommandService(
lessonHistory.id
)

notificationPublisher.publish(notification, LESSON_HISTORY_NOTIFICATION)
notificationPublisher.publish(notification, NOTIFICATION)

return CommandRegisterLessonHistoryResult.from(lessonHistory, files)
}
Expand Down Expand Up @@ -171,7 +171,7 @@ class LessonHistoryCommandService(
lessonHistory.id
)

notificationPublisher.publish(notification, LESSON_HISTORY_NOTIFICATION)
notificationPublisher.publish(notification, NOTIFICATION)

return CommandRegisterCommentResult.from(lessonHistoryComment, files)
}
Expand Down Expand Up @@ -208,7 +208,7 @@ class LessonHistoryCommandService(
lessonHistory.id
)

notificationPublisher.publish(notification, LESSON_HISTORY_NOTIFICATION)
notificationPublisher.publish(notification, NOTIFICATION)

lessonHistoryCommentRepository.save(entity)

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.tobe.healthy.schedule.application

import com.tobe.healthy.common.event.CustomEventPublisher
import com.tobe.healthy.common.event.EventType
import com.tobe.healthy.common.event.EventType.NOTIFICATION
import com.tobe.healthy.common.event.EventType.SCHEDULE_CANCEL
import com.tobe.healthy.config.error.CustomException
import com.tobe.healthy.config.error.ErrorCode.*
Expand Down Expand Up @@ -210,7 +210,7 @@ class TrainerScheduleCommandService(
RESERVE
)

notificationPublisher.publish(notification, EventType.SCHEDULE_NOTIFICATION)
notificationPublisher.publish(notification, NOTIFICATION)

return CommandRegisterScheduleByStudentResult.from(schedule, findStudent)
}
Expand All @@ -236,7 +236,7 @@ class TrainerScheduleCommandService(
CANCEL
)

notificationPublisher.publish(notification, EventType.SCHEDULE_NOTIFICATION)
notificationPublisher.publish(notification, NOTIFICATION)

eventPublisher.publish(schedule.id, SCHEDULE_CANCEL)

Expand Down
13 changes: 0 additions & 13 deletions src/main/resources/static/firebase-messaging-sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,6 @@ firebase.initializeApp({

const messaging = firebase.messaging();

messaging.onBackgroundMessage((payload) => {
console.log('[firebase-messaging-sw.js] Received background message ', payload);

// Customize notification here
const notificationTitle = 'Background Message Title';
const notificationOptions = {
body: 'Background Message body.',
icon: '/firebase-logo.png'
};

self.registration.showNotification(notificationTitle, notificationOptions);
});

self.addEventListener('push', function(event) {
var message = event.data ? event.data.json() : {};
event.waitUntil(
Expand Down

0 comments on commit a4868bd

Please sign in to comment.