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.
- Loading branch information
Showing
13 changed files
with
127 additions
and
11 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
app/src/main/java/org/sopt/and/data/datasource/remote/MyRemoteDataSource.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,8 @@ | ||
package org.sopt.and.data.datasource.remote | ||
|
||
import org.sopt.and.data.model.response.ResponseHobbyDto | ||
import org.sopt.and.presentation.util.NullableBaseRespone | ||
|
||
interface MyRemoteDataSource { | ||
suspend fun getMyHobby(): NullableBaseRespone<ResponseHobbyDto> | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/org/sopt/and/data/datasourceImpl/remote/MyRemoteDataSourceImpl.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,14 @@ | ||
package org.sopt.and.data.datasourceImpl.remote | ||
|
||
import org.sopt.and.data.datasource.remote.MyRemoteDataSource | ||
import org.sopt.and.data.model.response.ResponseHobbyDto | ||
import org.sopt.and.data.service.MyService | ||
import org.sopt.and.presentation.util.NullableBaseRespone | ||
import javax.inject.Inject | ||
|
||
class MyRemoteDataSourceImpl @Inject constructor( | ||
private val myService: MyService | ||
) : MyRemoteDataSource { | ||
override suspend fun getMyHobby(): NullableBaseRespone<ResponseHobbyDto> = | ||
myService.getMyHobby() | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/org/sopt/and/data/repositoryImpl/MyRepositoryImpl.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.remote.MyRemoteDataSource | ||
import org.sopt.and.domain.model.UserHobbyEntity | ||
import org.sopt.and.domain.repository.MyRepository | ||
import javax.inject.Inject | ||
|
||
class MyRepositoryImpl @Inject constructor( | ||
private val myRemoteDataSource: MyRemoteDataSource | ||
) : MyRepository { | ||
override suspend fun getMyHobby(): Result<UserHobbyEntity> = | ||
runCatching { | ||
myRemoteDataSource.getMyHobby().result.toUserHobbyEntity() | ||
} | ||
} |
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.service | ||
|
||
import org.sopt.and.data.model.response.ResponseHobbyDto | ||
import org.sopt.and.data.service.AuthService.Companion.USER | ||
import org.sopt.and.presentation.util.NullableBaseRespone | ||
import retrofit2.http.GET | ||
|
||
interface MyService { | ||
@GET("/$USER/$HOBBY") | ||
suspend fun getMyHobby(): NullableBaseRespone<ResponseHobbyDto> | ||
|
||
companion object { | ||
const val HOBBY = "my-hobby" | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
app/src/main/java/org/sopt/and/domain/repository/MyRepository.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,7 @@ | ||
package org.sopt.and.domain.repository | ||
|
||
import org.sopt.and.domain.model.UserHobbyEntity | ||
|
||
interface MyRepository { | ||
suspend fun getMyHobby(): Result<UserHobbyEntity> | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/org/sopt/and/domain/usecase/GetUserHobbyUseCase.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.UserHobbyEntity | ||
import org.sopt.and.domain.repository.MyRepository | ||
|
||
class GetUserHobbyUseCase( | ||
private val myRepository: MyRepository | ||
) { | ||
suspend operator fun invoke(): Result<UserHobbyEntity> = | ||
myRepository.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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ import org.sopt.and.ui.theme.White | |
|
||
@Composable | ||
fun MyScreen( | ||
userName: String, | ||
userHobby: String, | ||
modifier: Modifier = Modifier | ||
) { | ||
Column( | ||
|
@@ -44,7 +44,7 @@ fun MyScreen( | |
.padding(horizontal = 15.dp, vertical = 20.dp), | ||
verticalArrangement = Arrangement.spacedBy(8.dp) | ||
) { | ||
MyProfile(userEmail = userName) | ||
MyProfile(userHobby = userHobby) | ||
|
||
MyPurchaseBox(information = stringResource(R.string.my_purchase_event)) | ||
|
||
|
@@ -69,7 +69,7 @@ fun MyScreen( | |
} | ||
|
||
@Composable | ||
fun MyProfile(userEmail: String) { | ||
fun MyProfile(userHobby: String) { | ||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth(), | ||
|
@@ -83,7 +83,7 @@ fun MyProfile(userEmail: String) { | |
) | ||
|
||
Text( | ||
text = stringResource(R.string.my_nickname, userEmail), | ||
text = stringResource(R.string.my_hobby, userHobby), | ||
modifier = Modifier | ||
.padding(start = 8.dp), | ||
color = White | ||
|
@@ -178,6 +178,6 @@ fun MyListBox(title: String, description: String) { | |
@Composable | ||
fun MyPreview() { | ||
ANDANDROIDTheme { | ||
MyScreen(userName = "[email protected]") | ||
MyScreen(userHobby = "swim") | ||
} | ||
} |
23 changes: 20 additions & 3 deletions
23
app/src/main/java/org/sopt/and/presentation/ui/my/MyViewModel.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,13 +1,30 @@ | ||
package org.sopt.and.presentation.ui.my | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import org.sopt.and.data.datasource.local.WaveLocalDataSource | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.launch | ||
import org.sopt.and.domain.usecase.GetUserHobbyUseCase | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class MyViewModel @Inject constructor( | ||
private val localDataSource: WaveLocalDataSource | ||
private val getUserHobbyUseCase: GetUserHobbyUseCase | ||
) : ViewModel() { | ||
fun getLocalUserMail(): String = localDataSource.userEmail | ||
private val _userHobby = MutableStateFlow<String>("") | ||
val userHobby: StateFlow<String> = _userHobby | ||
|
||
init { | ||
getUserHobby() | ||
} | ||
|
||
private fun getUserHobby() { | ||
viewModelScope.launch { | ||
getUserHobbyUseCase().onSuccess { data -> | ||
_userHobby.value = data.hobby | ||
} | ||
} | ||
} | ||
} |