Skip to content

Commit

Permalink
[IDLE-504] 센터 관리자 인증 승인 및 거절 API
Browse files Browse the repository at this point in the history
  • Loading branch information
wonjunYou committed Nov 22, 2024
1 parent 3b22693 commit ac6c04c
Show file tree
Hide file tree
Showing 17 changed files with 372 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ data class CarerApplyNotificationInfo(
val notificationDetails = mapOf(
"jobPostingId" to jobPostingId,
)

return CarerApplyNotificationInfo(
title,
body,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.swm.idle.application.user.center.service.event

import com.swm.idle.domain.user.center.event.CenterManagerVerificationApproveEvent
import org.springframework.context.ApplicationEventPublisher
import org.springframework.stereotype.Service

@Service
class CenterManagerVerificationApproveEventPublisher(
private val eventPublisher: ApplicationEventPublisher,
) {

fun publish(centerManagerVerificationApproveEvent: CenterManagerVerificationApproveEvent) {
eventPublisher.publishEvent(centerManagerVerificationApproveEvent)
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.swm.idle.application.user.center.service.event

import com.swm.idle.domain.user.center.event.CenterManagerVerificationRejectEvent
import org.springframework.context.ApplicationEventPublisher
import org.springframework.stereotype.Service

@Service
class CenterManagerVerificationRejectEventPublisher(
private val eventPublisher: ApplicationEventPublisher,
) {

fun publish(centerManagerVerificationRejectEvent: CenterManagerVerificationRejectEvent) {
eventPublisher.publishEvent(centerManagerVerificationRejectEvent)
}

}

Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package com.swm.idle.application.user.center.service.facade

import com.swm.idle.application.common.security.getUserAuthentication
import com.swm.idle.application.notification.domain.DeviceTokenService
import com.swm.idle.application.notification.domain.NotificationService
import com.swm.idle.application.user.center.service.domain.CenterManagerService
import com.swm.idle.application.user.center.service.event.CenterManagerVerificationApproveEventPublisher
import com.swm.idle.application.user.center.service.event.CenterManagerVerificationRejectEventPublisher
import com.swm.idle.application.user.center.service.event.CenterManagerVerificationRequestEventPublisher
import com.swm.idle.application.user.center.vo.CenterManagerVerificationApproveNotificationInfo
import com.swm.idle.application.user.center.vo.CenterManagerVerificationRejectNotificationInfo
import com.swm.idle.application.user.common.service.domain.DeletedUserInfoService
import com.swm.idle.application.user.common.service.domain.RefreshTokenService
import com.swm.idle.application.user.common.service.util.JwtTokenService
import com.swm.idle.domain.common.enums.EntityStatus
import com.swm.idle.domain.common.exception.PersistenceException
import com.swm.idle.domain.notification.enums.NotificationType
import com.swm.idle.domain.user.center.event.CenterManagerVerificationApproveEvent
import com.swm.idle.domain.user.center.event.CenterManagerVerificationRejectEvent
import com.swm.idle.domain.user.center.event.CenterManagerVerificationRequestEvent.Companion.createVerifyEvent
import com.swm.idle.domain.user.center.exception.CenterException
import com.swm.idle.domain.user.center.vo.BusinessRegistrationNumber
Expand All @@ -26,6 +35,7 @@ import com.swm.idle.support.transfer.user.center.JoinStatusInfoResponse
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Propagation
import org.springframework.transaction.annotation.Transactional
import java.util.*

@Service
class CenterAuthFacadeService(
Expand All @@ -35,6 +45,10 @@ class CenterAuthFacadeService(
private val jwtTokenService: JwtTokenService,
private val refreshTokenService: RefreshTokenService,
private val centerManagerVerificationRequestEventPublisher: CenterManagerVerificationRequestEventPublisher,
private val centerManagerVerificationApproveEventPublisher: CenterManagerVerificationApproveEventPublisher,
private val centerManagerVerificationRejectEventPublisher: CenterManagerVerificationRejectEventPublisher,
private val deviceTokenService: DeviceTokenService,
private val notificationService: NotificationService,
) {

fun join(
Expand Down Expand Up @@ -152,6 +166,7 @@ class CenterAuthFacadeService(
}
}


fun getCenterManagerForPending(): CenterManagerForPendingResponse {
val centerManagers = centerManagerService.findAllByStatusPending()

Expand All @@ -162,4 +177,65 @@ class CenterAuthFacadeService(
} ?: CenterManagerForPendingResponse.of(emptyList())
}

@Transactional
fun approveVerification(centerManagerId: UUID) {
val centerManager = centerManagerService.getById(centerManagerId)

if (centerManager.isPending().not()) {
throw CenterException.IsNotPendingException()
}

centerManager.approve()

deviceTokenService.findByUserId(centerManagerId)?.let {
val notificationInfo = CenterManagerVerificationApproveNotificationInfo.of(
title = "[케어밋] 센터 관리자 인증 요청이 승인되었어요!",
body = "${centerManager.name} 관리자님! 센터 관리자 인증 요청이 최종 승인되었어요! 어서 확인해 보세요!",
receiverId = centerManager.id,
notificationType = NotificationType.CENTER_AUTHENTICATION,
)

val notification = notificationService.create(notificationInfo)


CenterManagerVerificationApproveEvent(
deviceToken = it.toString(),
notificationId = notification.id,
notificationInfo = notificationInfo
).also {
centerManagerVerificationApproveEventPublisher.publish(it)
}
}
}

@Transactional
fun rejectVerification(centerManagerId: UUID) {
val centerManager = centerManagerService.getById(centerManagerId)

if (centerManager.isPending().not()) {
throw CenterException.IsNotPendingException()
}

centerManager.reject()

deviceTokenService.findByUserId(centerManagerId)?.let {
val notificationInfo = CenterManagerVerificationRejectNotificationInfo.of(
title = "[케어밋] 센터 관리자 인증 요청이 거절되었어요.",
body = "${centerManager.name} 관리자님, 센터 관리자 인증 요청이 거절되었어요. 문의사항을 통해 연락해 주세요.",
receiverId = centerManager.id,
notificationType = NotificationType.CENTER_AUTHENTICATION,
)

val notification = notificationService.create(notificationInfo)

CenterManagerVerificationRejectEvent(
deviceToken = it.toString(),
notificationId = notification.id,
notificationInfo = notificationInfo
).also {
centerManagerVerificationRejectEventPublisher.publish(it)
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.swm.idle.application.user.center.vo

import com.swm.idle.domain.notification.enums.NotificationType
import com.swm.idle.domain.notification.event.NotificationInfo
import java.util.*

data class CenterManagerVerificationApproveNotificationInfo(
override val title: String,
override val body: String,
override val receiverId: UUID,
override val notificationType: NotificationType,
override val imageUrl: String?,
override val notificationDetails: Map<String, Any>?,
) : NotificationInfo {

companion object {

fun of(
title: String,
body: String,
receiverId: UUID,
notificationType: NotificationType,
): CenterManagerVerificationApproveNotificationInfo {
return CenterManagerVerificationApproveNotificationInfo(
title,
body,
receiverId,
notificationType,
null,
null
)
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.swm.idle.application.user.center.vo

import com.swm.idle.domain.notification.enums.NotificationType
import com.swm.idle.domain.notification.event.NotificationInfo
import java.util.*

data class CenterManagerVerificationRejectNotificationInfo(
override val title: String,
override val body: String,
override val receiverId: UUID,
override val notificationType: NotificationType,
override val imageUrl: String?,
override val notificationDetails: Map<String, Any>?,
) : NotificationInfo {

companion object {

fun of(
title: String,
body: String,
receiverId: UUID,
notificationType: NotificationType,
): CenterManagerVerificationApproveNotificationInfo {
return CenterManagerVerificationApproveNotificationInfo(
title,
body,
receiverId,
notificationType,
null,
null
)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.querydsl.core.types.Projections
import com.querydsl.jpa.impl.JPAQueryFactory
import com.swm.idle.domain.common.dto.NotificationQueryDto
import com.swm.idle.domain.common.enums.EntityStatus
import com.swm.idle.domain.notification.enums.NotificationType
import com.swm.idle.domain.notification.jpa.QNotification.notification
import org.springframework.stereotype.Repository
import java.util.*
Expand Down Expand Up @@ -37,6 +38,7 @@ class NotificationQueryRepository(
notification.receiverId.eq(userId)
.and(next?.let { notification.id.loe(it) })
.and(notification.entityStatus.eq(EntityStatus.ACTIVE))
.and(notification.notificationType.ne(NotificationType.CENTER_AUTHENTICATION))
)
.orderBy(notification.id.desc())
.limit(limit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ class CenterManager(
return status == CenterManagerAccountStatus.PENDING
}

fun updateStatusToApproved() {
fun approve() {
this.status = CenterManagerAccountStatus.APPROVED
}

fun updateStatusToRejected() {
fun reject() {
this.status = CenterManagerAccountStatus.REJECTED
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.swm.idle.domain.user.center.event

import com.swm.idle.domain.notification.event.NotificationInfo
import java.util.*

data class CenterManagerVerificationApproveEvent(
val notificationId: UUID,
val notificationInfo: NotificationInfo,
val deviceToken: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.swm.idle.domain.user.center.event

import com.swm.idle.domain.notification.event.NotificationInfo
import java.util.*

data class CenterManagerVerificationRejectEvent(
val notificationId: UUID,
val notificationInfo: NotificationInfo,
val deviceToken: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ sealed class CenterException(
class NotFoundException(message: String = "존재하지 않는 센터입니다.") :
CenterException(codeNumber = 4, message = message)

class IsNotPendingException(message: String = "관리자 인증 요청이 가능한 상태가 아닙니다.") :
CenterException(codeNumber = 5, message = message)

companion object {

const val CODE_PREFIX = "CENTER"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.swm.idle.infrastructure.fcm.users.listener

import com.swm.idle.domain.user.center.event.CenterManagerVerificationApproveEvent
import com.swm.idle.infrastructure.fcm.users.service.CenterManagerVerificationApproveEventService
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Component

@Component
class CenterManagerVerificationApproveEventListener(
private val centerManagerVerificationApproveEventService: CenterManagerVerificationApproveEventService,
) {

@EventListener
fun handleCenterManagerVerifyApproveEvent(centerManagerVerificationApproveEvent: CenterManagerVerificationApproveEvent) {
centerManagerVerificationApproveEventService.send(centerManagerVerificationApproveEvent)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.swm.idle.infrastructure.fcm.users.listener

import com.swm.idle.domain.user.center.event.CenterManagerVerificationRejectEvent
import com.swm.idle.infrastructure.fcm.users.service.CenterManagerVerificationRejectEventService
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Component

@Component
class CenterManagerVerificationRejectEventListener(
private val centerManagerVerificationRejectEventService: CenterManagerVerificationRejectEventService,
) {

@EventListener
fun handleCenterManagerVerifyRejectEvent(centerManagerVerificationRejectEvent: CenterManagerVerificationRejectEvent) {
centerManagerVerificationRejectEventService.send(centerManagerVerificationRejectEvent)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.swm.idle.infrastructure.fcm.users.service

import com.google.firebase.messaging.Message
import com.google.firebase.messaging.Notification
import com.swm.idle.domain.user.center.event.CenterManagerVerificationApproveEvent
import com.swm.idle.infrastructure.fcm.common.client.FcmClient
import io.github.oshai.kotlinlogging.KotlinLogging
import org.springframework.stereotype.Component

@Component
class CenterManagerVerificationApproveEventService(
private val fcmClient: FcmClient,
) {

private val logger = KotlinLogging.logger {}

fun send(centerManagerVerificationApproveEvent: CenterManagerVerificationApproveEvent) {
val message = createMessage(centerManagerVerificationApproveEvent)

try {
fcmClient.send(message)
} catch (e: Exception) {
logger.warn { "FCM 알림 전송에 실패했습니다 : ${message}, 실패한 Event : CenterManagerVerificationApproveEvent" }
}
}


private fun createJobPostingNotification(centerManagerVerificationApproveEvent: CenterManagerVerificationApproveEvent): Notification {
return Notification.builder()
.setTitle(centerManagerVerificationApproveEvent.notificationInfo.title)
.setBody(centerManagerVerificationApproveEvent.notificationInfo.body)
.build()
}

private fun createMessage(centerManagerVerificationApproveEvent: CenterManagerVerificationApproveEvent): Message {
val createJobPostingNotification =
createJobPostingNotification(centerManagerVerificationApproveEvent)

return Message.builder()
.setToken(centerManagerVerificationApproveEvent.deviceToken)
.setNotification(createJobPostingNotification)
.putData(
"notificationId",
centerManagerVerificationApproveEvent.notificationId.toString()
)
.putData(
"notificationType",
centerManagerVerificationApproveEvent.notificationInfo.notificationType.toString()
)
.build();
}


}
Loading

0 comments on commit ac6c04c

Please sign in to comment.