-
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.
Browse files
Browse the repository at this point in the history
#75 : 알림 탭 화면 구현
- Loading branch information
Showing
36 changed files
with
546 additions
and
31 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
14 changes: 14 additions & 0 deletions
14
app/src/main/kotlin/com/bff/wespot/PushNotificationService.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,14 @@ | ||
package com.bff.wespot | ||
|
||
import com.google.firebase.messaging.FirebaseMessagingService | ||
import com.google.firebase.messaging.RemoteMessage | ||
|
||
class PushNotificationService : FirebaseMessagingService() { | ||
override fun onNewToken(token: String) { | ||
super.onNewToken(token) | ||
} | ||
|
||
override fun onMessageReceived(message: RemoteMessage) { | ||
super.onMessageReceived(message) | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
core/model/src/main/kotlin/com/bff/wespot/model/notification/Notification.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,15 @@ | ||
package com.bff.wespot.model.notification | ||
|
||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
|
||
data class Notification( | ||
val id: Int, | ||
val type: NotificationType, | ||
val date: LocalDate, | ||
val targetId: Int, | ||
val content: String, | ||
val isNew: Boolean, | ||
val isEnable: Boolean, | ||
val createdAt: LocalDateTime, | ||
) |
18 changes: 18 additions & 0 deletions
18
core/model/src/main/kotlin/com/bff/wespot/model/notification/NotificationType.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,18 @@ | ||
package com.bff.wespot.model.notification | ||
|
||
enum class NotificationType { | ||
IDLE, | ||
MESSAGE, | ||
MESSAGE_SENT, | ||
MESSAGE_RECEIVED, | ||
VOTE, | ||
VOTE_RESULT, | ||
VOTE_RECEIVED, | ||
; | ||
|
||
fun toDescription(): String = when (this) { | ||
MESSAGE, MESSAGE_SENT, MESSAGE_RECEIVED -> "쪽지 알림" | ||
VOTE, VOTE_RESULT, VOTE_RECEIVED -> "투표 알림" | ||
IDLE -> "" | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
data-remote/src/main/kotlin/com/bff/wespot/data/remote/extensions/DateTimeExtensions.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,9 +1,18 @@ | ||
package com.bff.wespot.data.remote.extensions | ||
|
||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
fun String.toISOLocalDateTime(): LocalDateTime? = | ||
runCatching { | ||
LocalDateTime.parse(this, DateTimeFormatter.ISO_DATE_TIME) | ||
}.recoverCatching { | ||
val correctedString = this.replace(" ", "T") | ||
LocalDateTime.parse(correctedString, DateTimeFormatter.ISO_DATE_TIME) | ||
}.getOrNull() | ||
|
||
fun String.toLocalDateFromDashPattern(): LocalDate { | ||
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") | ||
return LocalDate.parse(this, formatter) | ||
} |
48 changes: 48 additions & 0 deletions
48
data-remote/src/main/kotlin/com/bff/wespot/data/remote/model/notification/NotificationDto.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,48 @@ | ||
package com.bff.wespot.data.remote.model.notification | ||
|
||
import com.bff.wespot.data.remote.extensions.toISOLocalDateTime | ||
import com.bff.wespot.data.remote.extensions.toLocalDateFromDashPattern | ||
import com.bff.wespot.model.notification.Notification | ||
import com.bff.wespot.model.notification.NotificationType | ||
import kotlinx.serialization.Serializable | ||
import java.time.LocalDateTime | ||
|
||
@Serializable | ||
data class NotificationListDto( | ||
val notifications: List<NotificationDto> | ||
) | ||
|
||
@Serializable | ||
data class NotificationDto ( | ||
val id: Int, | ||
val type: String, | ||
val date: String, | ||
val targetId: Int, | ||
val content: String, | ||
val isNew: Boolean, | ||
val isEnable: Boolean, | ||
val createdAt: String, | ||
) { | ||
fun toNotification(): Notification = Notification( | ||
id = id, | ||
type = type.convertToNotificationType(), | ||
date = date.toLocalDateFromDashPattern(), | ||
targetId = targetId, | ||
content = content, | ||
isNew = isNew, | ||
isEnable = isEnable, | ||
createdAt = createdAt.toISOLocalDateTime() ?: LocalDateTime.MIN, | ||
) | ||
|
||
private fun String.convertToNotificationType(): NotificationType { | ||
return when (this) { | ||
NotificationType.MESSAGE.name -> NotificationType.MESSAGE | ||
NotificationType.MESSAGE_SENT.name -> NotificationType.MESSAGE_SENT | ||
NotificationType.MESSAGE_RECEIVED.name -> NotificationType.MESSAGE_RECEIVED | ||
NotificationType.VOTE.name -> NotificationType.VOTE | ||
NotificationType.VOTE_RESULT.name -> NotificationType.VOTE_RESULT | ||
NotificationType.VOTE_RECEIVED.name -> NotificationType.VOTE_RECEIVED | ||
else -> NotificationType.IDLE | ||
} | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
.../src/main/kotlin/com/bff/wespot/data/remote/source/notification/NotificationDataSource.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,9 @@ | ||
package com.bff.wespot.data.remote.source.notification | ||
|
||
import com.bff.wespot.data.remote.model.notification.NotificationListDto | ||
|
||
interface NotificationDataSource { | ||
suspend fun getNotification(): Result<NotificationListDto> | ||
|
||
suspend fun updateNotificationReadStatus(id: Int): Result<Unit> | ||
} |
28 changes: 28 additions & 0 deletions
28
.../main/kotlin/com/bff/wespot/data/remote/source/notification/NotificationDataSourceImpl.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,28 @@ | ||
package com.bff.wespot.data.remote.source.notification | ||
|
||
import com.bff.wespot.data.remote.model.notification.NotificationListDto | ||
import com.bff.wespot.network.extensions.safeRequest | ||
import io.ktor.client.HttpClient | ||
import io.ktor.http.HttpMethod | ||
import io.ktor.http.path | ||
import javax.inject.Inject | ||
|
||
class NotificationDataSourceImpl @Inject constructor( | ||
private val httpClient: HttpClient, | ||
): NotificationDataSource { | ||
override suspend fun getNotification(): Result<NotificationListDto> = | ||
httpClient.safeRequest { | ||
url { | ||
method = HttpMethod.Get | ||
path("notifications") | ||
} | ||
} | ||
|
||
override suspend fun updateNotificationReadStatus(id: Int): Result<Unit> = | ||
httpClient.safeRequest { | ||
url { | ||
method = HttpMethod.Put | ||
path("notifications/$id") | ||
} | ||
} | ||
} |
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
Oops, something went wrong.