-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IDLE-400] 채용 공고 지원자 발생 시, 센터 관리자에게 알림을 발송한다.
- Loading branch information
Showing
14 changed files
with
218 additions
and
37 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...cation/src/main/kotlin/com/swm/idle/application/applys/domain/CarerApplyEventPublisher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.swm.idle.application.applys.domain | ||
|
||
import com.swm.idle.domain.applys.event.ApplyEvent | ||
import org.springframework.context.ApplicationEventPublisher | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class CarerApplyEventPublisher( | ||
private val eventPublisher: ApplicationEventPublisher, | ||
) { | ||
|
||
fun publish(applyEvent: ApplyEvent) { | ||
eventPublisher.publishEvent(applyEvent) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 34 additions & 8 deletions
42
...ication/src/main/kotlin/com/swm/idle/application/applys/facade/CarerApplyFacadeService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,65 @@ | ||
package com.swm.idle.application.applys.facade | ||
|
||
import com.swm.idle.application.applys.domain.CarerApplyEventPublisher | ||
import com.swm.idle.application.applys.domain.CarerApplyService | ||
import com.swm.idle.application.common.security.getUserAuthentication | ||
import com.swm.idle.application.jobposting.domain.JobPostingService | ||
import com.swm.idle.application.notification.domain.DeviceTokenService | ||
import com.swm.idle.application.user.carer.domain.CarerService | ||
import com.swm.idle.domain.applys.event.ApplyEvent | ||
import com.swm.idle.domain.applys.exception.ApplyException | ||
import com.swm.idle.domain.jobposting.enums.ApplyMethodType | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Propagation | ||
import org.springframework.transaction.annotation.Transactional | ||
import java.util.* | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
class CarerApplyFacadeService( | ||
private val carerApplyService: CarerApplyService, | ||
private val carerApplyEventPublisher: CarerApplyEventPublisher, | ||
private val deviceTokenService: DeviceTokenService, | ||
private val jobPostingService: JobPostingService, | ||
private val carerService: CarerService, | ||
) { | ||
|
||
@Transactional | ||
private val logger = KotlinLogging.logger { } | ||
|
||
@Transactional(propagation = Propagation.REQUIRES_NEW) | ||
fun createApply( | ||
jobPostingId: UUID, | ||
applyMethodType: ApplyMethodType, | ||
) { | ||
val carerId = getUserAuthentication().userId | ||
val carer = getUserAuthentication().userId.let { | ||
carerService.getById(it) | ||
} | ||
val deviceToken = deviceTokenService.findByUserId(carer.id) | ||
val jobPosting = jobPostingService.getById(jobPostingId) | ||
|
||
if (carerApplyService.existsByJobPostingIdAndCarerId( | ||
jobPostingId = jobPostingId, | ||
carerId = carerId, | ||
carerId = carer.id, | ||
) | ||
) { | ||
throw ApplyException.AlreadyApplied() | ||
} | ||
|
||
carerApplyService.create( | ||
jobPostingId = jobPostingId, | ||
carerId = carerId, | ||
applyMethodType = applyMethodType, | ||
) | ||
carerApplyService.create(jobPostingId, carer.id, applyMethodType) | ||
|
||
deviceToken?.let { | ||
carerApplyEventPublisher.publish( | ||
ApplyEvent.createApplyEvent( | ||
deviceToken = deviceToken, | ||
jobPosting = jobPosting, | ||
carer = carer, | ||
) | ||
) | ||
} ?: run { | ||
logger.warn { "${carer.id} 요양 보호사의 device Token이 존재하지 않아 알림이 발송되지 않았습니다." } | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
idle-domain/src/main/kotlin/com/swm/idle/domain/applys/event/ApplyEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.swm.idle.domain.applys.event | ||
|
||
import com.swm.idle.domain.jobposting.entity.jpa.JobPosting | ||
import com.swm.idle.domain.notification.jpa.DeviceToken | ||
import com.swm.idle.domain.user.carer.entity.jpa.Carer | ||
|
||
data class ApplyEvent( | ||
val deviceToken: DeviceToken, | ||
val jobPosting: JobPosting, | ||
val carer: Carer, | ||
) { | ||
|
||
companion object { | ||
|
||
fun createApplyEvent( | ||
deviceToken: DeviceToken, | ||
jobPosting: JobPosting, | ||
carer: Carer, | ||
): ApplyEvent { | ||
return ApplyEvent(deviceToken, jobPosting, carer) | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletions
11
idle-domain/src/main/kotlin/com/swm/idle/domain/user/common/enum/GenderType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package com.swm.idle.domain.user.common.enum | ||
|
||
enum class GenderType { | ||
MAN, | ||
WOMAN; | ||
} | ||
enum class GenderType( | ||
val value: String, | ||
) { | ||
|
||
MAN("남성"), | ||
WOMAN("여성"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...rc/main/kotlin/com/swm/idle/infrastructure/fcm/applys/listener/CarerApplyEventListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.swm.idle.infrastructure.fcm.applys.listener | ||
|
||
import com.swm.idle.domain.applys.event.ApplyEvent | ||
import com.swm.idle.infrastructure.fcm.applys.service.CarerApplyEventService | ||
import org.springframework.context.event.EventListener | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
|
||
class CarerApplyEventListener( | ||
private val carerApplyEventService: CarerApplyEventService, | ||
) { | ||
|
||
@EventListener | ||
fun handleCarerApplyEvent(applyEvent: ApplyEvent) { | ||
carerApplyEventService.send(applyEvent) | ||
} | ||
|
||
} | ||
|
51 changes: 51 additions & 0 deletions
51
.../src/main/kotlin/com/swm/idle/infrastructure/fcm/applys/service/CarerApplyEventService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.swm.idle.infrastructure.fcm.applys.service | ||
|
||
import com.google.firebase.messaging.Message | ||
import com.google.firebase.messaging.Notification | ||
import com.swm.idle.domain.applys.event.ApplyEvent | ||
import com.swm.idle.domain.user.common.vo.BirthYear | ||
import com.swm.idle.infrastructure.fcm.common.client.FcmClient | ||
import com.swm.idle.infrastructure.fcm.common.enums.DestinationType | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class CarerApplyEventService( | ||
private val fcmClient: FcmClient, | ||
) { | ||
|
||
fun send(applyEvent: ApplyEvent) { | ||
createMessage(applyEvent).also { | ||
fcmClient.send(it) | ||
} | ||
} | ||
|
||
private fun createApplyNotification(applyEvent: ApplyEvent): Notification { | ||
return Notification.builder() | ||
.setTitle("${applyEvent.carer.name} 님이 공고에 지원하였습니다.") | ||
.setBody(createBodyMessage(applyEvent)) | ||
.build() | ||
} | ||
|
||
private fun createBodyMessage(applyEvent: ApplyEvent): String? { | ||
val filteredLotNumberAddress = applyEvent.jobPosting.lotNumberAddress.split(" ") | ||
.take(3) | ||
.joinToString(" ") | ||
|
||
return "$filteredLotNumberAddress " + | ||
"${applyEvent.jobPosting.careLevel}등급 " + | ||
"${BirthYear.calculateAge(applyEvent.jobPosting.birthYear)}세 " + | ||
applyEvent.jobPosting.gender.value | ||
} | ||
|
||
private fun createMessage(applyEvent: ApplyEvent): Message { | ||
val applyNotification = createApplyNotification(applyEvent) | ||
|
||
return Message.builder() | ||
.setToken(applyEvent.deviceToken.deviceToken) | ||
.setNotification(applyNotification) | ||
.putData("destination", DestinationType.APPLICANTS.toString()) | ||
.putData("jobPostingId", applyEvent.jobPosting.id.toString()) | ||
.build(); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...astructure/fcm/src/main/kotlin/com/swm/idle/infrastructure/fcm/common/client/FcmClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.swm.idle.infrastructure.fcm.common.client | ||
|
||
import com.google.firebase.messaging.FirebaseMessaging | ||
import com.google.firebase.messaging.Message | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class FcmClient { | ||
|
||
fun send(message: Message) { | ||
firebase.sendAsync(message) | ||
} | ||
|
||
companion object { | ||
|
||
val firebase: FirebaseMessaging = FirebaseMessaging.getInstance() | ||
} | ||
|
||
} |
26 changes: 3 additions & 23 deletions
26
...astructure/fcm/src/main/kotlin/com/swm/idle/infrastructure/fcm/common/config/FcmConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,9 @@ | ||
package com.swm.idle.infrastructure.fcm.common.config | ||
|
||
import com.google.auth.oauth2.GoogleCredentials | ||
import com.google.firebase.FirebaseApp | ||
import com.google.firebase.FirebaseOptions | ||
import jakarta.annotation.PostConstruct | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.context.annotation.ComponentScan | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.core.io.ClassPathResource | ||
|
||
@Configuration | ||
class FcmConfig { | ||
|
||
@Value("\${firebase.json.path}") | ||
lateinit var firebaseConfigJsonPath: String | ||
|
||
@PostConstruct | ||
fun initializeFirebaseApp() { | ||
val googleCredentials = | ||
GoogleCredentials.fromStream(ClassPathResource(firebaseConfigJsonPath).inputStream) | ||
|
||
val fireBaseOptions = FirebaseOptions.builder() | ||
.setCredentials(googleCredentials) | ||
.build() | ||
|
||
FirebaseApp.initializeApp(fireBaseOptions) | ||
} | ||
|
||
@ComponentScan(basePackages = ["com.swm.idle.infrastructure.fcm"]) | ||
interface FcmConfig { | ||
} |
29 changes: 29 additions & 0 deletions
29
...cture/fcm/src/main/kotlin/com/swm/idle/infrastructure/fcm/common/config/FirebaseConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.swm.idle.infrastructure.fcm.common.config | ||
|
||
import com.google.auth.oauth2.GoogleCredentials | ||
import com.google.firebase.FirebaseApp | ||
import com.google.firebase.FirebaseOptions | ||
import jakarta.annotation.PostConstruct | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.core.io.ClassPathResource | ||
|
||
@Configuration | ||
class FirebaseConfig { | ||
|
||
@Value("\${firebase.json.path}") | ||
lateinit var firebaseConfigJsonPath: String | ||
|
||
@PostConstruct | ||
fun initializeFirebaseApp() { | ||
val googleCredentials = | ||
GoogleCredentials.fromStream(ClassPathResource(firebaseConfigJsonPath).inputStream) | ||
|
||
val fireBaseOptions = FirebaseOptions.builder() | ||
.setCredentials(googleCredentials) | ||
.build() | ||
|
||
FirebaseApp.initializeApp(fireBaseOptions) | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...cture/fcm/src/main/kotlin/com/swm/idle/infrastructure/fcm/common/enums/DestinationType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.swm.idle.infrastructure.fcm.common.enums | ||
|
||
enum class DestinationType { | ||
APPLICANTS | ||
} |