-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from dnd-side-project/refactor/expo
[BLOOM-138] refactor: 알림 기능 FCM -> Expo API 변경
- Loading branch information
Showing
16 changed files
with
110 additions
and
80 deletions.
There are no files selected for viewing
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
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
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
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
29 changes: 14 additions & 15 deletions
29
batch/src/main/kotlin/dnd11th/blooming/batch/notification/PlantNotificationWriter.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
13 changes: 13 additions & 0 deletions
13
client/src/main/kotlin/dnd11th/blooming/client/expo/ExpoPushClient.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,13 @@ | ||
package dnd11th.blooming.client.expo | ||
|
||
import org.springframework.cloud.openfeign.FeignClient | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
|
||
@FeignClient(name = "expoPushClient", url = "https://exp.host/--/api/v2/push/send") | ||
interface ExpoPushClient { | ||
@PostMapping(consumes = ["application/json"]) | ||
fun sendPushNotification( | ||
@RequestBody request: List<PushNotification>, | ||
): PushNotificationResponse | ||
} |
37 changes: 37 additions & 0 deletions
37
client/src/main/kotlin/dnd11th/blooming/client/expo/ExpoPushService.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,37 @@ | ||
package dnd11th.blooming.client.expo | ||
|
||
import dnd11th.blooming.common.exception.ErrorType | ||
import dnd11th.blooming.common.exception.ExternalServerException | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.withContext | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class ExpoPushService( | ||
private val expoPushClient: ExpoPushClient, | ||
) : PushService { | ||
override suspend fun send(push: List<PushNotification>) { | ||
val response: PushNotificationResponse = | ||
withContext(Dispatchers.IO) { | ||
expoPushClient.sendPushNotification(push) | ||
} | ||
|
||
val errorMessages: List<String> = | ||
response.data | ||
.filter { it.status == "error" } | ||
.mapNotNull { it.message } | ||
|
||
if (errorMessages.isNotEmpty()) { | ||
throw ExternalServerException(ErrorType.PUSH_API_CALL_EXCEPTION, errorMessages.joinToString(", ")) | ||
} | ||
} | ||
|
||
override suspend fun mock(push: List<PushNotification>) { | ||
try { | ||
delay(2000L) | ||
} catch (e: Exception) { | ||
println("지연 처리 중 예외 발생: ${e.message}") | ||
} | ||
} | ||
} |
9 changes: 3 additions & 6 deletions
9
...h/blooming/client/fcm/PushNotification.kt → .../blooming/client/expo/PushNotification.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
16 changes: 16 additions & 0 deletions
16
client/src/main/kotlin/dnd11th/blooming/client/expo/PushNotificationResponse.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 dnd11th.blooming.client.expo | ||
|
||
data class PushNotificationResponse( | ||
val data: List<PushResponse>, | ||
) | ||
|
||
data class PushResponse( | ||
val status: String, | ||
val id: String?, | ||
val message: String?, | ||
val details: ErrorDetails?, | ||
) | ||
|
||
data class ErrorDetails( | ||
val error: String?, | ||
) |
7 changes: 7 additions & 0 deletions
7
client/src/main/kotlin/dnd11th/blooming/client/expo/PushService.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,7 @@ | ||
package dnd11th.blooming.client.expo | ||
|
||
interface PushService { | ||
suspend fun send(push: List<PushNotification>) | ||
|
||
suspend fun mock(push: List<PushNotification>) | ||
} |
7 changes: 0 additions & 7 deletions
7
client/src/main/kotlin/dnd11th/blooming/client/fcm/FcmService.kt
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
client/src/main/kotlin/dnd11th/blooming/client/fcm/FcmServiceImpl.kt
This file was deleted.
Oops, something went wrong.
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
8 changes: 7 additions & 1 deletion
8
common/src/main/kotlin/dnd11th/blooming/common/exception/ExternalServerException.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,3 +1,9 @@ | ||
package dnd11th.blooming.common.exception | ||
|
||
class ExternalServerException(errorType: ErrorType) : MyException(errorType) | ||
class ExternalServerException( | ||
errorType: ErrorType, | ||
private val customMessage: String? = null, | ||
) : MyException(errorType) { | ||
override val message: String | ||
get() = customMessage ?: errorType.message | ||
} |
3 changes: 3 additions & 0 deletions
3
common/src/main/kotlin/dnd11th/blooming/common/exception/InternalServerException.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,3 @@ | ||
package dnd11th.blooming.common.exception | ||
|
||
class InternalServerException(errorType: ErrorType) : MyException(errorType) |
4 changes: 3 additions & 1 deletion
4
common/src/main/kotlin/dnd11th/blooming/common/exception/MyException.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,3 +1,5 @@ | ||
package dnd11th.blooming.common.exception | ||
|
||
abstract class MyException(val errorType: ErrorType) : RuntimeException(errorType.message) | ||
abstract class MyException( | ||
val errorType: ErrorType, | ||
) : RuntimeException(errorType.message) |