diff --git a/dmforu-admin/build.gradle.kts b/dmforu-admin/build.gradle.kts index c5578e8..c0dff20 100644 --- a/dmforu-admin/build.gradle.kts +++ b/dmforu-admin/build.gradle.kts @@ -13,7 +13,7 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-web") - runtimeOnly(project(":dmforu-infrastructure:sqs")) + runtimeOnly(project(":dmforu-infrastructure:fcm")) runtimeOnly(project(":dmforu-infrastructure:storage:mysql")) runtimeOnly(project(":dmforu-infrastructure:storage:mongo")) diff --git a/dmforu-admin/src/main/kotlin/com/dmforu/admin/AdminApplication.kt b/dmforu-admin/src/main/kotlin/com/dmforu/admin/AdminApplication.kt index 10ecf15..ca6d4be 100644 --- a/dmforu-admin/src/main/kotlin/com/dmforu/admin/AdminApplication.kt +++ b/dmforu-admin/src/main/kotlin/com/dmforu/admin/AdminApplication.kt @@ -8,7 +8,7 @@ import java.util.* @SpringBootApplication( scanBasePackages = [ "com.dmforu.admin", - "com.dmforu.sqs", + "com.dmforu.fcm", "com.dmforu.storage.db.mongo", "com.dmforu.storage.db.mysql" ] diff --git a/dmforu-admin/src/main/kotlin/com/dmforu/admin/message/MessageService.kt b/dmforu-admin/src/main/kotlin/com/dmforu/admin/message/MessageService.kt index e539c75..67b9de0 100644 --- a/dmforu-admin/src/main/kotlin/com/dmforu/admin/message/MessageService.kt +++ b/dmforu-admin/src/main/kotlin/com/dmforu/admin/message/MessageService.kt @@ -23,6 +23,18 @@ class MessageService( sendDepartmentNoticeMessage(notice) } + fun sendTestNoticeMessage(token: String, notice: Notice) { + if (notice.isUniversityNotice()) { + val keyword = keywordFilter.extractKeywordFrom(notice.title) ?: return + val message = NoticeMessage.createUniversityNoticeMessage(notice = notice, keyword = keyword) + messageSender.sendNoticeMessage(message = message, tokens = listOf(token)) + return + } + + val message = NoticeMessage.createDepartmentNoticeMessage(notice = notice) + messageSender.sendNoticeMessage(message = message, tokens = listOf(token)) + } + private fun sendUniversityNoticeMessage(notice: Notice) { val keyword = keywordFilter.extractKeywordFrom(notice.title) ?: return diff --git a/dmforu-admin/src/main/kotlin/com/dmforu/admin/presentation/PushMessageController.kt b/dmforu-admin/src/main/kotlin/com/dmforu/admin/presentation/PushMessageController.kt new file mode 100644 index 0000000..b57c3e7 --- /dev/null +++ b/dmforu-admin/src/main/kotlin/com/dmforu/admin/presentation/PushMessageController.kt @@ -0,0 +1,30 @@ +package com.dmforu.admin.presentation + +import com.dmforu.admin.message.MessageService +import com.dmforu.admin.presentation.request.SendNoticeMessageRequest +import com.dmforu.domain.notice.Notice +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RestController +import java.time.LocalDate + +@RestController +class PushMessageController( + private val messageService: MessageService, +) { + @PostMapping("/api/v1/messages/notice") + fun sendMessageToEvery(@RequestBody request: SendNoticeMessageRequest) { + val notice = Notice.of( + number = 0, + type = request.type, + date = LocalDate.now(), + title = request.title, + author = "관리자", + url = request.url + ) + + messageService.sendTestNoticeMessage(request.token, notice) + } + +} \ No newline at end of file diff --git a/dmforu-admin/src/main/kotlin/com/dmforu/admin/presentation/request/SendNoticeMessageRequest.kt b/dmforu-admin/src/main/kotlin/com/dmforu/admin/presentation/request/SendNoticeMessageRequest.kt new file mode 100644 index 0000000..916f161 --- /dev/null +++ b/dmforu-admin/src/main/kotlin/com/dmforu/admin/presentation/request/SendNoticeMessageRequest.kt @@ -0,0 +1,9 @@ +package com.dmforu.admin.presentation.request + +data class SendNoticeMessageRequest( + val token: String, + val title: String, + val type: String, + val body: String, + val url: String +)