-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/#538-member-profile-image-change
# Conflicts: # android/Staccato_AN/app/src/main/java/com/on/staccato/presentation/memorycreation/viewmodel/MemoryCreationViewModel.kt # android/Staccato_AN/app/src/main/java/com/on/staccato/presentation/memoryupdate/viewmodel/MemoryUpdateViewModel.kt # android/Staccato_AN/app/src/main/java/com/on/staccato/presentation/staccatocreation/viewmodel/StaccatoCreationViewModel.kt # android/Staccato_AN/app/src/main/java/com/on/staccato/presentation/staccatoupdate/viewmodel/StaccatoUpdateViewModel.kt
- Loading branch information
Showing
106 changed files
with
3,102 additions
and
984 deletions.
There are no files selected for viewing
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
2 changes: 1 addition & 1 deletion
2
...ub/workflows/backend-ci-cd-multi-prod.yml → ...hub/workflows/backend-ci-cd-multi-dev.yml
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Backend CI/CD multi prod | ||
name: Backend CI/CD multi dev | ||
|
||
on: | ||
push: | ||
|
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
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
60 changes: 0 additions & 60 deletions
60
android/Staccato_AN/app/src/main/java/com/on/staccato/data/ApiResponseHandler.kt
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
android/Staccato_AN/app/src/main/java/com/on/staccato/data/ApiResult.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,31 @@ | ||
package com.on.staccato.data | ||
|
||
import com.on.staccato.data.dto.Status | ||
|
||
sealed interface ApiResult<T : Any> | ||
|
||
class Success<T : Any>(val data: T) : ApiResult<T> | ||
|
||
class ServerError<T : Any>(val status: Status, val message: String) : ApiResult<T> | ||
|
||
sealed class Exception<T : Any> : ApiResult<T> { | ||
class NetworkError<T : Any> : Exception<T>() | ||
|
||
class UnknownError<T : Any> : Exception<T>() | ||
} | ||
|
||
inline fun <T : Any, R : Any> ApiResult<T>.handle(convert: (T) -> R): ApiResult<R> = | ||
when (this) { | ||
is Exception.NetworkError -> Exception.NetworkError() | ||
is Exception.UnknownError -> Exception.UnknownError() | ||
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) | ||
} |
90 changes: 90 additions & 0 deletions
90
android/Staccato_AN/app/src/main/java/com/on/staccato/data/ApiResultCall.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,90 @@ | ||
package com.on.staccato.data | ||
|
||
import com.on.staccato.StaccatoApplication.Companion.retrofit | ||
import com.on.staccato.data.StaccatoClient.getErrorResponse | ||
import com.on.staccato.data.dto.ErrorResponse | ||
import com.on.staccato.data.dto.Status | ||
import okhttp3.Request | ||
import okhttp3.ResponseBody | ||
import okio.Timeout | ||
import retrofit2.Call | ||
import retrofit2.HttpException | ||
import retrofit2.Response | ||
import java.io.IOException | ||
|
||
class ApiResultCall<T : Any>( | ||
private val delegate: Call<T>, | ||
) : Call<ApiResult<T>> { | ||
override fun enqueue(callback: retrofit2.Callback<ApiResult<T>>) { | ||
delegate.enqueue( | ||
object : retrofit2.Callback<T> { | ||
override fun onResponse( | ||
call: Call<T>, | ||
response: Response<T>, | ||
) { | ||
val networkResult: ApiResult<T> = handleApiResponse { response } | ||
callback.onResponse(this@ApiResultCall, Response.success(networkResult)) | ||
} | ||
|
||
override fun onFailure( | ||
call: Call<T>, | ||
throwable: Throwable, | ||
) { | ||
val exception = handleException<T>(throwable) | ||
callback.onResponse(this@ApiResultCall, Response.success(exception)) | ||
} | ||
}, | ||
) | ||
} | ||
|
||
override fun execute(): Response<ApiResult<T>> = throw NotImplementedError() | ||
|
||
override fun clone(): Call<ApiResult<T>> = ApiResultCall(delegate.clone()) | ||
|
||
override fun isExecuted(): Boolean = delegate.isExecuted | ||
|
||
override fun cancel() { | ||
delegate.cancel() | ||
} | ||
|
||
override fun isCanceled(): Boolean = delegate.isCanceled | ||
|
||
override fun request(): Request = delegate.request() | ||
|
||
override fun timeout(): Timeout = delegate.timeout() | ||
} | ||
|
||
private const val CREATED = 201 | ||
private const val NOT_FOUND_ERROR_BODY = "errorBody를 찾을 수 없습니다." | ||
|
||
private fun <T : Any> handleApiResponse(execute: () -> Response<T>): ApiResult<T> { | ||
return try { | ||
val response: Response<T> = execute() | ||
val body: T? = response.body() | ||
|
||
when { | ||
response.isSuccessful && response.code() == CREATED -> Success(body as T) | ||
response.isSuccessful && body != null -> Success(body) | ||
else -> { | ||
val errorBody: ResponseBody = | ||
response.errorBody() | ||
?: throw IllegalArgumentException(NOT_FOUND_ERROR_BODY) | ||
val errorResponse: ErrorResponse = retrofit.getErrorResponse(errorBody) | ||
ServerError( | ||
status = Status.Message(errorResponse.status), | ||
message = errorResponse.message, | ||
) | ||
} | ||
} | ||
} catch (httpException: HttpException) { | ||
ServerError(status = Status.Code(httpException.code()), message = httpException.message()) | ||
} catch (throwable: Throwable) { | ||
handleException<T>(throwable) | ||
} | ||
} | ||
|
||
private fun <T : Any> handleException(throwable: Throwable) = | ||
when (throwable) { | ||
is IOException -> Exception.NetworkError<T>() | ||
else -> Exception.UnknownError<T>() | ||
} |
13 changes: 13 additions & 0 deletions
13
android/Staccato_AN/app/src/main/java/com/on/staccato/data/ApiResultCallAdapter.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,13 @@ | ||
package com.on.staccato.data | ||
|
||
import retrofit2.Call | ||
import retrofit2.CallAdapter | ||
import java.lang.reflect.Type | ||
|
||
class ApiResultCallAdapter( | ||
private val resultType: Type, | ||
) : CallAdapter<Type, Call<ApiResult<Type>>> { | ||
override fun responseType(): Type = resultType | ||
|
||
override fun adapt(call: Call<Type>): Call<ApiResult<Type>> = ApiResultCall(call) | ||
} |
32 changes: 32 additions & 0 deletions
32
android/Staccato_AN/app/src/main/java/com/on/staccato/data/ApiResultCallAdapterFactory.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,32 @@ | ||
package com.on.staccato.data | ||
|
||
import retrofit2.Call | ||
import retrofit2.CallAdapter | ||
import retrofit2.Retrofit | ||
import java.lang.reflect.ParameterizedType | ||
import java.lang.reflect.Type | ||
|
||
class ApiResultCallAdapterFactory : CallAdapter.Factory() { | ||
override fun get( | ||
returnType: Type, | ||
annotations: Array<out Annotation>, | ||
retrofit: Retrofit, | ||
): CallAdapter<*, *>? { | ||
if (getRawType(returnType) != Call::class.java) { | ||
return null | ||
} | ||
|
||
val responseType = getParameterUpperBound(0, returnType as ParameterizedType) | ||
|
||
if (getRawType(responseType) != ApiResult::class.java) { | ||
return null | ||
} | ||
|
||
val resultType = getParameterUpperBound(0, responseType as ParameterizedType) | ||
return ApiResultCallAdapter(resultType) | ||
} | ||
|
||
companion object { | ||
fun create(): ApiResultCallAdapterFactory = ApiResultCallAdapterFactory() | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
android/Staccato_AN/app/src/main/java/com/on/staccato/data/ApiResultHandler.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.on.staccato.data | ||
|
||
import com.on.staccato.presentation.util.ExceptionState | ||
|
||
inline fun <T : Any> ApiResult<T>.onSuccess(action: (T) -> Unit): ApiResult<T> = | ||
apply { | ||
if (this is Success<T>) action(data) | ||
} | ||
|
||
inline fun <T : Any> ApiResult<T>.onServerError(action: (message: String) -> Unit): ApiResult<T> = | ||
apply { | ||
if (this is ServerError<T>) action(message) | ||
} | ||
|
||
inline fun <T : Any> ApiResult<T>.onException(action: (exceptionState: ExceptionState) -> Unit): ApiResult<T> = | ||
apply { | ||
if (this is Exception<T>) { | ||
when (this) { | ||
is Exception.NetworkError -> action(ExceptionState.NetworkError) | ||
is Exception.UnknownError -> action(ExceptionState.UnknownError) | ||
} | ||
} | ||
} |
11 changes: 0 additions & 11 deletions
11
android/Staccato_AN/app/src/main/java/com/on/staccato/data/ResponseResult.kt
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.