-
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.
- Loading branch information
Showing
6 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
app/src/main/java/com/polzzak_android/data/di/NotificationModule.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.polzzak_android.data.di | ||
|
||
import com.polzzak_android.data.remote.service.NotificationService | ||
import com.polzzak_android.data.repository.NotificationRepository | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import retrofit2.Retrofit | ||
import javax.inject.Named | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object NotificationModule { | ||
@Singleton | ||
@Provides | ||
fun provideNotificationService(@Named("Polzzak") retrofit: Retrofit): NotificationService = | ||
retrofit.create(NotificationService::class.java) | ||
|
||
@Singleton | ||
@Provides | ||
fun provideNotificationRepository(notificationService: NotificationService): NotificationRepository = | ||
NotificationRepository(notificationService = notificationService) | ||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/polzzak_android/data/remote/model/response/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,19 @@ | ||
package com.polzzak_android.data.remote.model.response | ||
|
||
data class NotificationDto( | ||
val id: Int?, | ||
val type: String?, | ||
val status: String?, | ||
val title: String?, | ||
val message: String?, | ||
val sender: Sender?, | ||
val link: String?, | ||
val requestFamilyId: Int?, | ||
val createdDate: String? | ||
) { | ||
data class Sender( | ||
val id: Int?, | ||
val nickName: String?, | ||
val profileUrl: String? | ||
) | ||
} |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/polzzak_android/data/remote/model/response/NotificationsDto.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,6 @@ | ||
package com.polzzak_android.data.remote.model.response | ||
|
||
data class NotificationsDto( | ||
val startId: Int?, | ||
val notificationDtoList: List<NotificationDto> | ||
) |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/polzzak_android/data/remote/model/response/NotificationsResponse.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 com.polzzak_android.data.remote.model.response | ||
|
||
data class NotificationsResponse( | ||
override val code: Int?, | ||
override val messages: List<String>?, | ||
override val data: NotificationsDto? | ||
) : BaseResponse<NotificationsDto> |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/polzzak_android/data/remote/service/NotificationService.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,23 @@ | ||
package com.polzzak_android.data.remote.service | ||
|
||
import com.polzzak_android.data.remote.model.response.EmptyDataResponse | ||
import com.polzzak_android.data.remote.model.response.NotificationsResponse | ||
import retrofit2.Response | ||
import retrofit2.http.DELETE | ||
import retrofit2.http.GET | ||
import retrofit2.http.Header | ||
import retrofit2.http.Query | ||
|
||
interface NotificationService { | ||
@GET("/api/v1/notifications") | ||
suspend fun requestNotifications( | ||
@Header("Authorization") authorization: String, | ||
@Query("startId") startId: Int? | ||
): Response<NotificationsResponse> | ||
|
||
@DELETE("/api/v1/notifications") | ||
suspend fun deleteNotifications( | ||
@Header("Authorization") authorization: String, | ||
@Query("notificationIds") notificationIds: List<Int> | ||
): Response<EmptyDataResponse> | ||
} |
30 changes: 30 additions & 0 deletions
30
app/src/main/java/com/polzzak_android/data/repository/NotificationRepository.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,30 @@ | ||
package com.polzzak_android.data.repository | ||
|
||
import com.polzzak_android.data.remote.service.NotificationService | ||
import com.polzzak_android.data.remote.util.createHeaderAuthorization | ||
import com.polzzak_android.data.remote.util.requestCatching | ||
import javax.inject.Inject | ||
|
||
class NotificationRepository @Inject constructor(private val notificationService: NotificationService) { | ||
suspend fun requestNotifications( | ||
accessToken: String, | ||
startId: Int? | ||
) = requestCatching { | ||
val authorization = createHeaderAuthorization(accessToken = accessToken) | ||
notificationService.requestNotifications( | ||
authorization = authorization, | ||
startId = startId | ||
) | ||
} | ||
|
||
suspend fun deleteNotifications( | ||
accessToken: String, | ||
notificationIds: List<Int> | ||
) = requestCatching { | ||
val authorization = createHeaderAuthorization(accessToken = accessToken) | ||
notificationService.deleteNotifications( | ||
authorization = authorization, | ||
notificationIds = notificationIds | ||
) | ||
} | ||
} |