-
Notifications
You must be signed in to change notification settings - Fork 0
[fix] FCM 메세지 분류용 messageType 필드 추가 #325
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
Changes from 3 commits
b46d01e
2d322fc
5410edf
2db9f68
e912cf5
da998f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.kustacks.kuring.admin.adapter.in.web.dto; | ||
|
|
||
| import com.kustacks.kuring.message.application.port.in.dto.AcademicTestNotificationCommand; | ||
|
|
||
| public record AcademicTestNotificationRequest( | ||
| String title, | ||
| String body | ||
| ) { | ||
| public AcademicTestNotificationCommand toCommand() { | ||
| return new AcademicTestNotificationCommand(title, body); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.kustacks.kuring.message.adapter.in.event.dto; | ||
|
|
||
| import com.kustacks.kuring.message.application.port.in.dto.AcademicTestNotificationCommand; | ||
|
|
||
| public record AcademicTestNotificationEvent( | ||
| String title, | ||
| String body | ||
| ) { | ||
| public AcademicTestNotificationCommand toCommand() { | ||
| return new AcademicTestNotificationCommand(title, body); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,14 @@ | ||
| package com.kustacks.kuring.message.application.port.in; | ||
|
|
||
| import com.kustacks.kuring.message.application.port.in.dto.AcademicTestNotificationCommand; | ||
| import com.kustacks.kuring.message.application.port.in.dto.AdminNotificationCommand; | ||
| import com.kustacks.kuring.message.application.port.in.dto.AdminTestNotificationCommand; | ||
|
|
||
| public interface FirebaseWithAdminUseCase { | ||
| void sendNotificationByAdmin(AdminNotificationCommand command); | ||
|
|
||
| void sendTestNotificationByAdmin(AdminTestNotificationCommand command); | ||
|
|
||
| void sendAcademicTestNotification(AcademicTestNotificationCommand command); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.kustacks.kuring.message.application.port.in.dto; | ||
|
|
||
| public record AcademicTestNotificationCommand( | ||
| String title, | ||
| String body | ||
| ) { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| import com.kustacks.kuring.common.exception.code.ErrorCode; | ||
| import com.kustacks.kuring.common.properties.ServerProperties; | ||
| import com.kustacks.kuring.message.application.port.in.FirebaseWithAdminUseCase; | ||
| import com.kustacks.kuring.message.application.port.in.dto.AcademicTestNotificationCommand; | ||
| import com.kustacks.kuring.message.application.port.in.dto.AdminNotificationCommand; | ||
| import com.kustacks.kuring.message.application.port.in.dto.AdminTestNotificationCommand; | ||
| import com.kustacks.kuring.message.application.port.out.FirebaseMessagingPort; | ||
|
|
@@ -22,6 +23,7 @@ | |
| import java.util.Map; | ||
| import java.util.function.UnaryOperator; | ||
|
|
||
| import static com.kustacks.kuring.message.application.service.FirebaseSubscribeService.ACADEMIC_EVENT_TOPIC; | ||
| import static com.kustacks.kuring.message.application.service.FirebaseSubscribeService.ALL_DEVICE_SUBSCRIBED_TOPIC; | ||
|
|
||
| @Slf4j | ||
|
|
@@ -62,6 +64,29 @@ | |
| sendNotices(notificationDtoList); | ||
| } | ||
|
|
||
| @Override | ||
| public void sendAcademicTestNotification(AcademicTestNotificationCommand command) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 근데, 이걸 test용도로 만들어다는거는? 향후 Prod 목적으로도 동일한 메서드가 추가되는건가요? 단일 메서드를 두고 환경(머신 자체의 linux 환경값에)에 따라 다르게 전달하는건 어떤가요?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 학사일정 알림이 원래는 스케줄러에서 자동으로 전송돼서 prod용으로 수동 전송하는 api를 따로 추가안할 것 같습니다! 이건 test용도로 수동으로 알림 전송해봐서 확인해보려고 만들었습니다!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 엇 근데 지금 공지 알림 전송은 test용이랑 prod용 메서드가 따로 존재하네요! 단일 메서드로 하면 코드가 깔끔해질 것 같긴 한데 실수로 prod로 알림이 전송되는 일이 있을 수도 있어서.. 어떤게 더 좋을까여??
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메서드에서 test를 명시해주신 지금 방식이 더 주의를 할 수 있어서 장점이 충분한것 같습니다!. |
||
| try { | ||
| Message newMessage = Message.builder() | ||
| .setNotification(Notification.builder() | ||
| .setTitle(command.title()) | ||
| .setBody(command.body()) | ||
| .build()) | ||
| .putAllData(Map.of( | ||
| "title", command.title(), | ||
| "body", command.body() | ||
| )) | ||
| .putData("messageType", "academic") | ||
|
Check failure on line 79 in src/main/java/com/kustacks/kuring/message/application/service/FirebaseNotificationService.java
|
||
| .setTopic(serverProperties.addDevSuffix(ACADEMIC_EVENT_TOPIC)) | ||
| .build(); | ||
|
|
||
| firebaseMessagingPort.send(newMessage); | ||
| } catch (FirebaseMessagingException exception) { | ||
| throw new FirebaseMessageSendException(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| private void sendNotices(List<NoticeMessageDto> notificationDtoList) { | ||
| try { | ||
| loggingNoticeSendInfo(notificationDtoList); | ||
|
|
@@ -127,6 +152,7 @@ | |
| .setBody(command.body()) | ||
| .build()) | ||
| .putAllData(objectMapper.convertValue(command, Map.class)) | ||
| .putData("messageType", "admin") | ||
| .setTopic(serverProperties.ifDevThenAddSuffix(ALL_DEVICE_SUBSCRIBED_TOPIC)) | ||
| .build(); | ||
| } | ||
|
|
@@ -139,6 +165,7 @@ | |
| .setBody(messageDto.getSubject()) | ||
| .build()) | ||
| .putAllData(objectMapper.convertValue(messageDto, Map.class)) | ||
| .putData("messageType", "notice") | ||
| .setTopic(suffixUtil.apply(messageDto.getCategory())) | ||
| .build(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package com.kustacks.kuring.acceptance; | ||
|
|
||
| import com.kustacks.kuring.admin.adapter.in.web.dto.AcademicTestNotificationRequest; | ||
| import com.kustacks.kuring.admin.adapter.in.web.dto.AdminAlertCreateRequest; | ||
| import com.kustacks.kuring.admin.adapter.in.web.dto.RealNotificationRequest; | ||
| import com.kustacks.kuring.admin.adapter.in.web.dto.TestNotificationRequest; | ||
|
|
@@ -150,6 +151,33 @@ void role_root_admin_create_real_notification() { | |
| ); | ||
| } | ||
|
|
||
| @DisplayName("[v2] 테스트 학사일정 알림 발송") | ||
| @Test | ||
| void role_root_admin_send_academic_test_notification() { | ||
| // given | ||
| String accessToken = 로그인_되어_있음(ADMIN_LOGIN_ID, ADMIN_PASSWORD); | ||
|
|
||
| // when | ||
| var response = RestAssured | ||
| .given().log().all() | ||
| .header("Authorization", "Bearer " + accessToken) | ||
| .contentType(MediaType.APPLICATION_JSON_VALUE) | ||
| .accept(MediaType.APPLICATION_JSON_VALUE) | ||
| .body(new AcademicTestNotificationRequest("테스트-수강신청 일정", "오늘은 수강신청 일정이 있어요")) | ||
| .when().post("/api/v2/admin/academic/dev") | ||
| .then().log().all() | ||
| .extract(); | ||
|
||
|
|
||
| // then | ||
| assertAll( | ||
| () -> assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()), | ||
| () -> assertThat(response.jsonPath().getInt("code")).isEqualTo(200), | ||
| () -> assertThat(response.jsonPath().getString("message")) | ||
| .isEqualTo("테스트 학사일정 알림 생성에 성공하였습니다"), | ||
| () -> assertThat(response.jsonPath().getString("data")).isNull() | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Given : 등록된 ROLE_ROOT의 Admin이 있다. | ||
| * When : 원하는 시간에 예약 알림을 등록한다 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
소나큐브 이슈에도 비슷한 내용이 있는데 enum화 해두는게 어떤지요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 enum화 하는게 훨씬 좋을 것 같아요!!