Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CallAdapter로 리팩토링한다. #534

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.app.edonymyeon.data.common

import com.app.edonymyeon.presentation.common.exception.HttpException

sealed interface FetchState {
object BadInternet : FetchState
object ParseError : FetchState
object WrongConnection : FetchState

class NoAuthorization(
val customThrowable: CustomThrowable,
val customThrowable: HttpException,
) : FetchState

class Fail(
val customThrowable: CustomThrowable,
val customThrowable: HttpException,
) : FetchState
}
14 changes: 0 additions & 14 deletions android/app/src/main/java/com/app/edonymyeon/data/common/Result.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.app.edonymyeon.data.dto.request.LogoutRequest
import com.app.edonymyeon.data.dto.request.TokenRequest
import com.app.edonymyeon.data.dto.request.UserRegistrationRequest
import com.app.edonymyeon.data.dto.response.AuthDuplicateResponse
import retrofit2.Response
import com.app.edonymyeon.data.service.client.calladapter.ApiResponse

interface AuthDataSource {

Expand All @@ -17,12 +17,16 @@ interface AuthDataSource {
interface Remote {
suspend fun login(
loginDataModel: LoginDataModel,
): Response<Unit>
): ApiResponse<Unit>

suspend fun loginByKakao(accessToken: TokenRequest): Response<Unit>
suspend fun loginByKakao(accessToken: TokenRequest): ApiResponse<Unit>

suspend fun signUp(userRegistrationRequest: UserRegistrationRequest): Response<Unit>
suspend fun checkDuplicate(target: String, value: String): Response<AuthDuplicateResponse>
suspend fun logout(logoutRequest: LogoutRequest): Response<Unit>
suspend fun signUp(userRegistrationRequest: UserRegistrationRequest): ApiResponse<Unit>
suspend fun checkDuplicate(
target: String,
value: String,
): ApiResponse<AuthDuplicateResponse>

suspend fun logout(logoutRequest: LogoutRequest): ApiResponse<Unit>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ import com.app.edonymyeon.data.dto.request.TokenRequest
import com.app.edonymyeon.data.dto.request.UserRegistrationRequest
import com.app.edonymyeon.data.dto.response.AuthDuplicateResponse
import com.app.edonymyeon.data.service.AuthService
import retrofit2.Response
import com.app.edonymyeon.data.service.client.calladapter.ApiResponse
import javax.inject.Inject

class AuthRemoteDataSource @Inject constructor(
private val authService: AuthService,
) : AuthDataSource.Remote {

override suspend fun signUp(userRegistrationRequest: UserRegistrationRequest): Response<Unit> {
override suspend fun signUp(userRegistrationRequest: UserRegistrationRequest): ApiResponse<Unit> {
return authService.signUp(userRegistrationRequest)
}

override suspend fun checkDuplicate(
target: String,
value: String,
): Response<AuthDuplicateResponse> {
): ApiResponse<AuthDuplicateResponse> {
return authService.checkDuplicate(target, value)
}

override suspend fun login(loginDataModel: LoginDataModel): Response<Unit> {
override suspend fun login(loginDataModel: LoginDataModel): ApiResponse<Unit> {
return authService.login(loginDataModel)
}

override suspend fun logout(logoutRequest: LogoutRequest): Response<Unit> {
override suspend fun logout(logoutRequest: LogoutRequest): ApiResponse<Unit> {
return authService.logout(logoutRequest)
}

override suspend fun loginByKakao(accessToken: TokenRequest): Response<Unit> {
override suspend fun loginByKakao(accessToken: TokenRequest): ApiResponse<Unit> {
return authService.loginByKakao(accessToken)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.app.edonymyeon.data.datasource.consumptions

import com.app.edonymyeon.data.dto.response.ConsumptionsResponse
import retrofit2.Response
import com.app.edonymyeon.data.service.client.calladapter.ApiResponse

interface ConsumptionsDataSource {
suspend fun getConsumptions(period: Int): Response<ConsumptionsResponse>
suspend fun getConsumptions(period: Int): ApiResponse<ConsumptionsResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package com.app.edonymyeon.data.datasource.consumptions

import com.app.edonymyeon.data.dto.response.ConsumptionsResponse
import com.app.edonymyeon.data.service.ConsumptionsService
import retrofit2.Response
import com.app.edonymyeon.data.service.client.calladapter.ApiResponse
import javax.inject.Inject

class ConsumptionsRemoteDataSource @Inject constructor(
private val consumptionsService: ConsumptionsService,
) : ConsumptionsDataSource {

override suspend fun getConsumptions(period: Int): Response<ConsumptionsResponse> {
override suspend fun getConsumptions(period: Int): ApiResponse<ConsumptionsResponse> {
return consumptionsService.getConsumptions(period)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.app.edonymyeon.data.datasource.notification

import com.app.edonymyeon.data.dto.response.NotificationsResponse
import retrofit2.Response
import com.app.edonymyeon.data.service.client.calladapter.ApiResponse

interface NotificationDataSource {
suspend fun getNotifications(size: Int, page: Int): Response<NotificationsResponse>
suspend fun getNotifications(size: Int, page: Int): ApiResponse<NotificationsResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package com.app.edonymyeon.data.datasource.notification

import com.app.edonymyeon.data.dto.response.NotificationsResponse
import com.app.edonymyeon.data.service.NotificationService
import retrofit2.Response
import com.app.edonymyeon.data.service.client.calladapter.ApiResponse
import javax.inject.Inject

class NotificationRemoteDataSource @Inject constructor(
private val notificationService: NotificationService,
) : NotificationDataSource {

override suspend fun getNotifications(size: Int, page: Int): Response<NotificationsResponse> {
override suspend fun getNotifications(
size: Int,
page: Int,
): ApiResponse<NotificationsResponse> {
return notificationService.getNotifications(size, page)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@ import com.app.edonymyeon.data.dto.response.CommentsResponse
import com.app.edonymyeon.data.dto.response.PostDetailResponse
import com.app.edonymyeon.data.dto.response.PostEditorResponse
import com.app.edonymyeon.data.dto.response.Posts
import retrofit2.Response
import com.app.edonymyeon.data.service.client.calladapter.ApiResponse
import java.io.File

interface PostDataSource {
suspend fun getPostDetail(
postId: Long,
notificationId: Long,
): Response<PostDetailResponse>
): ApiResponse<PostDetailResponse>

suspend fun deletePost(postId: Long): Response<Unit>
suspend fun getPosts(size: Int, page: Int): Response<Posts>
suspend fun deletePost(postId: Long): ApiResponse<Unit>
suspend fun getPosts(size: Int, page: Int): ApiResponse<Posts>

suspend fun savePost(
postEditorRequest: PostEditorRequest,
imageFiles: List<File>,
): Response<PostEditorResponse>
): ApiResponse<PostEditorResponse>

suspend fun updatePost(
id: Long,
postEditorRequest: PostEditorRequest,
imageUrls: List<String>,
imageFiles: List<File>,
): Response<PostEditorResponse>
): ApiResponse<PostEditorResponse>

suspend fun getHotPosts(): Response<Posts>
suspend fun getHotPosts(): ApiResponse<Posts>

suspend fun getComments(postId: Long): Response<CommentsResponse>
suspend fun getComments(postId: Long): ApiResponse<CommentsResponse>

suspend fun postComment(
id: Long,
image: File?,
comment: String,
): Response<Unit>
): ApiResponse<Unit>

suspend fun deleteComment(
postId: Long,
commentId: Long,
): Response<Unit>
): ApiResponse<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import com.app.edonymyeon.data.dto.response.PostDetailResponse
import com.app.edonymyeon.data.dto.response.PostEditorResponse
import com.app.edonymyeon.data.dto.response.Posts
import com.app.edonymyeon.data.service.PostService
import com.app.edonymyeon.data.service.client.calladapter.ApiResponse
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.asRequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import retrofit2.Response
import java.io.File
import javax.inject.Inject

Expand All @@ -22,22 +22,22 @@ class PostRemoteDataSource @Inject constructor(
override suspend fun getPostDetail(
postId: Long,
notificationId: Long,
): Response<PostDetailResponse> {
): ApiResponse<PostDetailResponse> {
return postService.getPost(postId, notificationId)
}

override suspend fun deletePost(postId: Long): Response<Unit> {
override suspend fun deletePost(postId: Long): ApiResponse<Unit> {
return postService.deletePost(postId)
}

override suspend fun getPosts(size: Int, page: Int): Response<Posts> {
override suspend fun getPosts(size: Int, page: Int): ApiResponse<Posts> {
return postService.getPosts(size, page)
}

override suspend fun savePost(
postEditorRequest: PostEditorRequest,
imageFiles: List<File>,
): Response<PostEditorResponse> {
): ApiResponse<PostEditorResponse> {
val postEditorMap: HashMap<String, RequestBody> = hashMapOf()
postEditorMap["title"] =
postEditorRequest.title.createRequestBody()
Expand All @@ -55,7 +55,7 @@ class PostRemoteDataSource @Inject constructor(
postEditorRequest: PostEditorRequest,
imageUrls: List<String>,
imageFiles: List<File>,
): Response<PostEditorResponse> {
): ApiResponse<PostEditorResponse> {
val postEditorMap: HashMap<String, RequestBody> = hashMapOf()
postEditorMap["title"] =
postEditorRequest.title.createRequestBody()
Expand All @@ -69,23 +69,23 @@ class PostRemoteDataSource @Inject constructor(
return postService.updatePost(id, postEditorMap, originalImages, newImages)
}

override suspend fun getHotPosts(): Response<Posts> {
override suspend fun getHotPosts(): ApiResponse<Posts> {
return postService.getHotPosts()
}

override suspend fun getComments(postId: Long): Response<CommentsResponse> {
override suspend fun getComments(postId: Long): ApiResponse<CommentsResponse> {
return postService.getComments(postId)
}

override suspend fun postComment(id: Long, image: File?, comment: String): Response<Unit> {
override suspend fun postComment(id: Long, image: File?, comment: String): ApiResponse<Unit> {
val requestFile = image?.asRequestBody("image/*".toMediaTypeOrNull())
val multipartFile =
requestFile?.let { MultipartBody.Part.createFormData("image", image.name, it) }
val requestBody = comment.createRequestBody()
return postService.postComment(id, if (image == null) null else multipartFile, requestBody)
}

override suspend fun deleteComment(postId: Long, commentId: Long): Response<Unit> {
override suspend fun deleteComment(postId: Long, commentId: Long): ApiResponse<Unit> {
return postService.deleteComment(postId, commentId)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package com.app.edonymyeon.data.datasource.preference

import com.app.edonymyeon.data.dto.request.NotificationPreferenceRequest
import com.app.edonymyeon.data.dto.response.NotificationPreferenceResponse
import retrofit2.Response
import com.app.edonymyeon.data.service.client.calladapter.ApiResponse

interface PreferenceDataSource {
suspend fun getNotificationPreference(): Response<NotificationPreferenceResponse>
suspend fun getNotificationPreference(): ApiResponse<NotificationPreferenceResponse>
suspend fun saveNotificationPreference(notificationPreferenceRequest: NotificationPreferenceRequest):
Response<NotificationPreferenceResponse>
ApiResponse<NotificationPreferenceResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package com.app.edonymyeon.data.datasource.preference
import com.app.edonymyeon.data.dto.request.NotificationPreferenceRequest
import com.app.edonymyeon.data.dto.response.NotificationPreferenceResponse
import com.app.edonymyeon.data.service.PreferenceService
import retrofit2.Response
import com.app.edonymyeon.data.service.client.calladapter.ApiResponse
import javax.inject.Inject

class PreferenceRemoteDataSource @Inject constructor(
private val preferenceService: PreferenceService,
) : PreferenceDataSource {

override suspend fun getNotificationPreference(): Response<NotificationPreferenceResponse> {
override suspend fun getNotificationPreference(): ApiResponse<NotificationPreferenceResponse> {
return preferenceService.getNotificationPreference()
}

override suspend fun saveNotificationPreference(notificationPreferenceRequest: NotificationPreferenceRequest): Response<NotificationPreferenceResponse> {
override suspend fun saveNotificationPreference(notificationPreferenceRequest: NotificationPreferenceRequest): ApiResponse<NotificationPreferenceResponse> {
return preferenceService.saveNotificationPreference(notificationPreferenceRequest)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ import com.app.edonymyeon.data.dto.request.PurchaseConfirmRequest
import com.app.edonymyeon.data.dto.request.SavingConfirmRequest
import com.app.edonymyeon.data.dto.response.AuthDuplicateResponse
import com.app.edonymyeon.data.dto.response.MyPostsResponse
import retrofit2.Response
import com.app.edonymyeon.data.service.client.calladapter.ApiResponse
import java.io.File

interface ProfileDataSource {
suspend fun getMyPosts(page: Int, notificationId: Long): Response<MyPostsResponse>
suspend fun getMyPosts(page: Int, notificationId: Long): ApiResponse<MyPostsResponse>
suspend fun postPurchaseConfirm(
id: Long,
purchaseConfirmRequest: PurchaseConfirmRequest,
): Response<Unit>
): ApiResponse<Unit>

suspend fun postSavingConfirm(
id: Long,
savingConfirmRequest: SavingConfirmRequest,
): Response<Unit>
): ApiResponse<Unit>

suspend fun deleteConfirm(id: Long): Response<Unit>
suspend fun getProfile(): Response<WriterDataModel>
suspend fun withdraw(): Response<Unit>
suspend fun deleteConfirm(id: Long): ApiResponse<Unit>
suspend fun getProfile(): ApiResponse<WriterDataModel>
suspend fun withdraw(): ApiResponse<Unit>

suspend fun updateProfile(
profileRequest: ProfileUpdateRequest,
newProfileImage: File?,
): Response<Unit>
): ApiResponse<Unit>

suspend fun checkDuplicate(target: String, value: String): Response<AuthDuplicateResponse>
suspend fun checkDuplicate(target: String, value: String): ApiResponse<AuthDuplicateResponse>
}
Loading
Loading