Skip to content

Commit

Permalink
Merge pull request #325 from apeun-gidaechi/feature/#323
Browse files Browse the repository at this point in the history
Fix :: 의존성 재정립
  • Loading branch information
yeseong0412 authored Oct 18, 2024
2 parents 41ee43c + 6752d2d commit 18db6a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class NotificationServiceImpl(
return workspaceService.findWorkspaceById(workspaceId)
}

private fun sendAlert(workspaceId: String, userId: Long, message: String) {
fcmService.sendNotificationAlert(workspaceId, userId, message)
private fun sendAlert(workspaceEntity: WorkspaceEntity, userId: Long, message: String) {
fcmService.sendNotificationAlert(workspaceEntity, userId, message)
}

@Transactional
Expand All @@ -51,7 +51,7 @@ class NotificationServiceImpl(
val notice = noticeMapper.transferNoticeEntity(createNoticeRequest, memberRepository.findById(userId).get())
noticeRepository.save(notice)

sendAlert(createNoticeRequest.workspaceId, userId, createNoticeRequest.title)
sendAlert(workspaceEntity, userId, createNoticeRequest.title)

}

Expand Down
14 changes: 6 additions & 8 deletions src/main/kotlin/com/seugi/api/global/infra/fcm/FCMService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.seugi.api.domain.chat.exception.ChatErrorCode
import com.seugi.api.domain.member.application.model.Member
import com.seugi.api.domain.member.application.port.out.LoadMemberPort
import com.seugi.api.domain.workspace.domain.entity.WorkspaceEntity
import com.seugi.api.domain.workspace.service.WorkspaceService
import com.seugi.api.global.exception.CustomException
import com.seugi.api.global.util.DateTimeUtil
import org.bson.types.ObjectId
Expand All @@ -19,7 +18,6 @@ import org.springframework.stereotype.Service
@Service
class FCMService(
private val memberPort: LoadMemberPort,
private val workspaceService: WorkspaceService,
private val chatRoomRepository: ChatRoomRepository,
@Value("\${fcm.icon.url}") private val icon: String,
) {
Expand All @@ -36,10 +34,10 @@ class FCMService(
return this.fcmToken.token
}

private fun getAlarmImage(workspaceId: String, type: FCMEnums, member: Member): String? {
private fun getAlarmImage(workspace: WorkspaceEntity?, type: FCMEnums, member: Member): String? {
return when (type) {
FCMEnums.CHAT -> member.getImg()
FCMEnums.NOTIFICATION -> workspaceService.findWorkspaceById(workspaceId).workspaceImageUrl ?: icon
FCMEnums.NOTIFICATION -> workspace?.workspaceImageUrl ?: icon
}
}

Expand Down Expand Up @@ -79,7 +77,7 @@ class FCMService(
val notification = buildNotification(
title = room.chatName.ifEmpty { "1대1 채팅" },
body = "${sendMember.name.value} : $message",
imageUrl = getAlarmImage(workspaceId = "", type = FCMEnums.CHAT, member = sendMember)
imageUrl = getAlarmImage(workspace = null, type = FCMEnums.CHAT, member = sendMember)
)

room.joinedUserInfo.forEach {
Expand All @@ -89,15 +87,15 @@ class FCMService(
}
}

fun sendNotificationAlert(workspaceId: String, userId: Long, message: String) {
val workspace = workspaceService.findWorkspaceById(workspaceId)
fun sendNotificationAlert(workspace: WorkspaceEntity, userId: Long, message: String) {

val sendUser = getMember(userId)
val users = workspace.student + workspace.middleAdmin + workspace.workspaceAdmin - userId

val notification = buildNotification(
title = "[공지] ${workspace.workspaceName}",
body = "${sendUser.name.value} : $message",
imageUrl = getAlarmImage(workspaceId, FCMEnums.NOTIFICATION, sendUser)
imageUrl = getAlarmImage(workspace, FCMEnums.NOTIFICATION, sendUser)
)

users.forEach {
Expand Down

0 comments on commit 18db6a8

Please sign in to comment.