Skip to content

Commit

Permalink
refactor: ApiResult<Unit> 함수 추가 및 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
hxeyexn committed Jan 20, 2025
1 parent 8a26c95 commit 084f788
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ inline fun <T : Any, R : Any> ApiResult<T>.handle(convert: (T) -> R): ApiResult<
is ServerError -> ServerError(status, message)
is Success -> Success(convert(data))
}

fun ApiResult<Unit>.handle(): ApiResult<Unit> =
when (this) {
is Exception.NetworkError -> Exception.NetworkError()
is Exception.UnknownError -> Exception.UnknownError()
is ServerError -> ServerError(status, message)
is Success -> Success(data)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CommentDefaultRepository
override suspend fun createComment(newComment: NewComment): ApiResult<Unit> =
commentDataSource.createComment(
newComment.toDto(),
).handle { Unit }
).handle()

override suspend fun updateComment(
commentId: Long,
Expand All @@ -30,7 +30,7 @@ class CommentDefaultRepository
commentDataSource.updateComment(
commentId,
CommentUpdateRequest(content),
).handle { Unit }
).handle()

override suspend fun deleteComment(commentId: Long): ApiResult<Unit> = commentDataSource.deleteComment(commentId).handle { Unit }
override suspend fun deleteComment(commentId: Long): ApiResult<Unit> = commentDataSource.deleteComment(commentId).handle()
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MemoryDefaultRepository
override suspend fun updateMemory(
memoryId: Long,
newMemory: NewMemory,
): ApiResult<Unit> = memoryDataSource.updateMemory(memoryId, newMemory).handle { Unit }
): ApiResult<Unit> = memoryDataSource.updateMemory(memoryId, newMemory).handle()

override suspend fun deleteMemory(memoryId: Long): ApiResult<Unit> = memoryDataSource.deleteMemory(memoryId).handle { Unit }
override suspend fun deleteMemory(memoryId: Long): ApiResult<Unit> = memoryDataSource.deleteMemory(memoryId).handle()
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ class StaccatoDefaultRepository
memoryId = memoryId,
momentImageUrls = staccatoImageUrls,
),
).handle { Unit }
).handle()

override suspend fun deleteStaccato(staccatoId: Long): ApiResult<Unit> = remoteDataSource.deleteStaccato(staccatoId).handle { Unit }
override suspend fun deleteStaccato(staccatoId: Long): ApiResult<Unit> = remoteDataSource.deleteStaccato(staccatoId).handle()

override suspend fun updateFeeling(
staccatoId: Long,
Expand All @@ -85,5 +85,5 @@ class StaccatoDefaultRepository
remoteDataSource.updateFeeling(
staccatoId = staccatoId,
feelingRequest = FeelingRequest(feeling),
).handle { Unit }
).handle()
}

0 comments on commit 084f788

Please sign in to comment.