Skip to content

Commit

Permalink
[feature] #9 - myInfo 재구현
Browse files Browse the repository at this point in the history
  • Loading branch information
sayyyho committed Dec 8, 2024
1 parent 9e4b874 commit 70cb373
Show file tree
Hide file tree
Showing 29 changed files with 396 additions and 140 deletions.
57 changes: 6 additions & 51 deletions app/src/main/java/org/sopt/and/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,19 @@ package org.sopt.and
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.runtime.Composable
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import org.sopt.and.navigation.SignNavigation
import org.sopt.and.signup.SignUpScreen

import org.sopt.and.signin.SignInScreen

import org.sopt.and.data.service.AppContext
import org.sopt.and.presentation.navigation.Navigation
import org.sopt.and.ui.theme.ANDANDROIDTheme
import org.sopt.and.presentation.viewmodel.SignViewModel

import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
AppContext.init(this)

setContent {
ANDANDROIDTheme {
val signViewModel: SignViewModel = viewModel()
MyApp(signViewModel)
Navigation()
}
}
}
}

@Composable
fun MyApp(signViewModel: SignViewModel) {
val navController = rememberNavController()

NavHost(navController, startDestination = SignNavigation.SignUp.route) {
composable(SignNavigation.SignUp.route) {
SignUpScreen(
signViewModel = signViewModel,
// onNavigateBack = { navController.popBackStack() },
onNavigateToSignIn = { navController.navigate("signIn") },
)
}
composable(SignNavigation.SignIn.route) {
SignInScreen(
signViewModel = signViewModel,
onNavigateToMain = {navController.navigate("main"){
popUpTo(navController.graph.findStartDestination().id) { saveState = true }
launchSingleTop = true
}},
onNavigateToSignUp = {navController.navigate("signUp")}

)
}

composable(SignNavigation.Main.route) {
MainScreen(signViewModel = signViewModel)
}
}
}

}
7 changes: 0 additions & 7 deletions app/src/main/java/org/sopt/and/MyApplication.kt

This file was deleted.

4 changes: 2 additions & 2 deletions app/src/main/java/org/sopt/and/data/mapper/Mapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.sopt.and.data.mapper

import org.sopt.and.data.model.request.SignInRequestDto
import org.sopt.and.data.model.request.SignUpRequestDto
import org.sopt.and.data.model.response.GetMyHobbyResponseResultDto
import org.sopt.and.data.model.response.MyHobbyResponseResultDto
import org.sopt.and.data.model.response.SignInResponseDto
import org.sopt.and.data.model.response.SignUpResponseDto
import org.sopt.and.domain.model.MyHobbyEntity
Expand All @@ -13,7 +13,7 @@ import org.sopt.and.domain.model.SignUpResponseEntity
import retrofit2.Response

object Mapper {
fun toMyHobbyEntity(getHobbyResponseResultDto: GetMyHobbyResponseResultDto) =
fun toMyHobbyEntity(getHobbyResponseResultDto: MyHobbyResponseResultDto) =
MyHobbyEntity(myHobby = getHobbyResponseResultDto.myHobby)

fun toSignUpResponseEntity(signUpResponseDto: Response<SignUpResponseDto>) =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.sopt.and.data.repositoryimpl

import org.sopt.and.data.datasource.GetMyHobbyDataSource
import org.sopt.and.data.datasource.MyHobbyDataSource
import org.sopt.and.data.mapper.Mapper
import org.sopt.and.domain.model.MyHobbyEntity
import org.sopt.and.domain.usecase.GetMyHobbyRepository
import org.sopt.and.domain.repository.MyHobbyRepository

class MyHobbyRepositoryImpl(
private val getMyHobbyDataSource: GetMyHobbyDataSource
) : GetMyHobbyRepository {
private val getMyHobbyDataSource: MyHobbyDataSource
) : MyHobbyRepository {
override suspend fun getMyHobby(): Result<MyHobbyEntity> =
runCatching {
getMyHobbyDataSource.getMyHobby().result?.let { Mapper.toMyHobbyEntity(it) }!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.sopt.and.data.datasource.SignInDataSource
import org.sopt.and.data.mapper.Mapper
import org.sopt.and.domain.model.SignInInformationEntity
import org.sopt.and.domain.model.SignInResponseEntity
import org.sopt.and.domain.usecase.SignInRepository
import org.sopt.and.domain.repository.SignInRepository

class SignInRepositoryImpl(
private val signInDataSource: SignInDataSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.sopt.and.data.datasource.SignUpDataSource
import org.sopt.and.data.mapper.Mapper
import org.sopt.and.domain.model.SignUpInformationEntity
import org.sopt.and.domain.model.SignUpResponseEntity
import org.sopt.and.domain.usecase.SignUpRepository
import org.sopt.and.domain.repository.SignUpRepository

class SignUpRepositoryImpl(
private val signUpDataSource: SignUpDataSource
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/sopt/and/data/service/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ interface UserService {
suspend fun signIn(@Body request: SignInRequestDto): Response<SignInResponseDto>

@GET("/user/my-hobby")
suspend fun getMyHobby(): GetMyHobbyResponseDto
suspend fun getMyHobby(): MyHobbyResponseDto
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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.datasource.MyHobbyDataSource
import org.sopt.and.data.repositoryimpl.MyHobbyRepositoryImpl
import org.sopt.and.data.service.ServicePool
import org.sopt.and.domain.model.MyHobbyEntity

interface MyHobbyRepository {
suspend fun getMyHobby(): Result<MyHobbyEntity>

companion object {
fun create(): GetMyHobbyRepositoryImpl {
return GetMyHobbyRepositoryImpl(
GetMyHobbyDataSource(
fun create(): MyHobbyRepositoryImpl {
return MyHobbyRepositoryImpl(
MyHobbyDataSource(
ServicePool.userService
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.sopt.and.domain.usecase

import org.sopt.and.domain.model.MyHobbyEntity
import org.sopt.and.domain.repository.GetMyHobbyRepository
import org.sopt.and.domain.repository.MyHobbyRepository

class MyHobbyUseCase(
private val getMyHobbyRepository: GetMyHobbyRepository
private val getMyHobbyRepository: MyHobbyRepository
) {
suspend operator fun invoke(): Result<MyHobbyEntity> =
getMyHobbyRepository.getMyHobby()
Expand Down
30 changes: 0 additions & 30 deletions app/src/main/java/org/sopt/and/navigation/BottomNavigation.kt

This file was deleted.

26 changes: 0 additions & 26 deletions app/src/main/java/org/sopt/and/navigation/BottomNavigationGraph.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and
package org.sopt.and.presentation

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.RowScope
Expand All @@ -20,8 +20,8 @@ import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import org.sopt.and.navigation.BottomNavigationGraph
import org.sopt.and.navigation.BottomNavigation
import org.sopt.and.presentation.navigation.BottomNavigationGraph
import org.sopt.and.presentation.navigation.BottomNavigation
import org.sopt.and.presentation.viewmodel.SignViewModel

@Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.home
package org.sopt.and.presentation.home

import androidx.annotation.StringRes
import androidx.compose.foundation.Image
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.sopt.and.presentation.myinfo

data class MyInfoUiState(
val myHobby: String = "오류"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.sopt.and.presentation.myinfo

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import org.sopt.and.domain.model.MyHobbyEntity
import org.sopt.and.domain.usecase.MyHobbyUseCase

class MyInfoViewModel(
private val getMyHobbyUseCase: MyHobbyUseCase
) : ViewModel() {

private val _uiState = MutableStateFlow(MyInfoUiState())
val uiState: StateFlow<MyInfoUiState> = _uiState.asStateFlow()

private fun setMyHobby(myHobby: String) {
_uiState.value = _uiState.value.copy(myHobby = myHobby)
}

fun getMyHobby() {
viewModelScope.launch {
getMyHobbyUseCase().onSuccess { myHobbyEntity: MyHobbyEntity ->
setMyHobby(myHobbyEntity.myHobby)
}.onFailure { }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.myinfo
package org.sopt.and.presentation.myinfo

import android.annotation.SuppressLint
import android.util.Log
Expand Down
Loading

0 comments on commit 70cb373

Please sign in to comment.