|
| 1 | +package hs.kr.entrydsm.status.infrastructure.kafka.consumer |
| 2 | + |
| 3 | +import com.fasterxml.jackson.databind.ObjectMapper |
| 4 | +import hs.kr.entrydsm.status.domain.status.application.port.`in`.CreateStatusUseCase |
| 5 | +import hs.kr.entrydsm.status.domain.status.application.port.`in`.DeleteStatusUseCase |
| 6 | +import hs.kr.entrydsm.status.domain.status.application.port.`in`.UpdateStatusUseCase |
| 7 | +import hs.kr.entrydsm.status.infrastructure.kafka.config.KafkaTopics |
| 8 | +import hs.kr.entrydsm.status.infrastructure.kafka.consumer.dto.CreateApplicationEvent |
| 9 | +import org.springframework.kafka.annotation.KafkaListener |
| 10 | +import org.springframework.stereotype.Component |
| 11 | + |
| 12 | +/** |
| 13 | + * 입학 원서 상태 관련 메시지를 수신하는 Consumer |
| 14 | + */ |
| 15 | +@Component |
| 16 | +class StatusConsumer( |
| 17 | + private val mapper: ObjectMapper, |
| 18 | + private val createStatusUseCase: CreateStatusUseCase, |
| 19 | + private val updateStatusUseCase: UpdateStatusUseCase, |
| 20 | + private val deleteStatusUseCase: DeleteStatusUseCase, |
| 21 | +) { |
| 22 | + /** |
| 23 | + * 원서가 생성되면, 원서 상태를 생성합니다. |
| 24 | + * |
| 25 | + * @param message 원서 생성 이벤트 |
| 26 | + */ |
| 27 | + @KafkaListener( |
| 28 | + topics = [KafkaTopics.CREATE_APPLICATION], |
| 29 | + groupId = "create-status", |
| 30 | + containerFactory = "kafkaListenerContainerFactory", |
| 31 | + ) |
| 32 | + fun createStatus(message: String) { |
| 33 | + val createApplicationEvent = mapper.readValue(message, CreateApplicationEvent::class.java) |
| 34 | + createStatusUseCase.execute(createApplicationEvent.receiptCode) |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * 최종 제출된 원서의 상태를 변경합니다. |
| 39 | + * |
| 40 | + * @param message 최종 제출된 원서의 접수 번호 |
| 41 | + */ |
| 42 | + @KafkaListener( |
| 43 | + topics = [KafkaTopics.SUBMIT_APPLICATION_FINAL], |
| 44 | + groupId = "update-status", |
| 45 | + containerFactory = "kafkaListenerContainerFactory", |
| 46 | + ) |
| 47 | + fun updateStatus(message: String) { |
| 48 | + val receiptCode = mapper.readValue(message, Long::class.java) |
| 49 | + updateStatusUseCase.execute(receiptCode) |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * 탈퇴한 유저의 원서 상태를 삭제합니다. |
| 54 | + * |
| 55 | + * @param message 탈퇴한 유저의 접수 번호 |
| 56 | + */ |
| 57 | + @KafkaListener( |
| 58 | + topics = [KafkaTopics.DELETE_USER], |
| 59 | + groupId = "delete-status", |
| 60 | + containerFactory = "kafkaListenerContainerFactory", |
| 61 | + ) |
| 62 | + fun deleteStatus(message: String) { |
| 63 | + val receiptCode = mapper.readValue(message, Long::class.java) |
| 64 | + deleteStatusUseCase.execute(receiptCode) |
| 65 | + } |
| 66 | +} |
0 commit comments