Files
sodalive-backend-spring-boot/src/main/kotlin/kr/co/vividnext/sodalive/fcm/FcmController.kt
Klaus 3ada2dea87 관리자 - 푸시 발송
- 본인 인증 여부에 따라 푸시 메시지를 발송할 수 있도록 isAuth 플래그 추가
2023-11-24 14:58:30 +09:00

53 lines
1.8 KiB
Kotlin

package kr.co.vividnext.sodalive.fcm
import org.springframework.context.ApplicationEventPublisher
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("/push")
@PreAuthorize("hasRole('ADMIN')")
class FcmController(private val applicationEventPublisher: ApplicationEventPublisher) {
@PostMapping
@Transactional(readOnly = true)
fun send(
@RequestBody request: PushRequest
) = run {
if (request.memberIds.isNotEmpty()) {
applicationEventPublisher.publishEvent(
FcmEvent(
type = FcmEventType.INDIVIDUAL,
title = request.title,
isAuth = request.isAuth,
message = request.message,
recipients = request.memberIds
)
)
} else {
applicationEventPublisher.publishEvent(
FcmEvent(
type = FcmEventType.ALL,
title = request.title,
message = request.message,
container = "ios",
isAuth = request.isAuth
)
)
applicationEventPublisher.publishEvent(
FcmEvent(
type = FcmEventType.ALL,
title = request.title,
message = request.message,
container = "aos",
isAuth = request.isAuth
)
)
}
}
}