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 ) ) } } }