-
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 pull request #1 from hyeonhh/feature/code-refactor
refactor : 코드 구조 개선
- Loading branch information
Showing
112 changed files
with
2,137 additions
and
789 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
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
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/example/com_us/base/AppInterceptor.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,28 @@ | ||
package com.example.com_us.base | ||
|
||
import android.util.Log | ||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
import java.io.IOException | ||
|
||
class AppInterceptor(private val accessToken: String) : Interceptor { | ||
private val contentType = "application/json" | ||
@Throws(IOException::class) | ||
override fun intercept(chain: Interceptor.Chain) : Response = with(chain) { | ||
val newRequest = request().newBuilder() | ||
.addHeader("Content-Type", contentType) | ||
.addHeader("Authorization", accessToken) | ||
.build() | ||
|
||
val response = proceed(newRequest) | ||
when (response.code) { | ||
401, 404 -> { | ||
Log.d("API FAILURE", response.toString()) | ||
} | ||
500 -> { | ||
Log.d("API FAILURE 500", response.toString()) | ||
} | ||
} | ||
response | ||
} | ||
} |
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,8 @@ | ||
package com.example.com_us.base | ||
|
||
import android.app.Application | ||
import dagger.hilt.android.HiltAndroidApp | ||
|
||
@HiltAndroidApp | ||
class Application : Application() { | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/example/com_us/base/data/BaseResponse.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,26 @@ | ||
package com.example.com_us.base.data | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class BaseResponse<T>( | ||
val status: Int, | ||
val message: String, | ||
val data: T? = null, | ||
) | ||
|
||
@Serializable | ||
data class BaseResponseNoData( | ||
val status: Int, | ||
val message: String, | ||
) | ||
|
||
fun <T> BaseResponse<T>.toResult(): Result<T> { | ||
return when{ | ||
status == 200 && data != null -> Result.success(data) | ||
status == 200 && data == null -> Result.failure(NetworkError.NullDataError()) | ||
status == 400 or 401 -> Result.failure(NetworkError.ApiError(status, message)) | ||
status == 500 -> Result.failure(NetworkError.ApiError(status, message)) | ||
else -> Result.failure(NetworkError.ApiError(status, message)) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/example/com_us/base/data/NetworkError.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,17 @@ | ||
package com.example.com_us.base.data | ||
|
||
sealed class NetworkError : Exception(){ | ||
data class ApiError( | ||
val statusCode : Int, | ||
override val message : String | ||
) : NetworkError() | ||
|
||
data class NetworkException( | ||
override val cause : Throwable, | ||
) : NetworkError() | ||
|
||
data class NullDataError( | ||
override val message : String = "Data is null" | ||
) : NetworkError() | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/example/com_us/base/di/ServiceModule.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,22 @@ | ||
package com.example.com_us.base.di | ||
|
||
import android.content.Context | ||
import com.example.com_us.R | ||
import com.example.com_us.data.di.BaseUrl | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
import dagger.Provides | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object ServiceModule { | ||
|
||
@Provides | ||
@BaseUrl | ||
fun provideBaseUrl( | ||
@ApplicationContext context: Context | ||
) : String = context.getString(R.string.baseUrl) | ||
} |
8 changes: 0 additions & 8 deletions
8
app/src/main/java/com/example/com_us/data/datasource/HomeDataSource.kt
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
app/src/main/java/com/example/com_us/data/datasource/HomeRemoteDataSource.kt
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
app/src/main/java/com/example/com_us/data/datasource/ProfileDataSource.kt
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
app/src/main/java/com/example/com_us/data/datasource/ProfileRemoteDataSource.kt
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
app/src/main/java/com/example/com_us/data/datasource/QuestionDataSource.kt
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
app/src/main/java/com/example/com_us/data/datasource/QuestionRemoteDataSource.kt
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/example/com_us/data/default_repository/DefaultHomeRepository.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,22 @@ | ||
package com.example.com_us.data.default_repository | ||
|
||
import com.example.com_us.base.data.NetworkError | ||
import com.example.com_us.data.model.home.ResponseHomeDataDto | ||
import com.example.com_us.data.repository.HomeRepository | ||
import com.example.com_us.data.default_source.DefaultHomeDataSource | ||
import com.example.com_us.base.data.toResult | ||
import javax.inject.Inject | ||
|
||
|
||
|
||
class DefaultHomeRepository @Inject constructor( | ||
private val defaultHomeDataSource: DefaultHomeDataSource | ||
) : HomeRepository { | ||
override suspend fun getHomeData(): Result<ResponseHomeDataDto> { | ||
return try { | ||
defaultHomeDataSource.getHomeData().toResult() | ||
} catch (e: Exception) { | ||
Result.failure(NetworkError.NetworkException(e)) | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/example/com_us/data/default_repository/DefaultProfileRepository.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,20 @@ | ||
package com.example.com_us.data.default_repository | ||
|
||
import com.example.com_us.base.data.NetworkError | ||
import com.example.com_us.data.model.question.response.question.ResponseProfileDto | ||
import com.example.com_us.data.repository.ProfileRepository | ||
import com.example.com_us.data.default_source.DefaultProfileDataSource | ||
import com.example.com_us.base.data.toResult | ||
import javax.inject.Inject | ||
|
||
class DefaultProfileRepository @Inject constructor( | ||
private val profileRemoteDataSource: DefaultProfileDataSource | ||
) : ProfileRepository { | ||
override suspend fun getProfileData(): Result<ResponseProfileDto> { | ||
return try { | ||
profileRemoteDataSource.getProfileData().toResult() | ||
}catch (e: Exception){ | ||
Result.failure(NetworkError.NetworkException(e)) | ||
} | ||
} | ||
} |
Oops, something went wrong.