generated from AND-SOPT-ANDROID/and-sopt-android-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] #9 getMyHobby관련 clean architecture 적용
- Loading branch information
Showing
24 changed files
with
132 additions
and
45 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
10 changes: 10 additions & 0 deletions
10
app/src/main/java/org/sopt/and/data/datasource/GetMyHobbyDataSource.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,10 @@ | ||
package org.sopt.and.data.datasource | ||
|
||
import org.sopt.and.data.model.response.GetMyHobbyResponseDto | ||
import org.sopt.and.data.service.UserService | ||
|
||
class GetMyHobbyDataSource( | ||
private val userService: UserService | ||
) { | ||
suspend fun getMyHobby(): GetMyHobbyResponseDto = userService.getMyHobby() | ||
} |
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,9 @@ | ||
package org.sopt.and.data.mapper | ||
|
||
import org.sopt.and.data.model.response.GetMyHobbyResponseResultDto | ||
import org.sopt.and.domain.model.MyHobbyEntity | ||
|
||
object Mapper { | ||
fun toMyHobbyEntity(getHobbyResponseResultDto: GetMyHobbyResponseResultDto) = | ||
MyHobbyEntity(myHobby = getHobbyResponseResultDto.myHobby) | ||
} |
14 changes: 0 additions & 14 deletions
14
app/src/main/java/org/sopt/and/data/model/response/GetHobbyResponseDto.kt
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
app/src/main/java/org/sopt/and/data/model/response/GetMyHobbyResponseDto.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,16 @@ | ||
package org.sopt.and.data.model.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class GetMyHobbyResponseDto( | ||
val result: GetMyHobbyResponseResultDto? = null, | ||
val code: String? = null | ||
) | ||
|
||
@Serializable | ||
data class GetMyHobbyResponseResultDto( | ||
@SerialName("hobby") | ||
val myHobby: String | ||
) |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/org/sopt/and/data/repositoryimpl/GetMyHobbyRepositoryImpl.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,15 @@ | ||
package org.sopt.and.data.repositoryimpl | ||
|
||
import org.sopt.and.data.datasource.GetMyHobbyDataSource | ||
import org.sopt.and.data.mapper.Mapper | ||
import org.sopt.and.domain.model.MyHobbyEntity | ||
import org.sopt.and.domain.repository.GetMyHobbyRepository | ||
|
||
class GetMyHobbyRepositoryImpl( | ||
private val getMyHobbyDataSource: GetMyHobbyDataSource | ||
) : GetMyHobbyRepository { | ||
override suspend fun getMyHobby(): Result<MyHobbyEntity> = | ||
runCatching { | ||
getMyHobbyDataSource.getMyHobby().result?.let { Mapper.toMyHobbyEntity(it) }!! | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../java/org/sopt/and/services/ApiFactory.kt → ...a/org/sopt/and/data/service/ApiFactory.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
2 changes: 1 addition & 1 deletion
2
.../java/org/sopt/and/services/AppContext.kt → ...a/org/sopt/and/data/service/AppContext.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.sopt.and.services | ||
package org.sopt.and.data.service | ||
|
||
import android.content.Context | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
.../org/sopt/and/services/AuthInterceptor.kt → .../sopt/and/data/service/AuthInterceptor.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
4 changes: 2 additions & 2 deletions
4
...ava/org/sopt/and/services/TokenManager.kt → ...org/sopt/and/data/service/TokenManager.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
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
13 changes: 13 additions & 0 deletions
13
app/src/main/java/org/sopt/and/domain/repository/GetMyHobbyRepository.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 |
---|---|---|
@@ -1,7 +1,20 @@ | ||
package org.sopt.and.domain.repository | ||
|
||
import org.sopt.and.data.datasource.GetMyHobbyDataSource | ||
import org.sopt.and.data.repositoryimpl.GetMyHobbyRepositoryImpl | ||
import org.sopt.and.data.service.ServicePool | ||
import org.sopt.and.domain.model.MyHobbyEntity | ||
|
||
interface GetMyHobbyRepository { | ||
suspend fun getMyHobby(): Result<MyHobbyEntity> | ||
|
||
companion object { | ||
fun create(): GetMyHobbyRepositoryImpl { | ||
return GetMyHobbyRepositoryImpl( | ||
GetMyHobbyDataSource( | ||
ServicePool.userService | ||
) | ||
) | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/org/sopt/and/domain/usecase/GetMyHobbyUseCase.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,11 @@ | ||
package org.sopt.and.domain.usecase | ||
|
||
import org.sopt.and.domain.model.MyHobbyEntity | ||
import org.sopt.and.domain.repository.GetMyHobbyRepository | ||
|
||
class GetMyHobbyUseCase( | ||
private val getMyHobbyRepository: GetMyHobbyRepository | ||
) { | ||
suspend operator fun invoke(): Result<MyHobbyEntity> = | ||
getMyHobbyRepository.getMyHobby() | ||
} |
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
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
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
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
24 changes: 24 additions & 0 deletions
24
app/src/main/java/org/sopt/and/presentation/viewmodelfactory/ViewModelFactory.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,24 @@ | ||
package org.sopt.and.presentation.viewmodelfactory | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import org.sopt.and.domain.repository.GetMyHobbyRepository | ||
import org.sopt.and.domain.usecase.GetMyHobbyUseCase | ||
import org.sopt.and.presentation.myinfo.MyInfoViewModel | ||
|
||
class MyInfoViewModelFactory() : ViewModelProvider.Factory { | ||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
return when (modelClass) { | ||
|
||
MyInfoViewModel::class.java -> { | ||
MyInfoViewModel( | ||
GetMyHobbyUseCase( | ||
getMyHobbyRepository = GetMyHobbyRepository.create() | ||
) | ||
) as T | ||
} | ||
|
||
else -> throw IllegalArgumentException("Unknown ViewModel Class") | ||
} | ||
} | ||
} |