From 084f7887d112adc548f5edd8518325eda128e9c1 Mon Sep 17 00:00:00 2001 From: hxeyexn Date: Mon, 20 Jan 2025 17:02:29 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20ApiResult=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/src/main/java/com/on/staccato/data/ApiResult.kt | 8 ++++++++ .../on/staccato/data/comment/CommentDefaultRepository.kt | 6 +++--- .../on/staccato/data/memory/MemoryDefaultRepository.kt | 4 ++-- .../staccato/data/staccato/StaccatoDefaultRepository.kt | 6 +++--- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/android/Staccato_AN/app/src/main/java/com/on/staccato/data/ApiResult.kt b/android/Staccato_AN/app/src/main/java/com/on/staccato/data/ApiResult.kt index 53c62102..a530165d 100644 --- a/android/Staccato_AN/app/src/main/java/com/on/staccato/data/ApiResult.kt +++ b/android/Staccato_AN/app/src/main/java/com/on/staccato/data/ApiResult.kt @@ -21,3 +21,11 @@ inline fun ApiResult.handle(convert: (T) -> R): ApiResult< is ServerError -> ServerError(status, message) is Success -> Success(convert(data)) } + +fun ApiResult.handle(): ApiResult = + when (this) { + is Exception.NetworkError -> Exception.NetworkError() + is Exception.UnknownError -> Exception.UnknownError() + is ServerError -> ServerError(status, message) + is Success -> Success(data) + } diff --git a/android/Staccato_AN/app/src/main/java/com/on/staccato/data/comment/CommentDefaultRepository.kt b/android/Staccato_AN/app/src/main/java/com/on/staccato/data/comment/CommentDefaultRepository.kt index 3e372335..abe941f5 100644 --- a/android/Staccato_AN/app/src/main/java/com/on/staccato/data/comment/CommentDefaultRepository.kt +++ b/android/Staccato_AN/app/src/main/java/com/on/staccato/data/comment/CommentDefaultRepository.kt @@ -21,7 +21,7 @@ class CommentDefaultRepository override suspend fun createComment(newComment: NewComment): ApiResult = commentDataSource.createComment( newComment.toDto(), - ).handle { Unit } + ).handle() override suspend fun updateComment( commentId: Long, @@ -30,7 +30,7 @@ class CommentDefaultRepository commentDataSource.updateComment( commentId, CommentUpdateRequest(content), - ).handle { Unit } + ).handle() - override suspend fun deleteComment(commentId: Long): ApiResult = commentDataSource.deleteComment(commentId).handle { Unit } + override suspend fun deleteComment(commentId: Long): ApiResult = commentDataSource.deleteComment(commentId).handle() } diff --git a/android/Staccato_AN/app/src/main/java/com/on/staccato/data/memory/MemoryDefaultRepository.kt b/android/Staccato_AN/app/src/main/java/com/on/staccato/data/memory/MemoryDefaultRepository.kt index 8415a472..e4d5f32d 100644 --- a/android/Staccato_AN/app/src/main/java/com/on/staccato/data/memory/MemoryDefaultRepository.kt +++ b/android/Staccato_AN/app/src/main/java/com/on/staccato/data/memory/MemoryDefaultRepository.kt @@ -26,7 +26,7 @@ class MemoryDefaultRepository override suspend fun updateMemory( memoryId: Long, newMemory: NewMemory, - ): ApiResult = memoryDataSource.updateMemory(memoryId, newMemory).handle { Unit } + ): ApiResult = memoryDataSource.updateMemory(memoryId, newMemory).handle() - override suspend fun deleteMemory(memoryId: Long): ApiResult = memoryDataSource.deleteMemory(memoryId).handle { Unit } + override suspend fun deleteMemory(memoryId: Long): ApiResult = memoryDataSource.deleteMemory(memoryId).handle() } diff --git a/android/Staccato_AN/app/src/main/java/com/on/staccato/data/staccato/StaccatoDefaultRepository.kt b/android/Staccato_AN/app/src/main/java/com/on/staccato/data/staccato/StaccatoDefaultRepository.kt index 0ba967a0..c2ed9426 100644 --- a/android/Staccato_AN/app/src/main/java/com/on/staccato/data/staccato/StaccatoDefaultRepository.kt +++ b/android/Staccato_AN/app/src/main/java/com/on/staccato/data/staccato/StaccatoDefaultRepository.kt @@ -74,9 +74,9 @@ class StaccatoDefaultRepository memoryId = memoryId, momentImageUrls = staccatoImageUrls, ), - ).handle { Unit } + ).handle() - override suspend fun deleteStaccato(staccatoId: Long): ApiResult = remoteDataSource.deleteStaccato(staccatoId).handle { Unit } + override suspend fun deleteStaccato(staccatoId: Long): ApiResult = remoteDataSource.deleteStaccato(staccatoId).handle() override suspend fun updateFeeling( staccatoId: Long, @@ -85,5 +85,5 @@ class StaccatoDefaultRepository remoteDataSource.updateFeeling( staccatoId = staccatoId, feelingRequest = FeelingRequest(feeling), - ).handle { Unit } + ).handle() }