Skip to content

Commit

Permalink
[FEAT] 알림 API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kim0hoon committed Sep 15, 2023
1 parent 9105a9f commit db7a73a
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 0 deletions.
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)
}
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?
)
}
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>
)
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>
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>
}
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
)
}
}

0 comments on commit db7a73a

Please sign in to comment.