Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
[Fix] Event 래핑 & 에러 포워딩 (#50)
Browse files Browse the repository at this point in the history
* refactor: Server error를 그대로 포워딩

* refactor: Events 객체 컬랙션 래핑
  • Loading branch information
goldentrash authored Feb 1, 2024
1 parent ea98159 commit f208b69
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CommonExceptionHandler {
fun unHandleException(ex: Exception, request: HttpServletRequest): ResponseEntity<ErrorResponse> {
log.error("서버 에러 발생! ${request.method} ${request.requestURI} ${ex.message}")

return ResponseEntity.internalServerError().body(ErrorResponse("서버 에러가 발생했습니다. 관리자에게 문의해주세요."))
return ResponseEntity.internalServerError().body(ErrorResponse(ex.message))
}

@ExceptionHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class WaterCycleEventListener(

@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
@Async
fun sendFcmNotification(events: List<WaterCycleEvent>) {
val messages: List<Message> = createMessages(events, FCMChannel.WATER_ALERT.name)
fun sendFcmNotification(events: WaterCycleEvents) {
val messages: List<Message> = createMessages(events.plantsNeedWateredToday, FCMChannel.WATER_ALERT.name)

try {
firebaseMessaging.sendEach(messages)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package gdsc.plantory.event.notification

data class WaterCycleEvents(
val plantsNeedWateredToday: List<WaterCycleEvent>
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gdsc.plantory.plant.service

import gdsc.plantory.event.Events
import gdsc.plantory.event.notification.WaterCycleEvent
import gdsc.plantory.event.notification.WaterCycleEvents
import gdsc.plantory.plant.domain.CompanionPlantRepository
import gdsc.plantory.plant.presentation.dto.CompanionPlantWaterCycleDto
import org.springframework.scheduling.annotation.Scheduled
Expand All @@ -18,7 +19,7 @@ class ReminderService(
@Scheduled(cron = "0 0 8 * * *")
fun sendWaterNotification() {
val companionPlants = companionPlantRepository.findAllByNextWaterDate(LocalDate.now())
val events: List<WaterCycleEvent> = buildWaterCycleEvents(companionPlants)
val events = WaterCycleEvents(buildWaterCycleEvents(companionPlants))
Events.raise(events)
}

Expand Down

0 comments on commit f208b69

Please sign in to comment.