Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kustacks.kuring.admin.adapter.in.web;

import com.google.firebase.database.annotations.NotNull;
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;
Expand Down Expand Up @@ -38,6 +39,7 @@

import static com.kustacks.kuring.common.dto.ResponseCodeAndMessages.ADMIN_EMBEDDING_NOTICE_SUCCESS;
import static com.kustacks.kuring.common.dto.ResponseCodeAndMessages.ADMIN_REAL_NOTICE_CREATE_SUCCESS;
import static com.kustacks.kuring.common.dto.ResponseCodeAndMessages.ADMIN_TEST_ACADEMIC_CREATE_SUCCESS;
import static com.kustacks.kuring.common.dto.ResponseCodeAndMessages.ADMIN_TEST_NOTICE_CREATE_SUCCESS;

@Tag(name = "Admin-Command", description = "관리자가 주체가 되는 정보 수정")
Expand Down Expand Up @@ -75,6 +77,18 @@ public ResponseEntity<BaseResponse<String>> createRealNotice(
return ResponseEntity.ok().body(new BaseResponse<>(ADMIN_REAL_NOTICE_CREATE_SUCCESS, null));
}

@Operation(summary = "테스트 학사일정 알림 전송", description = "테스트 학사일정 알림을 전송합니다, 실제 운영시 사용하지 않습니다")
@SecurityRequirement(name = "JWT")
@Secured(AdminRole.ROLE_ROOT)
@PostMapping("/academic/dev")
public ResponseEntity<BaseResponse<String>> sendAcademicTest(
@RequestBody AcademicTestNotificationRequest request
) {
adminCommandUseCase.createAcademicTestNotification(request.toCommand());
return ResponseEntity.ok().body(new BaseResponse<>(ADMIN_TEST_ACADEMIC_CREATE_SUCCESS, null));
}


@Operation(summary = "예약 알림 등록", description = "서버에 알림 시간을 yyyy-MM-dd HH:mm:ss 형태로 요청시 예약 알림을 등록한다")
@SecurityRequirement(name = "JWT")
@Secured(AdminRole.ROLE_ROOT)
Expand Down
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
Expand Up @@ -2,6 +2,7 @@

import com.kustacks.kuring.admin.application.port.out.AdminEventPort;
import com.kustacks.kuring.common.domain.Events;
import com.kustacks.kuring.message.adapter.in.event.dto.AcademicTestNotificationEvent;
import com.kustacks.kuring.message.adapter.in.event.dto.AdminNotificationEvent;
import com.kustacks.kuring.message.adapter.in.event.dto.AdminTestNotificationEvent;
import com.kustacks.kuring.message.application.service.exception.FirebaseMessageSendException;
Expand Down Expand Up @@ -37,4 +38,9 @@ public void sendTestNotificationByAdmin(
.build()
);
}

@Override
public void sendAcademicTestNotification(String title, String body) {
Events.raise(new AcademicTestNotificationEvent(title, body));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.kustacks.kuring.admin.application.port.in.dto.TestNotificationCommand;
import com.kustacks.kuring.alert.application.port.in.dto.AlertCreateCommand;
import com.kustacks.kuring.alert.application.port.in.dto.DataEmbeddingCommand;
import com.kustacks.kuring.message.application.port.in.dto.AcademicTestNotificationCommand;

public interface AdminCommandUseCase {

Expand All @@ -18,4 +19,7 @@ public interface AdminCommandUseCase {
void embeddingCustomData(DataEmbeddingCommand command);

void resubscribeAllUsersToTopics();

void createAcademicTestNotification(AcademicTestNotificationCommand command);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ void sendTestNotificationByAdmin(
String korName,
String url
) throws FirebaseMessageSendException;

void sendAcademicTestNotification(String title, String body);

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.kustacks.kuring.auth.userdetails.UserDetailsServicePort;
import com.kustacks.kuring.common.annotation.UseCase;
import com.kustacks.kuring.common.properties.ServerProperties;
import com.kustacks.kuring.message.application.port.in.dto.AcademicTestNotificationCommand;
import com.kustacks.kuring.message.application.port.out.FirebaseSubscribePort;
import com.kustacks.kuring.notice.domain.CategoryName;
import com.kustacks.kuring.user.application.port.out.UserQueryPort;
Expand Down Expand Up @@ -82,6 +83,14 @@ public void createRealNoticeForAllUser(RealNotificationCommand command) {
adminEventPort.sendNotificationByAdmin(command.title(), command.body(), command.url());
}

@Override
public void createAcademicTestNotification(AcademicTestNotificationCommand command) {
adminEventPort.sendAcademicTestNotification(
command.title(),
command.body()
);
}

@Override
public void addAlertSchedule(AlertCreateCommand command) {
adminAlertEventPort.addAlertSchedule(command.title(), command.content(), command.alertTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.List;

import static com.kustacks.kuring.message.application.service.FirebaseSubscribeService.ACADEMIC_EVENT_TOPIC;
import static com.kustacks.kuring.message.domain.MessageType.ACADEMIC;

@Slf4j
@UseCase
Expand Down Expand Up @@ -99,6 +100,7 @@ private Message makeMessage(String title, String body) {
.setTopic(serverProperties.ifDevThenAddSuffix(ACADEMIC_EVENT_TOPIC))
.putData("title", title)
.putData("body", body)
.putData("messageType", ACADEMIC.getValue())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum ResponseCodeAndMessages {
ADMIN_LOAD_BAD_WORDS(HttpStatus.OK.value(), "금칙어 로드에 성공했습니다."),
ADMIN_LOAD_WHITELIST_WORDS(HttpStatus.OK.value(), "허용 단어 로드에 성공했습니다."),
ADMIN_USER_SUBSCRIPTION_UPDATE_SUCCESS(HttpStatus.OK.value(), "사용자들의 구독 정보를 성공적으로 재설정했습니다."),
ADMIN_TEST_ACADEMIC_CREATE_SUCCESS(HttpStatus.OK.value(), "테스트 학사일정 알림 생성에 성공하였습니다"),

/* User */
USER_REGISTER_SUCCESS(HttpStatus.OK.value(), "회원가입에 성공하였습니다"),
Expand All @@ -52,7 +53,7 @@ public enum ResponseCodeAndMessages {

/* Email */
EMAIL_SEND_SUCCESS(HttpStatus.OK.value(), "이메일 전송에 성공했습니다."),
EMAIL_CODE_VERIFY_SUCCESS(HttpStatus.OK.value(),"인증에 성공했습니다."),
EMAIL_CODE_VERIFY_SUCCESS(HttpStatus.OK.value(), "인증에 성공했습니다."),

REPORT_SEARCH_SUCCESS(HttpStatus.OK.value(), "신고 목록 조회에 성공하였습니다"),
REPORT_COMMENT_SUCCESS(HttpStatus.CREATED.value(), "댓글 신고에 성공했습니다"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kustacks.kuring.message.adapter.in.event;

import com.kustacks.kuring.message.adapter.in.event.dto.AcademicTestNotificationEvent;
import com.kustacks.kuring.message.adapter.in.event.dto.AdminNotificationEvent;
import com.kustacks.kuring.message.adapter.in.event.dto.AdminTestNotificationEvent;
import com.kustacks.kuring.message.adapter.in.event.dto.AlertSendEvent;
Expand Down Expand Up @@ -37,4 +38,13 @@ public void sendAlertEvent(
) {
firebaseWithAdminUseCase.sendNotificationByAdmin(event.toCommand());
}

@Async
@EventListener
public void sendAcademicTestNotificationEvent(
AcademicTestNotificationEvent event
) {
firebaseWithAdminUseCase.sendAcademicTestNotification(event.toCommand());
}

}
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
Expand Up @@ -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;
Expand All @@ -22,7 +23,11 @@
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;
import static com.kustacks.kuring.message.domain.MessageType.ACADEMIC;
import static com.kustacks.kuring.message.domain.MessageType.ADMIN;
import static com.kustacks.kuring.message.domain.MessageType.NOTICE;

@Slf4j
@UseCase
Expand Down Expand Up @@ -62,6 +67,29 @@ public void sendNotifications(List<? extends Notice> noticeList) {
sendNotices(notificationDtoList);
}

@Override
public void sendAcademicTestNotification(AcademicTestNotificationCommand command) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

근데, 이걸 test용도로 만들어다는거는? 향후 Prod 목적으로도 동일한 메서드가 추가되는건가요? 단일 메서드를 두고 환경(머신 자체의 linux 환경값에)에 따라 다르게 전달하는건 어떤가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

학사일정 알림이 원래는 스케줄러에서 자동으로 전송돼서 prod용으로 수동 전송하는 api를 따로 추가안할 것 같습니다! 이건 test용도로 수동으로 알림 전송해봐서 확인해보려고 만들었습니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엇 근데 지금 공지 알림 전송은 test용이랑 prod용 메서드가 따로 존재하네요! 단일 메서드로 하면 코드가 깔끔해질 것 같긴 한데 실수로 prod로 알림이 전송되는 일이 있을 수도 있어서.. 어떤게 더 좋을까여??

Copy link
Member

Choose a reason for hiding this comment

The 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(),
"messageType", ACADEMIC.getValue()
))
.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);
Expand Down Expand Up @@ -127,6 +155,7 @@ private Message createMessageFromCommand(AdminNotificationCommand command) {
.setBody(command.body())
.build())
.putAllData(objectMapper.convertValue(command, Map.class))
.putData("messageType", ADMIN.getValue())
.setTopic(serverProperties.ifDevThenAddSuffix(ALL_DEVICE_SUBSCRIBED_TOPIC))
.build();
}
Expand All @@ -139,6 +168,7 @@ private Message createMessageFromDto(NoticeMessageDto messageDto, UnaryOperator<
.setBody(messageDto.getSubject())
.build())
.putAllData(objectMapper.convertValue(messageDto, Map.class))
.putData("messageType", NOTICE.getValue())
.setTopic(suffixUtil.apply(messageDto.getCategory()))
.build();
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/kustacks/kuring/message/domain/MessageType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.kustacks.kuring.message.domain;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum MessageType {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum화 하여 관리하시는점 좋습니다!!


NOTICE("notice"),
ADMIN("admin"),
ACADEMIC("academic");

private final String value;
}
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;
Expand Down Expand Up @@ -27,6 +28,7 @@
import static com.kustacks.kuring.acceptance.AdminStep.알림_예약;
import static com.kustacks.kuring.acceptance.AdminStep.예약_알림_삭제;
import static com.kustacks.kuring.acceptance.AdminStep.예약_알림_조회;
import static com.kustacks.kuring.acceptance.AdminStep.테스트_학사일정_알림_발송;
import static com.kustacks.kuring.acceptance.AdminStep.피드백_조회_확인;
import static com.kustacks.kuring.acceptance.AdminStep.허용_단어_로드_요청;
import static com.kustacks.kuring.acceptance.AuthStep.로그인_되어_있음;
Expand Down Expand Up @@ -150,6 +152,28 @@ 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 = 테스트_학사일정_알림_발송(
accessToken,
new AcademicTestNotificationRequest("테스트-수강신청 일정", "오늘은 수강신청 일정이 있어요")
);

// 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 : 원하는 시간에 예약 알림을 등록한다
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/com/kustacks/kuring/acceptance/AdminStep.java
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 io.restassured.RestAssured;
import io.restassured.response.ExtractableResponse;
Expand Down Expand Up @@ -137,4 +138,20 @@ public class AdminStep {
() -> assertThat(response.jsonPath().getString("data")).isNull()
);
}

public static ExtractableResponse<Response> 테스트_학사일정_알림_발송(
String accessToken,
AcademicTestNotificationRequest request
) {
return RestAssured
.given().log().all()
.header("Authorization", "Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE)
.body(request)
.when().post("/api/v2/admin/academic/dev")
.then().log().all()
.extract();
}

}
Loading