From 0eeb1065b8e193625b1dae95aaf1a7388307ab91 Mon Sep 17 00:00:00 2001 From: DoReMinWoo Date: Fri, 12 Jan 2024 00:28:12 +0900 Subject: [PATCH 01/13] =?UTF-8?q?[add]=20#98=20DI(Hilt)=20Module=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/org/sopt/pingle/di/DataSourceModule.kt | 8 +++++++- app/src/main/java/org/sopt/pingle/di/RepositoryModule.kt | 8 +++++++- app/src/main/java/org/sopt/pingle/di/ServiceModule.kt | 9 +++++++-- app/src/main/java/org/sopt/pingle/di/UseCaseModule.kt | 9 ++++++++- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/sopt/pingle/di/DataSourceModule.kt b/app/src/main/java/org/sopt/pingle/di/DataSourceModule.kt index 92780fcb..f76dcef4 100644 --- a/app/src/main/java/org/sopt/pingle/di/DataSourceModule.kt +++ b/app/src/main/java/org/sopt/pingle/di/DataSourceModule.kt @@ -4,13 +4,15 @@ import dagger.Binds import dagger.Module import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent -import javax.inject.Singleton import org.sopt.pingle.data.datasource.local.DummyLocalDataSource import org.sopt.pingle.data.datasource.remote.DummyRemoteDataSource +import org.sopt.pingle.data.datasource.remote.JoinGroupCodeRemoteDataSource import org.sopt.pingle.data.datasource.remote.MapRemoteDataSource import org.sopt.pingle.data.datasourceimpl.local.DummyLocalDataSourceImpl import org.sopt.pingle.data.datasourceimpl.remote.DummyRemoteDataSourceImpl +import org.sopt.pingle.data.datasourceimpl.remote.JoinGroupCodeRemoteDataSourceImpl import org.sopt.pingle.data.datasourceimpl.remote.MapRemoteDataSourceImpl +import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) @@ -26,4 +28,8 @@ abstract class DataSourceModule { @Binds @Singleton abstract fun bindsMapRemoteDataSource(mapRemoteDataSourceImpl: MapRemoteDataSourceImpl): MapRemoteDataSource + + @Binds + @Singleton + abstract fun bindsJoinGroupCodeRemoteDataSource(joinGroupCodeRemoteDataSourceImpl: JoinGroupCodeRemoteDataSourceImpl): JoinGroupCodeRemoteDataSource } diff --git a/app/src/main/java/org/sopt/pingle/di/RepositoryModule.kt b/app/src/main/java/org/sopt/pingle/di/RepositoryModule.kt index 81f14c1e..7f15e286 100644 --- a/app/src/main/java/org/sopt/pingle/di/RepositoryModule.kt +++ b/app/src/main/java/org/sopt/pingle/di/RepositoryModule.kt @@ -4,11 +4,13 @@ import dagger.Binds import dagger.Module import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent -import javax.inject.Singleton import org.sopt.pingle.data.repository.DummyRepositoryImpl +import org.sopt.pingle.data.repository.JoinGroupCodeRepositoryImpl import org.sopt.pingle.data.repository.MapRepositoryImpl import org.sopt.pingle.domain.repository.DummyRepository +import org.sopt.pingle.domain.repository.JoinGroupCodeRepository import org.sopt.pingle.domain.repository.MapRepository +import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) @@ -20,4 +22,8 @@ abstract class RepositoryModule { @Binds @Singleton abstract fun bindsMapRepository(mapRepositoryImpl: MapRepositoryImpl): MapRepository + + @Binds + @Singleton + abstract fun bindsJoinGroupCodeRepository(joinGroupCodeRepositoryImpl: JoinGroupCodeRepositoryImpl): JoinGroupCodeRepository } diff --git a/app/src/main/java/org/sopt/pingle/di/ServiceModule.kt b/app/src/main/java/org/sopt/pingle/di/ServiceModule.kt index 754022b6..f5925a45 100644 --- a/app/src/main/java/org/sopt/pingle/di/ServiceModule.kt +++ b/app/src/main/java/org/sopt/pingle/di/ServiceModule.kt @@ -4,12 +4,12 @@ import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent -import javax.inject.Singleton import org.sopt.pingle.data.service.DummyService +import org.sopt.pingle.data.service.JoinGroupService import org.sopt.pingle.data.service.MapService import org.sopt.pingle.di.qualifier.Pingle import retrofit2.Retrofit -import retrofit2.create +import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) @@ -23,4 +23,9 @@ object ServiceModule { @Singleton fun providesMapService(@Pingle retrofit: Retrofit): MapService = retrofit.create(MapService::class.java) + + @Provides + @Singleton + fun providesJoinGroupService(@Pingle retrofit: Retrofit): JoinGroupService = + retrofit.create(JoinGroupService::class.java) } diff --git a/app/src/main/java/org/sopt/pingle/di/UseCaseModule.kt b/app/src/main/java/org/sopt/pingle/di/UseCaseModule.kt index 0c360644..092b2053 100644 --- a/app/src/main/java/org/sopt/pingle/di/UseCaseModule.kt +++ b/app/src/main/java/org/sopt/pingle/di/UseCaseModule.kt @@ -4,12 +4,14 @@ import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent -import javax.inject.Singleton import org.sopt.pingle.domain.repository.DummyRepository +import org.sopt.pingle.domain.repository.JoinGroupCodeRepository import org.sopt.pingle.domain.repository.MapRepository import org.sopt.pingle.domain.usecase.GetDummyUserListUseCase +import org.sopt.pingle.domain.usecase.GetJoinGroupInfoUseCase import org.sopt.pingle.domain.usecase.GetPinListWithoutFilteringUseCase import org.sopt.pingle.domain.usecase.SetDummyDataUseCase +import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) @@ -28,4 +30,9 @@ class UseCaseModule { @Singleton fun providesGetPinListWithoutFilteringUseCase(mapRepository: MapRepository): GetPinListWithoutFilteringUseCase = GetPinListWithoutFilteringUseCase(mapRepository = mapRepository) + + @Provides + @Singleton + fun providesGetJoinGroupInfoUseCase(joinGroupCodeRepository: JoinGroupCodeRepository): GetJoinGroupInfoUseCase = + GetJoinGroupInfoUseCase(joinGroupCodeRepository = joinGroupCodeRepository) } From 7ca73419b08252e692daf77bf586171cc0b8c6ba Mon Sep 17 00:00:00 2001 From: DoReMinWoo Date: Fri, 12 Jan 2024 00:28:44 +0900 Subject: [PATCH 02/13] =?UTF-8?q?[feat]=20#98=20=EA=B8=B0=EC=A1=B4?= =?UTF-8?q?=EB=8B=A8=EC=B2=B4=EC=9E=85=EC=9E=A5(=EC=B4=88=EB=8C=80?= =?UTF-8?q?=EC=BD=94=EB=93=9C)=20=EA=B7=B8=EB=A3=B9=20=EB=8B=A8=EC=B2=B4?= =?UTF-8?q?=20=EB=94=94=ED=85=8C=EC=9D=BC=20=EC=84=9C=EB=B2=84=ED=86=B5?= =?UTF-8?q?=EC=8B=A0=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../remote/JoinGroupCodeRemoteDataSource.kt | 8 +++ .../JoinGroupCodeRemoteDataSourceImpl.kt | 14 ++++ .../response/ResponseJoinGroupCodeDto.kt | 34 --------- .../response/ResponseJoinGroupInfoDto.kt | 27 +++++++ .../repository/JoinGroupCodeRepositoryImpl.kt | 19 +++++ .../pingle/data/service/JoinGroupService.kt | 19 +++++ ...upCodeEntity.kt => JoinGroupInfoEntity.kt} | 2 +- .../repository/JoinGroupCodeRepository.kt | 8 +++ .../domain/usecase/GetJoinGroupInfoUseCase.kt | 12 ++++ .../ui/joingroup/JoinGroupCodeActivity.kt | 71 ++++++++++++++----- .../ui/joingroup/JoinViewModel.kt | 43 +++++++---- 11 files changed, 189 insertions(+), 68 deletions(-) create mode 100644 app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupCodeRemoteDataSource.kt create mode 100644 app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupCodeRemoteDataSourceImpl.kt delete mode 100644 app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupCodeDto.kt create mode 100644 app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupInfoDto.kt create mode 100644 app/src/main/java/org/sopt/pingle/data/repository/JoinGroupCodeRepositoryImpl.kt create mode 100644 app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt rename app/src/main/java/org/sopt/pingle/domain/model/{JoinGroupCodeEntity.kt => JoinGroupInfoEntity.kt} (83%) create mode 100644 app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupCodeRepository.kt create mode 100644 app/src/main/java/org/sopt/pingle/domain/usecase/GetJoinGroupInfoUseCase.kt diff --git a/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupCodeRemoteDataSource.kt b/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupCodeRemoteDataSource.kt new file mode 100644 index 00000000..740070f3 --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupCodeRemoteDataSource.kt @@ -0,0 +1,8 @@ +package org.sopt.pingle.data.datasource.remote + +import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupInfoDto +import org.sopt.pingle.util.base.BaseResponse + +interface JoinGroupCodeRemoteDataSource { + suspend fun getJoinGroupCodeInfo(teamId: Int): BaseResponse +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupCodeRemoteDataSourceImpl.kt b/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupCodeRemoteDataSourceImpl.kt new file mode 100644 index 00000000..eb566182 --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupCodeRemoteDataSourceImpl.kt @@ -0,0 +1,14 @@ +package org.sopt.pingle.data.datasourceimpl.remote + +import org.sopt.pingle.data.datasource.remote.JoinGroupCodeRemoteDataSource +import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupInfoDto +import org.sopt.pingle.data.service.JoinGroupService +import org.sopt.pingle.util.base.BaseResponse +import javax.inject.Inject + +class JoinGroupCodeRemoteDataSourceImpl @Inject constructor( + private val joinGroupService: JoinGroupService +) : JoinGroupCodeRemoteDataSource { + override suspend fun getJoinGroupCodeInfo(teamId: Int): BaseResponse = + joinGroupService.getJoinGroupDetail(teamId = teamId) +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupCodeDto.kt b/app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupCodeDto.kt deleted file mode 100644 index b5032ef6..00000000 --- a/app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupCodeDto.kt +++ /dev/null @@ -1,34 +0,0 @@ -package org.sopt.pingle.data.model.remote.response - -import kotlinx.serialization.SerialName -import org.sopt.pingle.domain.model.JoinGroupCodeEntity - -data class ResponseJoinGroupCodeDto( - @SerialName("code") - val code: Int, - @SerialName("message") - val message: String, - @SerialName("data") - val data: Data -) { - data class Data( - @SerialName("id") - val id: Int, - @SerialName("keyword") - val keyword: String, - @SerialName("name") - val name: String, - @SerialName("meetingCount") - val meetingCount: Int, - @SerialName("participantCount") - val participantCount: Int - ) { - fun toJoinGroupCodeEntity() = JoinGroupCodeEntity( - id = this.id, - keyword = this.keyword, - name = this.name, - meetingCount = this.meetingCount, - participantCount = this.participantCount - ) - } -} diff --git a/app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupInfoDto.kt b/app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupInfoDto.kt new file mode 100644 index 00000000..608ccf4b --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupInfoDto.kt @@ -0,0 +1,27 @@ +package org.sopt.pingle.data.model.remote.response + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import org.sopt.pingle.domain.model.JoinGroupInfoEntity + +@Serializable +data class ResponseJoinGroupInfoDto( + @SerialName("id") + val id: Int, + @SerialName("keyword") + val keyword: String, + @SerialName("name") + val name: String, + @SerialName("meetingCount") + val meetingCount: Int, + @SerialName("participantCount") + val participantCount: Int +) { + fun toJoinGroupCodeEntity() = JoinGroupInfoEntity( + id = this.id, + keyword = this.keyword, + name = this.name, + meetingCount = this.meetingCount, + participantCount = this.participantCount + ) +} diff --git a/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupCodeRepositoryImpl.kt b/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupCodeRepositoryImpl.kt new file mode 100644 index 00000000..c28f4f5a --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupCodeRepositoryImpl.kt @@ -0,0 +1,19 @@ +package org.sopt.pingle.data.repository + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flow +import org.sopt.pingle.data.datasource.remote.JoinGroupCodeRemoteDataSource +import org.sopt.pingle.domain.model.JoinGroupInfoEntity +import org.sopt.pingle.domain.repository.JoinGroupCodeRepository +import javax.inject.Inject + +class JoinGroupCodeRepositoryImpl @Inject constructor( + private val joinGroupCodeRemoteDataSource: JoinGroupCodeRemoteDataSource +) : JoinGroupCodeRepository { + override fun getJoinGroupInfo(teamId: Int): Flow = flow { + val result = runCatching { + joinGroupCodeRemoteDataSource.getJoinGroupCodeInfo(teamId = teamId).data.toJoinGroupCodeEntity() + } + emit(result.getOrThrow()) + } +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt b/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt new file mode 100644 index 00000000..0bb357f9 --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt @@ -0,0 +1,19 @@ +package org.sopt.pingle.data.service + +import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupInfoDto +import org.sopt.pingle.util.base.BaseResponse +import retrofit2.http.GET +import retrofit2.http.Path + +interface JoinGroupService { + @GET("$VERSION/$TEAMS/{$TEAM_ID}") + suspend fun getJoinGroupDetail( + @Path("$TEAM_ID") teamId: Int + ): BaseResponse + + companion object { + const val VERSION = "v1" + const val TEAMS = "teams" + const val TEAM_ID = "teamId" + } +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/domain/model/JoinGroupCodeEntity.kt b/app/src/main/java/org/sopt/pingle/domain/model/JoinGroupInfoEntity.kt similarity index 83% rename from app/src/main/java/org/sopt/pingle/domain/model/JoinGroupCodeEntity.kt rename to app/src/main/java/org/sopt/pingle/domain/model/JoinGroupInfoEntity.kt index 63283e91..0f2942b7 100644 --- a/app/src/main/java/org/sopt/pingle/domain/model/JoinGroupCodeEntity.kt +++ b/app/src/main/java/org/sopt/pingle/domain/model/JoinGroupInfoEntity.kt @@ -1,6 +1,6 @@ package org.sopt.pingle.domain.model -data class JoinGroupCodeEntity( +data class JoinGroupInfoEntity( val id: Int, val keyword: String, val name: String, diff --git a/app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupCodeRepository.kt b/app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupCodeRepository.kt new file mode 100644 index 00000000..114dc1b3 --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupCodeRepository.kt @@ -0,0 +1,8 @@ +package org.sopt.pingle.domain.repository + +import kotlinx.coroutines.flow.Flow +import org.sopt.pingle.domain.model.JoinGroupInfoEntity + +interface JoinGroupCodeRepository { + fun getJoinGroupInfo(teamId: Int): Flow +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/domain/usecase/GetJoinGroupInfoUseCase.kt b/app/src/main/java/org/sopt/pingle/domain/usecase/GetJoinGroupInfoUseCase.kt new file mode 100644 index 00000000..ce1ada74 --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/domain/usecase/GetJoinGroupInfoUseCase.kt @@ -0,0 +1,12 @@ +package org.sopt.pingle.domain.usecase + +import kotlinx.coroutines.flow.Flow +import org.sopt.pingle.domain.model.JoinGroupInfoEntity +import org.sopt.pingle.domain.repository.JoinGroupCodeRepository + +class GetJoinGroupInfoUseCase( + private val joinGroupCodeRepository: JoinGroupCodeRepository +) { + operator fun invoke(teamId: Int): Flow = + joinGroupCodeRepository.getJoinGroupInfo(teamId = teamId) +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinGroupCodeActivity.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinGroupCodeActivity.kt index 24458ffb..30c1aa70 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinGroupCodeActivity.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinGroupCodeActivity.kt @@ -3,10 +3,16 @@ package org.sopt.pingle.presentation.ui.joingroup import android.content.Intent import android.os.Bundle import androidx.activity.viewModels +import androidx.lifecycle.flowWithLifecycle +import androidx.lifecycle.lifecycleScope import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import org.sopt.pingle.R import org.sopt.pingle.databinding.ActivityJoinGroupCodeBinding import org.sopt.pingle.util.base.BindingActivity +import org.sopt.pingle.util.view.UiState +import timber.log.Timber @AndroidEntryPoint class JoinGroupCodeActivity : @@ -15,16 +21,25 @@ class JoinGroupCodeActivity : override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - binding.joinViewModel = viewModel + initLayout() addListeners() addObservers() + collectData() + } + + private fun initLayout() { + binding.joinViewModel = viewModel + viewModel.getJoinGroupInfo(TEAM_ID) } private fun addListeners() { binding.btnJoinGroupCodeNext.setOnClickListener { - // TODO 초대코드 일치하지 않을 시 - // CustomSnackbar.makeSnackbar(binding.root, getString(R.string.join_group_code_snackbar_message), 97) +// PingleSnackbar.makeSnackbar( +// binding.root, +// getString(R.string.join_group_code_snackbar_message), +// 97 +// ) navigateToJoinGroupSuccess() } @@ -34,34 +49,52 @@ class JoinGroupCodeActivity : } private fun addObservers() { - viewModel.joinGroupData.observe(this) { joinGroupData -> - with(binding) { - tvJoinGroupCodeTag.text = joinGroupData.keyword - tvJoinGroupCodeGroupName.text = joinGroupData.name - tvJoinGroupCodeMeetingCount.text = - getString(R.string.join_group_code_meeting_count, joinGroupData.meetingCount) - tvJoinGroupCodeParticipantCount.text = - getString( - R.string.join_group_code_participant_count, - joinGroupData.participantCount - ) - } - } - viewModel.joinGroupCode.observe(this) { editText -> binding.btnJoinGroupCodeNext.isEnabled = editText.isNotEmpty() } } + private fun collectData() { + viewModel.joinGroupCodeUiState.flowWithLifecycle(lifecycle).onEach { uiState -> + when (uiState) { + is UiState.Success -> { + with(binding) { + tvJoinGroupCodeTag.text = uiState.data.keyword + tvJoinGroupCodeGroupName.text = uiState.data.name + tvJoinGroupCodeMeetingCount.text = + getString( + R.string.join_group_code_meeting_count, + uiState.data.meetingCount + ) + tvJoinGroupCodeParticipantCount.text = + getString( + R.string.join_group_code_participant_count, + uiState.data.participantCount + ) + } + } + + is UiState.Error -> Timber.tag(JOIN_GROUP_CODE_ACTIVITY).d(uiState.message) + + is UiState.Loading -> Timber.tag(JOIN_GROUP_CODE_ACTIVITY).d(LOADING) + + is UiState.Empty -> Timber.tag(JOIN_GROUP_CODE_ACTIVITY).d(EMPTY) + } + }.launchIn(lifecycleScope) + } + private fun navigateToJoinGroupSuccess() { Intent(this, JoinGroupSuccessActivity::class.java).apply { - // TODO 서버통신시 group name 가져와서 전달하기 - putExtra(GROUP_NAME, viewModel.joinGroupData.value?.name) + putExtra(GROUP_NAME, binding.tvJoinGroupCodeGroupName.text) startActivity(this) } } companion object { const val GROUP_NAME = "groupName" + const val TEAM_ID = 1 + const val LOADING = "Loding" + const val EMPTY = "Empty" + const val JOIN_GROUP_CODE_ACTIVITY = "JoinGroupCodeActivity" } } diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt index 57c05cc0..bd0047b7 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt @@ -2,14 +2,24 @@ package org.sopt.pingle.presentation.ui.joingroup import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow -import org.sopt.pingle.domain.model.JoinGroupCodeEntity +import kotlinx.coroutines.launch +import org.sopt.pingle.domain.model.JoinGroupInfoEntity import org.sopt.pingle.domain.model.JoinGroupSearchEntity +import org.sopt.pingle.domain.usecase.GetJoinGroupInfoUseCase +import org.sopt.pingle.util.view.UiState +import javax.inject.Inject -class JoinViewModel : ViewModel() { - private val _joinGroupData = MutableLiveData() - val joinGroupData get() = _joinGroupData +@HiltViewModel +class JoinViewModel @Inject constructor( + private val getJoinGroupInfoUseCase: GetJoinGroupInfoUseCase +) : ViewModel() { + private val _joinGroupCodeUiState = + MutableStateFlow>(UiState.Empty) + val joinGroupCodeUiState get() = _joinGroupCodeUiState.asStateFlow() private var _isJoinGroupCodeBtn = MutableLiveData(false) val isJoinGroupCodeBtn get() = _isJoinGroupCodeBtn @@ -27,9 +37,7 @@ class JoinViewModel : ViewModel() { private var oldPosition = DEFAULT_OLD_POSITION fun updateJoinGroupSearchList(newPosition: Int) { when (oldPosition) { - DEFAULT_OLD_POSITION -> { - setIsSelected(newPosition) - } + DEFAULT_OLD_POSITION -> setIsSelected(newPosition) newPosition -> { setIsSelected(newPosition) @@ -52,16 +60,23 @@ class JoinViewModel : ViewModel() { ) } + fun getJoinGroupInfo(teamId: Int) { + _joinGroupCodeUiState.value = UiState.Loading + viewModelScope.launch { + _joinGroupCodeUiState.value = UiState.Loading + runCatching { + getJoinGroupInfoUseCase.invoke(teamId = teamId).collect { joinGroupInfo -> + _joinGroupCodeUiState.value = UiState.Success(joinGroupInfo) + } + }.onFailure { + _joinGroupCodeUiState.value = UiState.Error(it.message) + } + } + } + private fun getIsSelected(position: Int) = _joinGroupSearchData.value[position].isSelected.get() init { - _joinGroupData.value = JoinGroupCodeEntity( - id = 0, - keyword = "연합동아리", - name = "SOPT", - meetingCount = 10, - participantCount = 200 - ) _joinGroupSearchData.value = listOf( JoinGroupSearchEntity( From 79e2b4b9a260aeeb5b4a609cc8146e45d4fd2751 Mon Sep 17 00:00:00 2001 From: DoReMinWoo Date: Fri, 12 Jan 2024 00:31:21 +0900 Subject: [PATCH 03/13] =?UTF-8?q?[chore]=20#98=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasource/remote/JoinGroupCodeRemoteDataSource.kt | 2 +- .../remote/JoinGroupCodeRemoteDataSourceImpl.kt | 4 ++-- .../pingle/data/repository/JoinGroupCodeRepositoryImpl.kt | 2 +- .../java/org/sopt/pingle/data/service/JoinGroupService.kt | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupCodeRemoteDataSource.kt b/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupCodeRemoteDataSource.kt index 740070f3..ecd6fda0 100644 --- a/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupCodeRemoteDataSource.kt +++ b/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupCodeRemoteDataSource.kt @@ -4,5 +4,5 @@ import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupInfoDto import org.sopt.pingle.util.base.BaseResponse interface JoinGroupCodeRemoteDataSource { - suspend fun getJoinGroupCodeInfo(teamId: Int): BaseResponse + suspend fun getJoinGroupInfo(teamId: Int): BaseResponse } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupCodeRemoteDataSourceImpl.kt b/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupCodeRemoteDataSourceImpl.kt index eb566182..4878090e 100644 --- a/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupCodeRemoteDataSourceImpl.kt +++ b/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupCodeRemoteDataSourceImpl.kt @@ -9,6 +9,6 @@ import javax.inject.Inject class JoinGroupCodeRemoteDataSourceImpl @Inject constructor( private val joinGroupService: JoinGroupService ) : JoinGroupCodeRemoteDataSource { - override suspend fun getJoinGroupCodeInfo(teamId: Int): BaseResponse = - joinGroupService.getJoinGroupDetail(teamId = teamId) + override suspend fun getJoinGroupInfo(teamId: Int): BaseResponse = + joinGroupService.getJoinGroupInfo(teamId = teamId) } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupCodeRepositoryImpl.kt b/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupCodeRepositoryImpl.kt index c28f4f5a..c3ef8a32 100644 --- a/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupCodeRepositoryImpl.kt +++ b/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupCodeRepositoryImpl.kt @@ -12,7 +12,7 @@ class JoinGroupCodeRepositoryImpl @Inject constructor( ) : JoinGroupCodeRepository { override fun getJoinGroupInfo(teamId: Int): Flow = flow { val result = runCatching { - joinGroupCodeRemoteDataSource.getJoinGroupCodeInfo(teamId = teamId).data.toJoinGroupCodeEntity() + joinGroupCodeRemoteDataSource.getJoinGroupInfo(teamId = teamId).data.toJoinGroupCodeEntity() } emit(result.getOrThrow()) } diff --git a/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt b/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt index 0bb357f9..b2986064 100644 --- a/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt +++ b/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt @@ -7,7 +7,7 @@ import retrofit2.http.Path interface JoinGroupService { @GET("$VERSION/$TEAMS/{$TEAM_ID}") - suspend fun getJoinGroupDetail( + suspend fun getJoinGroupInfo( @Path("$TEAM_ID") teamId: Int ): BaseResponse From 16768eb29964c898fcc7167d1b105f6876ba57cb Mon Sep 17 00:00:00 2001 From: DoReMinWoo Date: Fri, 12 Jan 2024 03:11:50 +0900 Subject: [PATCH 04/13] =?UTF-8?q?[add]=20#98=20Hilt=20Module=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/sopt/pingle/di/DataSourceModule.kt | 6 +++--- .../main/java/org/sopt/pingle/di/RepositoryModule.kt | 6 +++--- .../main/java/org/sopt/pingle/di/UseCaseModule.kt | 12 +++++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/sopt/pingle/di/DataSourceModule.kt b/app/src/main/java/org/sopt/pingle/di/DataSourceModule.kt index f76dcef4..aa55b600 100644 --- a/app/src/main/java/org/sopt/pingle/di/DataSourceModule.kt +++ b/app/src/main/java/org/sopt/pingle/di/DataSourceModule.kt @@ -6,11 +6,11 @@ import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import org.sopt.pingle.data.datasource.local.DummyLocalDataSource import org.sopt.pingle.data.datasource.remote.DummyRemoteDataSource -import org.sopt.pingle.data.datasource.remote.JoinGroupCodeRemoteDataSource +import org.sopt.pingle.data.datasource.remote.JoinGroupRemoteDataSource import org.sopt.pingle.data.datasource.remote.MapRemoteDataSource import org.sopt.pingle.data.datasourceimpl.local.DummyLocalDataSourceImpl import org.sopt.pingle.data.datasourceimpl.remote.DummyRemoteDataSourceImpl -import org.sopt.pingle.data.datasourceimpl.remote.JoinGroupCodeRemoteDataSourceImpl +import org.sopt.pingle.data.datasourceimpl.remote.JoinGroupRemoteDataSourceImpl import org.sopt.pingle.data.datasourceimpl.remote.MapRemoteDataSourceImpl import javax.inject.Singleton @@ -31,5 +31,5 @@ abstract class DataSourceModule { @Binds @Singleton - abstract fun bindsJoinGroupCodeRemoteDataSource(joinGroupCodeRemoteDataSourceImpl: JoinGroupCodeRemoteDataSourceImpl): JoinGroupCodeRemoteDataSource + abstract fun bindsJoinGroupRemoteDataSource(joinGroupRemoteDataSourceImpl: JoinGroupRemoteDataSourceImpl): JoinGroupRemoteDataSource } diff --git a/app/src/main/java/org/sopt/pingle/di/RepositoryModule.kt b/app/src/main/java/org/sopt/pingle/di/RepositoryModule.kt index 7f15e286..9834e142 100644 --- a/app/src/main/java/org/sopt/pingle/di/RepositoryModule.kt +++ b/app/src/main/java/org/sopt/pingle/di/RepositoryModule.kt @@ -5,10 +5,10 @@ import dagger.Module import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import org.sopt.pingle.data.repository.DummyRepositoryImpl -import org.sopt.pingle.data.repository.JoinGroupCodeRepositoryImpl +import org.sopt.pingle.data.repository.JoinGroupRepositoryImpl import org.sopt.pingle.data.repository.MapRepositoryImpl import org.sopt.pingle.domain.repository.DummyRepository -import org.sopt.pingle.domain.repository.JoinGroupCodeRepository +import org.sopt.pingle.domain.repository.JoinGroupRepository import org.sopt.pingle.domain.repository.MapRepository import javax.inject.Singleton @@ -25,5 +25,5 @@ abstract class RepositoryModule { @Binds @Singleton - abstract fun bindsJoinGroupCodeRepository(joinGroupCodeRepositoryImpl: JoinGroupCodeRepositoryImpl): JoinGroupCodeRepository + abstract fun bindsJoinGroupRepository(joinGroupRepositoryImpl: JoinGroupRepositoryImpl): JoinGroupRepository } diff --git a/app/src/main/java/org/sopt/pingle/di/UseCaseModule.kt b/app/src/main/java/org/sopt/pingle/di/UseCaseModule.kt index 092b2053..15585eee 100644 --- a/app/src/main/java/org/sopt/pingle/di/UseCaseModule.kt +++ b/app/src/main/java/org/sopt/pingle/di/UseCaseModule.kt @@ -5,11 +5,12 @@ import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import org.sopt.pingle.domain.repository.DummyRepository -import org.sopt.pingle.domain.repository.JoinGroupCodeRepository +import org.sopt.pingle.domain.repository.JoinGroupRepository import org.sopt.pingle.domain.repository.MapRepository import org.sopt.pingle.domain.usecase.GetDummyUserListUseCase import org.sopt.pingle.domain.usecase.GetJoinGroupInfoUseCase import org.sopt.pingle.domain.usecase.GetPinListWithoutFilteringUseCase +import org.sopt.pingle.domain.usecase.PostJoinGroupCodeUseCase import org.sopt.pingle.domain.usecase.SetDummyDataUseCase import javax.inject.Singleton @@ -33,6 +34,11 @@ class UseCaseModule { @Provides @Singleton - fun providesGetJoinGroupInfoUseCase(joinGroupCodeRepository: JoinGroupCodeRepository): GetJoinGroupInfoUseCase = - GetJoinGroupInfoUseCase(joinGroupCodeRepository = joinGroupCodeRepository) + fun providesGetJoinGroupInfoUseCase(joinGroupRepository: JoinGroupRepository): GetJoinGroupInfoUseCase = + GetJoinGroupInfoUseCase(joinGroupRepository = joinGroupRepository) + + @Provides + @Singleton + fun providesPostJoinGroupCodeUseCase(joinGroupRepository: JoinGroupRepository): PostJoinGroupCodeUseCase = + PostJoinGroupCodeUseCase(joinGroupRepository = joinGroupRepository) } From 630059303aa5420da6f62acd27786a700c31482a Mon Sep 17 00:00:00 2001 From: DoReMinWoo Date: Fri, 12 Jan 2024 03:12:09 +0900 Subject: [PATCH 05/13] =?UTF-8?q?[feat]=20#98=20=EC=B4=88=EB=8C=80?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80?= =?UTF-8?q?=EC=82=AC=20=EB=B0=8F=20=EB=8B=A8=EC=B2=B4=EA=B0=80=EC=9E=85=20?= =?UTF-8?q?api=20=EC=84=9C=EB=B2=84=ED=86=B5=EC=8B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 +- .../remote/JoinGroupCodeRemoteDataSource.kt | 8 --- .../remote/JoinGroupRemoteDataSource.kt | 14 +++++ .../JoinGroupCodeRemoteDataSourceImpl.kt | 14 ----- .../remote/JoinGroupRemoteDataSourceImpl.kt | 23 +++++++++ .../org/sopt/pingle/data/mapper/JoinGroup.kt | 8 +++ .../remote/request/RequestJoinGroupCodeDto.kt | 15 ++++++ .../response/ResponseJoinGroupCodeDto.kt | 18 +++++++ .../repository/JoinGroupCodeRepositoryImpl.kt | 19 ------- .../repository/JoinGroupRepositoryImpl.kt | 35 +++++++++++++ .../pingle/data/service/JoinGroupService.kt | 11 ++++ .../model/RequestJoinGroupCodeEntity.kt | 5 ++ .../model/ResponseJoinGroupCodeEntity.kt | 6 +++ .../repository/JoinGroupCodeRepository.kt | 8 --- .../domain/repository/JoinGroupRepository.kt | 14 +++++ .../domain/usecase/GetJoinGroupInfoUseCase.kt | 6 +-- .../usecase/PostJoinGroupCodeUseCase.kt | 16 ++++++ .../ui/joingroup/JoinGroupCodeActivity.kt | 35 ++++++++++--- .../ui/joingroup/JoinViewModel.kt | 51 +++++++++++++------ .../res/layout/activity_join_group_code.xml | 2 +- 20 files changed, 233 insertions(+), 77 deletions(-) delete mode 100644 app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupCodeRemoteDataSource.kt create mode 100644 app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupRemoteDataSource.kt delete mode 100644 app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupCodeRemoteDataSourceImpl.kt create mode 100644 app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt create mode 100644 app/src/main/java/org/sopt/pingle/data/mapper/JoinGroup.kt create mode 100644 app/src/main/java/org/sopt/pingle/data/model/remote/request/RequestJoinGroupCodeDto.kt create mode 100644 app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupCodeDto.kt delete mode 100644 app/src/main/java/org/sopt/pingle/data/repository/JoinGroupCodeRepositoryImpl.kt create mode 100644 app/src/main/java/org/sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt create mode 100644 app/src/main/java/org/sopt/pingle/domain/model/RequestJoinGroupCodeEntity.kt create mode 100644 app/src/main/java/org/sopt/pingle/domain/model/ResponseJoinGroupCodeEntity.kt delete mode 100644 app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupCodeRepository.kt create mode 100644 app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupRepository.kt create mode 100644 app/src/main/java/org/sopt/pingle/domain/usecase/PostJoinGroupCodeUseCase.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f965d7b9..ebc00dc8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -66,7 +66,7 @@ tools:ignore="LockedOrientationActivity" /> -} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupRemoteDataSource.kt b/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupRemoteDataSource.kt new file mode 100644 index 00000000..543e188e --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupRemoteDataSource.kt @@ -0,0 +1,14 @@ +package org.sopt.pingle.data.datasource.remote + +import org.sopt.pingle.data.model.remote.request.RequestJoinGroupCodeDto +import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupCodeDto +import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupInfoDto +import org.sopt.pingle.util.base.BaseResponse + +interface JoinGroupRemoteDataSource { + suspend fun getJoinGroupInfo(teamId: Int): BaseResponse + suspend fun postJoinGroupCode( + teamId: Int, + code: RequestJoinGroupCodeDto + ): BaseResponse +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupCodeRemoteDataSourceImpl.kt b/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupCodeRemoteDataSourceImpl.kt deleted file mode 100644 index 4878090e..00000000 --- a/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupCodeRemoteDataSourceImpl.kt +++ /dev/null @@ -1,14 +0,0 @@ -package org.sopt.pingle.data.datasourceimpl.remote - -import org.sopt.pingle.data.datasource.remote.JoinGroupCodeRemoteDataSource -import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupInfoDto -import org.sopt.pingle.data.service.JoinGroupService -import org.sopt.pingle.util.base.BaseResponse -import javax.inject.Inject - -class JoinGroupCodeRemoteDataSourceImpl @Inject constructor( - private val joinGroupService: JoinGroupService -) : JoinGroupCodeRemoteDataSource { - override suspend fun getJoinGroupInfo(teamId: Int): BaseResponse = - joinGroupService.getJoinGroupInfo(teamId = teamId) -} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt b/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt new file mode 100644 index 00000000..3c5b168a --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt @@ -0,0 +1,23 @@ +package org.sopt.pingle.data.datasourceimpl.remote + +import org.sopt.pingle.data.datasource.remote.JoinGroupRemoteDataSource +import org.sopt.pingle.data.model.remote.request.RequestJoinGroupCodeDto +import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupCodeDto +import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupInfoDto +import org.sopt.pingle.data.service.JoinGroupService +import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity +import org.sopt.pingle.util.base.BaseResponse +import javax.inject.Inject + +class JoinGroupRemoteDataSourceImpl @Inject constructor( + private val joinGroupService: JoinGroupService +) : JoinGroupRemoteDataSource { + override suspend fun getJoinGroupInfo(teamId: Int): BaseResponse = + joinGroupService.getJoinGroupInfo(teamId = teamId) + + override suspend fun postJoinGroupCode( + teamId: Int, + code: RequestJoinGroupCodeDto + ): BaseResponse = + joinGroupService.postJoinGroupCode(teamId = teamId, code = code) +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/data/mapper/JoinGroup.kt b/app/src/main/java/org/sopt/pingle/data/mapper/JoinGroup.kt new file mode 100644 index 00000000..d23e6fee --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/data/mapper/JoinGroup.kt @@ -0,0 +1,8 @@ +package org.sopt.pingle.data.mapper + +import org.sopt.pingle.data.model.remote.request.RequestJoinGroupCodeDto +import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity + +fun RequestJoinGroupCodeEntity.toRequestJoinGroupCode() = RequestJoinGroupCodeDto( + code = code +) diff --git a/app/src/main/java/org/sopt/pingle/data/model/remote/request/RequestJoinGroupCodeDto.kt b/app/src/main/java/org/sopt/pingle/data/model/remote/request/RequestJoinGroupCodeDto.kt new file mode 100644 index 00000000..128a021b --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/data/model/remote/request/RequestJoinGroupCodeDto.kt @@ -0,0 +1,15 @@ +package org.sopt.pingle.data.model.remote.request + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity + +@Serializable +data class RequestJoinGroupCodeDto( + @SerialName("code") + val code: String +) { + fun toRequestJoinGroupCode() = RequestJoinGroupCodeEntity( + code = this.code + ) +} diff --git a/app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupCodeDto.kt b/app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupCodeDto.kt new file mode 100644 index 00000000..d8ea3e3f --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupCodeDto.kt @@ -0,0 +1,18 @@ +package org.sopt.pingle.data.model.remote.response + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import org.sopt.pingle.domain.model.ResponseJoinGroupCodeEntity + +@Serializable +data class ResponseJoinGroupCodeDto( + @SerialName("id") + val id: String, + @SerialName("name") + val name: String +) { + fun toResponseJoinGroupCode() = ResponseJoinGroupCodeEntity( + id = id, + name = name + ) +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupCodeRepositoryImpl.kt b/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupCodeRepositoryImpl.kt deleted file mode 100644 index c3ef8a32..00000000 --- a/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupCodeRepositoryImpl.kt +++ /dev/null @@ -1,19 +0,0 @@ -package org.sopt.pingle.data.repository - -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.flow -import org.sopt.pingle.data.datasource.remote.JoinGroupCodeRemoteDataSource -import org.sopt.pingle.domain.model.JoinGroupInfoEntity -import org.sopt.pingle.domain.repository.JoinGroupCodeRepository -import javax.inject.Inject - -class JoinGroupCodeRepositoryImpl @Inject constructor( - private val joinGroupCodeRemoteDataSource: JoinGroupCodeRemoteDataSource -) : JoinGroupCodeRepository { - override fun getJoinGroupInfo(teamId: Int): Flow = flow { - val result = runCatching { - joinGroupCodeRemoteDataSource.getJoinGroupInfo(teamId = teamId).data.toJoinGroupCodeEntity() - } - emit(result.getOrThrow()) - } -} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt b/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt new file mode 100644 index 00000000..7e1c44f3 --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt @@ -0,0 +1,35 @@ +package org.sopt.pingle.data.repository + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flow +import org.sopt.pingle.data.datasource.remote.JoinGroupRemoteDataSource +import org.sopt.pingle.data.mapper.toRequestJoinGroupCode +import org.sopt.pingle.domain.model.JoinGroupInfoEntity +import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity +import org.sopt.pingle.domain.model.ResponseJoinGroupCodeEntity +import org.sopt.pingle.domain.repository.JoinGroupRepository +import javax.inject.Inject + +class JoinGroupRepositoryImpl @Inject constructor( + private val joinGroupRemoteDataSource: JoinGroupRemoteDataSource +) : JoinGroupRepository { + override fun getJoinGroupInfo(teamId: Int): Flow = flow { + val result = runCatching { + joinGroupRemoteDataSource.getJoinGroupInfo(teamId = teamId).data.toJoinGroupCodeEntity() + } + emit(result.getOrThrow()) + } + + override fun postJoinGroupCode( + teamId: Int, + code: RequestJoinGroupCodeEntity + ): Flow = flow { + val result = runCatching { + joinGroupRemoteDataSource.postJoinGroupCode( + teamId = teamId, + code = code.toRequestJoinGroupCode() + ).data.toResponseJoinGroupCode() + } + emit(result.getOrThrow()) + } +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt b/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt index b2986064..eeafd546 100644 --- a/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt +++ b/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt @@ -1,8 +1,12 @@ package org.sopt.pingle.data.service +import org.sopt.pingle.data.model.remote.request.RequestJoinGroupCodeDto +import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupCodeDto import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupInfoDto import org.sopt.pingle.util.base.BaseResponse +import retrofit2.http.Body import retrofit2.http.GET +import retrofit2.http.POST import retrofit2.http.Path interface JoinGroupService { @@ -11,9 +15,16 @@ interface JoinGroupService { @Path("$TEAM_ID") teamId: Int ): BaseResponse + @POST("$VERSION/$TEAMS/{$TEAM_ID}/$REGISTER") + suspend fun postJoinGroupCode( + @Path("$TEAM_ID") teamId: Int, + @Body code: RequestJoinGroupCodeDto + ): BaseResponse + companion object { const val VERSION = "v1" const val TEAMS = "teams" const val TEAM_ID = "teamId" + const val REGISTER = "register" } } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/domain/model/RequestJoinGroupCodeEntity.kt b/app/src/main/java/org/sopt/pingle/domain/model/RequestJoinGroupCodeEntity.kt new file mode 100644 index 00000000..e62fc4ec --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/domain/model/RequestJoinGroupCodeEntity.kt @@ -0,0 +1,5 @@ +package org.sopt.pingle.domain.model + +class RequestJoinGroupCodeEntity( + val code: String +) \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/domain/model/ResponseJoinGroupCodeEntity.kt b/app/src/main/java/org/sopt/pingle/domain/model/ResponseJoinGroupCodeEntity.kt new file mode 100644 index 00000000..bfab89bc --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/domain/model/ResponseJoinGroupCodeEntity.kt @@ -0,0 +1,6 @@ +package org.sopt.pingle.domain.model + +data class ResponseJoinGroupCodeEntity( + val id: String, + val name: String +) \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupCodeRepository.kt b/app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupCodeRepository.kt deleted file mode 100644 index 114dc1b3..00000000 --- a/app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupCodeRepository.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.sopt.pingle.domain.repository - -import kotlinx.coroutines.flow.Flow -import org.sopt.pingle.domain.model.JoinGroupInfoEntity - -interface JoinGroupCodeRepository { - fun getJoinGroupInfo(teamId: Int): Flow -} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupRepository.kt b/app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupRepository.kt new file mode 100644 index 00000000..5d05ad01 --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupRepository.kt @@ -0,0 +1,14 @@ +package org.sopt.pingle.domain.repository + +import kotlinx.coroutines.flow.Flow +import org.sopt.pingle.domain.model.JoinGroupInfoEntity +import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity +import org.sopt.pingle.domain.model.ResponseJoinGroupCodeEntity + +interface JoinGroupRepository { + fun getJoinGroupInfo(teamId: Int): Flow + fun postJoinGroupCode( + teamId: Int, + code: RequestJoinGroupCodeEntity + ): Flow +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/domain/usecase/GetJoinGroupInfoUseCase.kt b/app/src/main/java/org/sopt/pingle/domain/usecase/GetJoinGroupInfoUseCase.kt index ce1ada74..a4fffd62 100644 --- a/app/src/main/java/org/sopt/pingle/domain/usecase/GetJoinGroupInfoUseCase.kt +++ b/app/src/main/java/org/sopt/pingle/domain/usecase/GetJoinGroupInfoUseCase.kt @@ -2,11 +2,11 @@ package org.sopt.pingle.domain.usecase import kotlinx.coroutines.flow.Flow import org.sopt.pingle.domain.model.JoinGroupInfoEntity -import org.sopt.pingle.domain.repository.JoinGroupCodeRepository +import org.sopt.pingle.domain.repository.JoinGroupRepository class GetJoinGroupInfoUseCase( - private val joinGroupCodeRepository: JoinGroupCodeRepository + private val joinGroupRepository: JoinGroupRepository ) { operator fun invoke(teamId: Int): Flow = - joinGroupCodeRepository.getJoinGroupInfo(teamId = teamId) + joinGroupRepository.getJoinGroupInfo(teamId = teamId) } \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/domain/usecase/PostJoinGroupCodeUseCase.kt b/app/src/main/java/org/sopt/pingle/domain/usecase/PostJoinGroupCodeUseCase.kt new file mode 100644 index 00000000..a74e2d46 --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/domain/usecase/PostJoinGroupCodeUseCase.kt @@ -0,0 +1,16 @@ +package org.sopt.pingle.domain.usecase + +import kotlinx.coroutines.flow.Flow +import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity +import org.sopt.pingle.domain.model.ResponseJoinGroupCodeEntity +import org.sopt.pingle.domain.repository.JoinGroupRepository + +class PostJoinGroupCodeUseCase( + private val joinGroupRepository: JoinGroupRepository +) { + operator fun invoke( + teamId: Int, + code: RequestJoinGroupCodeEntity + ): Flow = + joinGroupRepository.postJoinGroupCode(teamId = teamId, code = code) +} \ No newline at end of file diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinGroupCodeActivity.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinGroupCodeActivity.kt index 30c1aa70..89b2b760 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinGroupCodeActivity.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinGroupCodeActivity.kt @@ -10,7 +10,9 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import org.sopt.pingle.R import org.sopt.pingle.databinding.ActivityJoinGroupCodeBinding +import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity import org.sopt.pingle.util.base.BindingActivity +import org.sopt.pingle.util.component.PingleSnackbar import org.sopt.pingle.util.view.UiState import timber.log.Timber @@ -35,12 +37,10 @@ class JoinGroupCodeActivity : private fun addListeners() { binding.btnJoinGroupCodeNext.setOnClickListener { -// PingleSnackbar.makeSnackbar( -// binding.root, -// getString(R.string.join_group_code_snackbar_message), -// 97 -// ) - navigateToJoinGroupSuccess() + viewModel.postJoinGroupCode( + TEAM_ID, + RequestJoinGroupCodeEntity(viewModel.joinGroupCodeEditText.value.toString()) + ) } binding.includeJoinGroupCodeTopbar.ivAllTopbarArrowWithTitleArrowLeft.setOnClickListener { @@ -49,13 +49,13 @@ class JoinGroupCodeActivity : } private fun addObservers() { - viewModel.joinGroupCode.observe(this) { editText -> + viewModel.joinGroupCodeEditText.observe(this) { editText -> binding.btnJoinGroupCodeNext.isEnabled = editText.isNotEmpty() } } private fun collectData() { - viewModel.joinGroupCodeUiState.flowWithLifecycle(lifecycle).onEach { uiState -> + viewModel.joinGroupCodeState.flowWithLifecycle(lifecycle).onEach { uiState -> when (uiState) { is UiState.Success -> { with(binding) { @@ -81,6 +81,25 @@ class JoinGroupCodeActivity : is UiState.Empty -> Timber.tag(JOIN_GROUP_CODE_ACTIVITY).d(EMPTY) } }.launchIn(lifecycleScope) + + viewModel.joinGroupCode.flowWithLifecycle(lifecycle).onEach { uiState -> + when (uiState) { + is UiState.Success -> navigateToJoinGroupSuccess() + + is UiState.Error -> { + PingleSnackbar.makeSnackbar( + binding.root, + getString(R.string.join_group_code_snackbar_message), + 97 + ) + } + + is UiState.Loading -> Timber.tag(JOIN_GROUP_CODE_ACTIVITY).d(LOADING) + + is UiState.Empty -> Timber.tag(JOIN_GROUP_CODE_ACTIVITY).d(EMPTY) + } + + }.launchIn(lifecycleScope) } private fun navigateToJoinGroupSuccess() { diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt index bd0047b7..4334576c 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt @@ -9,28 +9,36 @@ import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import org.sopt.pingle.domain.model.JoinGroupInfoEntity import org.sopt.pingle.domain.model.JoinGroupSearchEntity +import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity +import org.sopt.pingle.domain.model.ResponseJoinGroupCodeEntity import org.sopt.pingle.domain.usecase.GetJoinGroupInfoUseCase +import org.sopt.pingle.domain.usecase.PostJoinGroupCodeUseCase import org.sopt.pingle.util.view.UiState import javax.inject.Inject @HiltViewModel class JoinViewModel @Inject constructor( - private val getJoinGroupInfoUseCase: GetJoinGroupInfoUseCase + private val getJoinGroupInfoUseCase: GetJoinGroupInfoUseCase, + private val postJoinGroupCodeUseCase: PostJoinGroupCodeUseCase ) : ViewModel() { - private val _joinGroupCodeUiState = + private val _selectedJoinGroup = MutableStateFlow(null) + val selectedJoinGroup get() = _selectedJoinGroup.asStateFlow() + + private val _joinGroupSearchData = MutableStateFlow>(emptyList()) + val joinGroupSearchData get() = _joinGroupSearchData + + private val _joinGroupCodeState = MutableStateFlow>(UiState.Empty) - val joinGroupCodeUiState get() = _joinGroupCodeUiState.asStateFlow() + val joinGroupCodeState get() = _joinGroupCodeState.asStateFlow() private var _isJoinGroupCodeBtn = MutableLiveData(false) val isJoinGroupCodeBtn get() = _isJoinGroupCodeBtn - val joinGroupCode = MutableLiveData() + private var _joinGroupCode = + MutableStateFlow>(UiState.Empty) + val joinGroupCode get() = _joinGroupCode - private val _joinGroupSearchData = MutableStateFlow>(emptyList()) - val joinGroupSearchData get() = _joinGroupSearchData - - private val _selectedJoinGroup = MutableStateFlow(null) - val selectedJoinGroup get() = _selectedJoinGroup.asStateFlow() + val joinGroupCodeEditText = MutableLiveData() val joinGroupSearchEditText = MutableLiveData("") @@ -60,24 +68,37 @@ class JoinViewModel @Inject constructor( ) } + private fun getIsSelected(position: Int) = _joinGroupSearchData.value[position].isSelected.get() + fun getJoinGroupInfo(teamId: Int) { - _joinGroupCodeUiState.value = UiState.Loading + _joinGroupCodeState.value = UiState.Loading viewModelScope.launch { - _joinGroupCodeUiState.value = UiState.Loading + _joinGroupCodeState.value = UiState.Loading runCatching { getJoinGroupInfoUseCase.invoke(teamId = teamId).collect { joinGroupInfo -> - _joinGroupCodeUiState.value = UiState.Success(joinGroupInfo) + _joinGroupCodeState.value = UiState.Success(joinGroupInfo) } }.onFailure { - _joinGroupCodeUiState.value = UiState.Error(it.message) + _joinGroupCodeState.value = UiState.Error(it.message) } } } - private fun getIsSelected(position: Int) = _joinGroupSearchData.value[position].isSelected.get() + fun postJoinGroupCode(teamId: Int, code: RequestJoinGroupCodeEntity) { + _joinGroupCode.value = UiState.Loading + viewModelScope.launch { + runCatching { + postJoinGroupCodeUseCase.invoke(teamId = teamId, code = code) + .collect { joinGroupCode -> + _joinGroupCode.value = UiState.Success(joinGroupCode) + } + }.onFailure { + _joinGroupCode.value = UiState.Error(it.message) + } + } + } init { - _joinGroupSearchData.value = listOf( JoinGroupSearchEntity( id = 0, diff --git a/app/src/main/res/layout/activity_join_group_code.xml b/app/src/main/res/layout/activity_join_group_code.xml index 0700882c..a7459be6 100644 --- a/app/src/main/res/layout/activity_join_group_code.xml +++ b/app/src/main/res/layout/activity_join_group_code.xml @@ -163,7 +163,7 @@ Date: Fri, 12 Jan 2024 03:16:58 +0900 Subject: [PATCH 06/13] =?UTF-8?q?[chore]=20#98=20ktlint=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasource/remote/JoinGroupRemoteDataSource.kt | 2 +- .../datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt | 5 ++--- .../data/model/remote/response/ResponseJoinGroupCodeDto.kt | 2 +- .../sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt | 4 ++-- .../java/org/sopt/pingle/data/service/JoinGroupService.kt | 2 +- app/src/main/java/org/sopt/pingle/di/DataSourceModule.kt | 2 +- app/src/main/java/org/sopt/pingle/di/RepositoryModule.kt | 2 +- app/src/main/java/org/sopt/pingle/di/UseCaseModule.kt | 4 ++-- .../sopt/pingle/domain/model/RequestJoinGroupCodeEntity.kt | 2 +- .../sopt/pingle/domain/model/ResponseJoinGroupCodeEntity.kt | 2 +- .../org/sopt/pingle/domain/repository/JoinGroupRepository.kt | 2 +- .../sopt/pingle/domain/usecase/GetJoinGroupInfoUseCase.kt | 2 +- .../sopt/pingle/domain/usecase/PostJoinGroupCodeUseCase.kt | 2 +- .../presentation/ui/joingroup/JoinGroupCodeActivity.kt | 1 - .../sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt | 2 +- 15 files changed, 17 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupRemoteDataSource.kt b/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupRemoteDataSource.kt index 543e188e..efe4108f 100644 --- a/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupRemoteDataSource.kt +++ b/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupRemoteDataSource.kt @@ -11,4 +11,4 @@ interface JoinGroupRemoteDataSource { teamId: Int, code: RequestJoinGroupCodeDto ): BaseResponse -} \ No newline at end of file +} diff --git a/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt b/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt index 3c5b168a..29c1c4e3 100644 --- a/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt +++ b/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt @@ -1,13 +1,12 @@ package org.sopt.pingle.data.datasourceimpl.remote +import javax.inject.Inject import org.sopt.pingle.data.datasource.remote.JoinGroupRemoteDataSource import org.sopt.pingle.data.model.remote.request.RequestJoinGroupCodeDto import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupCodeDto import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupInfoDto import org.sopt.pingle.data.service.JoinGroupService -import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity import org.sopt.pingle.util.base.BaseResponse -import javax.inject.Inject class JoinGroupRemoteDataSourceImpl @Inject constructor( private val joinGroupService: JoinGroupService @@ -20,4 +19,4 @@ class JoinGroupRemoteDataSourceImpl @Inject constructor( code: RequestJoinGroupCodeDto ): BaseResponse = joinGroupService.postJoinGroupCode(teamId = teamId, code = code) -} \ No newline at end of file +} diff --git a/app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupCodeDto.kt b/app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupCodeDto.kt index d8ea3e3f..5374b7ed 100644 --- a/app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupCodeDto.kt +++ b/app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupCodeDto.kt @@ -15,4 +15,4 @@ data class ResponseJoinGroupCodeDto( id = id, name = name ) -} \ No newline at end of file +} diff --git a/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt b/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt index 7e1c44f3..1dfe8c53 100644 --- a/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt +++ b/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt @@ -1,5 +1,6 @@ package org.sopt.pingle.data.repository +import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import org.sopt.pingle.data.datasource.remote.JoinGroupRemoteDataSource @@ -8,7 +9,6 @@ import org.sopt.pingle.domain.model.JoinGroupInfoEntity import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity import org.sopt.pingle.domain.model.ResponseJoinGroupCodeEntity import org.sopt.pingle.domain.repository.JoinGroupRepository -import javax.inject.Inject class JoinGroupRepositoryImpl @Inject constructor( private val joinGroupRemoteDataSource: JoinGroupRemoteDataSource @@ -32,4 +32,4 @@ class JoinGroupRepositoryImpl @Inject constructor( } emit(result.getOrThrow()) } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt b/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt index eeafd546..e4927115 100644 --- a/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt +++ b/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt @@ -27,4 +27,4 @@ interface JoinGroupService { const val TEAM_ID = "teamId" const val REGISTER = "register" } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/sopt/pingle/di/DataSourceModule.kt b/app/src/main/java/org/sopt/pingle/di/DataSourceModule.kt index a811ce2d..98be5212 100644 --- a/app/src/main/java/org/sopt/pingle/di/DataSourceModule.kt +++ b/app/src/main/java/org/sopt/pingle/di/DataSourceModule.kt @@ -4,6 +4,7 @@ import dagger.Binds import dagger.Module import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton import org.sopt.pingle.data.datasource.local.DummyLocalDataSource import org.sopt.pingle.data.datasource.local.PingleLocalDataSource import org.sopt.pingle.data.datasource.remote.AuthRemoteDataSource @@ -20,7 +21,6 @@ import org.sopt.pingle.data.datasourceimpl.remote.JoinGroupRemoteDataSourceImpl import org.sopt.pingle.data.datasourceimpl.remote.MapRemoteDataSourceImpl import org.sopt.pingle.data.datasourceimpl.remote.PingleRemoteDataSourceImpl import org.sopt.pingle.data.datasourceimpl.remote.PlanRemoteDataSourceImpl -import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) diff --git a/app/src/main/java/org/sopt/pingle/di/RepositoryModule.kt b/app/src/main/java/org/sopt/pingle/di/RepositoryModule.kt index 3620ba14..e379596e 100644 --- a/app/src/main/java/org/sopt/pingle/di/RepositoryModule.kt +++ b/app/src/main/java/org/sopt/pingle/di/RepositoryModule.kt @@ -4,6 +4,7 @@ import dagger.Binds import dagger.Module import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton import org.sopt.pingle.data.repository.AuthRepositoryImpl import org.sopt.pingle.data.repository.DummyRepositoryImpl import org.sopt.pingle.data.repository.JoinGroupRepositoryImpl @@ -16,7 +17,6 @@ import org.sopt.pingle.domain.repository.JoinGroupRepository import org.sopt.pingle.domain.repository.MapRepository import org.sopt.pingle.domain.repository.PingleRepository import org.sopt.pingle.domain.repository.PlanRepository -import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) diff --git a/app/src/main/java/org/sopt/pingle/di/UseCaseModule.kt b/app/src/main/java/org/sopt/pingle/di/UseCaseModule.kt index bd4ddb3c..f828421b 100644 --- a/app/src/main/java/org/sopt/pingle/di/UseCaseModule.kt +++ b/app/src/main/java/org/sopt/pingle/di/UseCaseModule.kt @@ -4,6 +4,7 @@ import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton import org.sopt.pingle.domain.repository.DummyRepository import org.sopt.pingle.domain.repository.JoinGroupRepository import org.sopt.pingle.domain.repository.MapRepository @@ -14,11 +15,10 @@ import org.sopt.pingle.domain.usecase.GetJoinGroupInfoUseCase import org.sopt.pingle.domain.usecase.GetPinListWithoutFilteringUseCase import org.sopt.pingle.domain.usecase.GetPingleListUseCase import org.sopt.pingle.domain.usecase.GetPlanLocationListUseCase +import org.sopt.pingle.domain.usecase.PostJoinGroupCodeUseCase import org.sopt.pingle.domain.usecase.PostPingleCancelUseCase import org.sopt.pingle.domain.usecase.PostPingleJoinUseCase -import org.sopt.pingle.domain.usecase.PostJoinGroupCodeUseCase import org.sopt.pingle.domain.usecase.SetDummyDataUseCase -import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) diff --git a/app/src/main/java/org/sopt/pingle/domain/model/RequestJoinGroupCodeEntity.kt b/app/src/main/java/org/sopt/pingle/domain/model/RequestJoinGroupCodeEntity.kt index e62fc4ec..4e925d57 100644 --- a/app/src/main/java/org/sopt/pingle/domain/model/RequestJoinGroupCodeEntity.kt +++ b/app/src/main/java/org/sopt/pingle/domain/model/RequestJoinGroupCodeEntity.kt @@ -2,4 +2,4 @@ package org.sopt.pingle.domain.model class RequestJoinGroupCodeEntity( val code: String -) \ No newline at end of file +) diff --git a/app/src/main/java/org/sopt/pingle/domain/model/ResponseJoinGroupCodeEntity.kt b/app/src/main/java/org/sopt/pingle/domain/model/ResponseJoinGroupCodeEntity.kt index bfab89bc..0f656ff3 100644 --- a/app/src/main/java/org/sopt/pingle/domain/model/ResponseJoinGroupCodeEntity.kt +++ b/app/src/main/java/org/sopt/pingle/domain/model/ResponseJoinGroupCodeEntity.kt @@ -3,4 +3,4 @@ package org.sopt.pingle.domain.model data class ResponseJoinGroupCodeEntity( val id: String, val name: String -) \ No newline at end of file +) diff --git a/app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupRepository.kt b/app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupRepository.kt index 5d05ad01..a20b8a64 100644 --- a/app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupRepository.kt +++ b/app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupRepository.kt @@ -11,4 +11,4 @@ interface JoinGroupRepository { teamId: Int, code: RequestJoinGroupCodeEntity ): Flow -} \ No newline at end of file +} diff --git a/app/src/main/java/org/sopt/pingle/domain/usecase/GetJoinGroupInfoUseCase.kt b/app/src/main/java/org/sopt/pingle/domain/usecase/GetJoinGroupInfoUseCase.kt index a4fffd62..dd5aee85 100644 --- a/app/src/main/java/org/sopt/pingle/domain/usecase/GetJoinGroupInfoUseCase.kt +++ b/app/src/main/java/org/sopt/pingle/domain/usecase/GetJoinGroupInfoUseCase.kt @@ -9,4 +9,4 @@ class GetJoinGroupInfoUseCase( ) { operator fun invoke(teamId: Int): Flow = joinGroupRepository.getJoinGroupInfo(teamId = teamId) -} \ No newline at end of file +} diff --git a/app/src/main/java/org/sopt/pingle/domain/usecase/PostJoinGroupCodeUseCase.kt b/app/src/main/java/org/sopt/pingle/domain/usecase/PostJoinGroupCodeUseCase.kt index a74e2d46..ff19814e 100644 --- a/app/src/main/java/org/sopt/pingle/domain/usecase/PostJoinGroupCodeUseCase.kt +++ b/app/src/main/java/org/sopt/pingle/domain/usecase/PostJoinGroupCodeUseCase.kt @@ -13,4 +13,4 @@ class PostJoinGroupCodeUseCase( code: RequestJoinGroupCodeEntity ): Flow = joinGroupRepository.postJoinGroupCode(teamId = teamId, code = code) -} \ No newline at end of file +} diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinGroupCodeActivity.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinGroupCodeActivity.kt index 89b2b760..ef51f15f 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinGroupCodeActivity.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinGroupCodeActivity.kt @@ -98,7 +98,6 @@ class JoinGroupCodeActivity : is UiState.Empty -> Timber.tag(JOIN_GROUP_CODE_ACTIVITY).d(EMPTY) } - }.launchIn(lifecycleScope) } diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt index 4334576c..93e0e78e 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt @@ -4,6 +4,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch @@ -14,7 +15,6 @@ import org.sopt.pingle.domain.model.ResponseJoinGroupCodeEntity import org.sopt.pingle.domain.usecase.GetJoinGroupInfoUseCase import org.sopt.pingle.domain.usecase.PostJoinGroupCodeUseCase import org.sopt.pingle.util.view.UiState -import javax.inject.Inject @HiltViewModel class JoinViewModel @Inject constructor( From ffeadc2e6b273e6bd139cc29ed6ac78b0f814ba9 Mon Sep 17 00:00:00 2001 From: DoReMinWoo Date: Fri, 12 Jan 2024 03:30:21 +0900 Subject: [PATCH 07/13] =?UTF-8?q?[feat]=20#98=20=EC=89=90=EC=96=B4?= =?UTF-8?q?=EB=93=9C=ED=94=84=EB=A6=AC=ED=8D=BC=EB=9F=B0=EC=8A=A4=EC=97=90?= =?UTF-8?q?=20groupId,=20groupName=20=EC=A0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasource/local/PingleLocalDataSource.kt | 2 ++ .../datasourceimpl/local/PingleLocalDataSourceImpl.kt | 10 ++++++++++ .../model/remote/response/ResponseJoinGroupCodeDto.kt | 2 +- .../domain/model/ResponseJoinGroupCodeEntity.kt | 2 +- .../pingle/presentation/ui/joingroup/JoinViewModel.kt | 11 ++++++++++- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/sopt/pingle/data/datasource/local/PingleLocalDataSource.kt b/app/src/main/java/org/sopt/pingle/data/datasource/local/PingleLocalDataSource.kt index 785b3440..b83ed88f 100644 --- a/app/src/main/java/org/sopt/pingle/data/datasource/local/PingleLocalDataSource.kt +++ b/app/src/main/java/org/sopt/pingle/data/datasource/local/PingleLocalDataSource.kt @@ -5,5 +5,7 @@ interface PingleLocalDataSource { var userName: String var accessToken: String var refreshToken: String + var groupId: Int + var groupName: String fun clear(): Unit } diff --git a/app/src/main/java/org/sopt/pingle/data/datasourceimpl/local/PingleLocalDataSourceImpl.kt b/app/src/main/java/org/sopt/pingle/data/datasourceimpl/local/PingleLocalDataSourceImpl.kt index d08a0f80..37b9e3bd 100644 --- a/app/src/main/java/org/sopt/pingle/data/datasourceimpl/local/PingleLocalDataSourceImpl.kt +++ b/app/src/main/java/org/sopt/pingle/data/datasourceimpl/local/PingleLocalDataSourceImpl.kt @@ -47,6 +47,14 @@ class PingleLocalDataSourceImpl @Inject constructor( get() = pref.getString(REFRESH_TOKEN, "") ?: "" set(value) = pref.edit { putString(REFRESH_TOKEN, value) } + override var groupId: Int + get() = pref.getInt(GROUP_ID, -1) + set(value) = pref.edit { putInt(GROUP_ID, value) } + + override var groupName: String + get() = pref.getString(GROUP_NAME, "") ?: "" + set(value) = pref.edit { putString(GROUP_NAME, value) } + override fun clear() { pref.edit { clear() @@ -59,5 +67,7 @@ class PingleLocalDataSourceImpl @Inject constructor( const val USER_NAME = "UserName" const val ACCESS_TOKEN = "AccessToken" const val REFRESH_TOKEN = "RefreshToken" + const val GROUP_ID = "GroupId" + const val GROUP_NAME = "GroupName" } } diff --git a/app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupCodeDto.kt b/app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupCodeDto.kt index 5374b7ed..d6c8523e 100644 --- a/app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupCodeDto.kt +++ b/app/src/main/java/org/sopt/pingle/data/model/remote/response/ResponseJoinGroupCodeDto.kt @@ -7,7 +7,7 @@ import org.sopt.pingle.domain.model.ResponseJoinGroupCodeEntity @Serializable data class ResponseJoinGroupCodeDto( @SerialName("id") - val id: String, + val id: Int, @SerialName("name") val name: String ) { diff --git a/app/src/main/java/org/sopt/pingle/domain/model/ResponseJoinGroupCodeEntity.kt b/app/src/main/java/org/sopt/pingle/domain/model/ResponseJoinGroupCodeEntity.kt index 0f656ff3..8f85e140 100644 --- a/app/src/main/java/org/sopt/pingle/domain/model/ResponseJoinGroupCodeEntity.kt +++ b/app/src/main/java/org/sopt/pingle/domain/model/ResponseJoinGroupCodeEntity.kt @@ -1,6 +1,6 @@ package org.sopt.pingle.domain.model data class ResponseJoinGroupCodeEntity( - val id: String, + val id: Int, val name: String ) diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt index 93e0e78e..965fff91 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt @@ -1,13 +1,14 @@ package org.sopt.pingle.presentation.ui.joingroup +import android.util.Log import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel -import javax.inject.Inject import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch +import org.sopt.pingle.data.datasource.local.PingleLocalDataSource import org.sopt.pingle.domain.model.JoinGroupInfoEntity import org.sopt.pingle.domain.model.JoinGroupSearchEntity import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity @@ -15,9 +16,11 @@ import org.sopt.pingle.domain.model.ResponseJoinGroupCodeEntity import org.sopt.pingle.domain.usecase.GetJoinGroupInfoUseCase import org.sopt.pingle.domain.usecase.PostJoinGroupCodeUseCase import org.sopt.pingle.util.view.UiState +import javax.inject.Inject @HiltViewModel class JoinViewModel @Inject constructor( + private val localStorage: PingleLocalDataSource, private val getJoinGroupInfoUseCase: GetJoinGroupInfoUseCase, private val postJoinGroupCodeUseCase: PostJoinGroupCodeUseCase ) : ViewModel() { @@ -91,6 +94,12 @@ class JoinViewModel @Inject constructor( postJoinGroupCodeUseCase.invoke(teamId = teamId, code = code) .collect { joinGroupCode -> _joinGroupCode.value = UiState.Success(joinGroupCode) + with(localStorage) { + groupId = joinGroupCode.id + groupName = joinGroupCode.name + Log.d("ㅁㅇ", groupId.toString()) + Log.d("ㅁㅇ", groupName) + } } }.onFailure { _joinGroupCode.value = UiState.Error(it.message) From 6fbc26e82b4b090a45b3a0e582cf56b40e563db1 Mon Sep 17 00:00:00 2001 From: DoReMinWoo Date: Fri, 12 Jan 2024 03:34:37 +0900 Subject: [PATCH 08/13] =?UTF-8?q?[chore]=20#98=20Log=20=EC=82=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt index 965fff91..83bb4dcd 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt @@ -1,10 +1,10 @@ package org.sopt.pingle.presentation.ui.joingroup -import android.util.Log import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch @@ -16,7 +16,6 @@ import org.sopt.pingle.domain.model.ResponseJoinGroupCodeEntity import org.sopt.pingle.domain.usecase.GetJoinGroupInfoUseCase import org.sopt.pingle.domain.usecase.PostJoinGroupCodeUseCase import org.sopt.pingle.util.view.UiState -import javax.inject.Inject @HiltViewModel class JoinViewModel @Inject constructor( @@ -97,8 +96,6 @@ class JoinViewModel @Inject constructor( with(localStorage) { groupId = joinGroupCode.id groupName = joinGroupCode.name - Log.d("ㅁㅇ", groupId.toString()) - Log.d("ㅁㅇ", groupName) } } }.onFailure { From e00794d27aafad35438a99d126f5e707524b4dc7 Mon Sep 17 00:00:00 2001 From: DoReMinWoo Date: Fri, 12 Jan 2024 03:34:37 +0900 Subject: [PATCH 09/13] =?UTF-8?q?[chore]=20#98=20Log=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt index 965fff91..83bb4dcd 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt @@ -1,10 +1,10 @@ package org.sopt.pingle.presentation.ui.joingroup -import android.util.Log import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch @@ -16,7 +16,6 @@ import org.sopt.pingle.domain.model.ResponseJoinGroupCodeEntity import org.sopt.pingle.domain.usecase.GetJoinGroupInfoUseCase import org.sopt.pingle.domain.usecase.PostJoinGroupCodeUseCase import org.sopt.pingle.util.view.UiState -import javax.inject.Inject @HiltViewModel class JoinViewModel @Inject constructor( @@ -97,8 +96,6 @@ class JoinViewModel @Inject constructor( with(localStorage) { groupId = joinGroupCode.id groupName = joinGroupCode.name - Log.d("ㅁㅇ", groupId.toString()) - Log.d("ㅁㅇ", groupName) } } }.onFailure { From e4db7be6e7d6674eb9bfc05965869a809cf59831 Mon Sep 17 00:00:00 2001 From: DoReMinWoo Date: Fri, 12 Jan 2024 15:58:55 +0900 Subject: [PATCH 10/13] =?UTF-8?q?[chore]=20#98=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 +- ...kt => RequestJoinGroupCodeEntityMapper.kt} | 0 .../remote/request/RequestJoinGroupCodeDto.kt | 7 +---- .../pingle/data/service/JoinGroupService.kt | 2 +- .../ui/joingroup/JoinGroupCodeActivity.kt | 13 +++++---- .../ui/joingroup/JoinViewModel.kt | 28 +++++++++---------- 6 files changed, 24 insertions(+), 28 deletions(-) rename app/src/main/java/org/sopt/pingle/data/mapper/{JoinGroup.kt => RequestJoinGroupCodeEntityMapper.kt} (100%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 70c5687d..b346f57e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -67,7 +67,7 @@ tools:ignore="LockedOrientationActivity" /> companion object { diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinGroupCodeActivity.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinGroupCodeActivity.kt index ef51f15f..a73d9ad5 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinGroupCodeActivity.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinGroupCodeActivity.kt @@ -23,6 +23,7 @@ class JoinGroupCodeActivity : override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + binding.joinViewModel = viewModel initLayout() addListeners() @@ -31,13 +32,12 @@ class JoinGroupCodeActivity : } private fun initLayout() { - binding.joinViewModel = viewModel - viewModel.getJoinGroupInfo(TEAM_ID) + viewModel.joinGroupInfoState(TEAM_ID) } private fun addListeners() { binding.btnJoinGroupCodeNext.setOnClickListener { - viewModel.postJoinGroupCode( + viewModel.joinGroupCodeState( TEAM_ID, RequestJoinGroupCodeEntity(viewModel.joinGroupCodeEditText.value.toString()) ) @@ -55,7 +55,7 @@ class JoinGroupCodeActivity : } private fun collectData() { - viewModel.joinGroupCodeState.flowWithLifecycle(lifecycle).onEach { uiState -> + viewModel.joinGroupInfoState.flowWithLifecycle(lifecycle).onEach { uiState -> when (uiState) { is UiState.Success -> { with(binding) { @@ -82,7 +82,7 @@ class JoinGroupCodeActivity : } }.launchIn(lifecycleScope) - viewModel.joinGroupCode.flowWithLifecycle(lifecycle).onEach { uiState -> + viewModel.joinGroupCodeState.flowWithLifecycle(lifecycle).onEach { uiState -> when (uiState) { is UiState.Success -> navigateToJoinGroupSuccess() @@ -90,7 +90,7 @@ class JoinGroupCodeActivity : PingleSnackbar.makeSnackbar( binding.root, getString(R.string.join_group_code_snackbar_message), - 97 + SNACKBAR_BOTTOM_MARGIN ) } @@ -114,5 +114,6 @@ class JoinGroupCodeActivity : const val LOADING = "Loding" const val EMPTY = "Empty" const val JOIN_GROUP_CODE_ACTIVITY = "JoinGroupCodeActivity" + const val SNACKBAR_BOTTOM_MARGIN = 97 } } diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt index 83bb4dcd..9790b9bd 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt @@ -29,16 +29,16 @@ class JoinViewModel @Inject constructor( private val _joinGroupSearchData = MutableStateFlow>(emptyList()) val joinGroupSearchData get() = _joinGroupSearchData - private val _joinGroupCodeState = + private val _joinGroupInfoState = MutableStateFlow>(UiState.Empty) - val joinGroupCodeState get() = _joinGroupCodeState.asStateFlow() + val joinGroupInfoState get() = _joinGroupInfoState.asStateFlow() private var _isJoinGroupCodeBtn = MutableLiveData(false) val isJoinGroupCodeBtn get() = _isJoinGroupCodeBtn - private var _joinGroupCode = + private var _joinGroupCodeState = MutableStateFlow>(UiState.Empty) - val joinGroupCode get() = _joinGroupCode + val joinGroupCodeState get() = _joinGroupCodeState val joinGroupCodeEditText = MutableLiveData() @@ -72,34 +72,34 @@ class JoinViewModel @Inject constructor( private fun getIsSelected(position: Int) = _joinGroupSearchData.value[position].isSelected.get() - fun getJoinGroupInfo(teamId: Int) { - _joinGroupCodeState.value = UiState.Loading + fun joinGroupInfoState(teamId: Int) { + _joinGroupInfoState.value = UiState.Loading viewModelScope.launch { - _joinGroupCodeState.value = UiState.Loading + _joinGroupInfoState.value = UiState.Loading runCatching { getJoinGroupInfoUseCase.invoke(teamId = teamId).collect { joinGroupInfo -> - _joinGroupCodeState.value = UiState.Success(joinGroupInfo) + _joinGroupInfoState.value = UiState.Success(joinGroupInfo) } }.onFailure { - _joinGroupCodeState.value = UiState.Error(it.message) + _joinGroupInfoState.value = UiState.Error(it.message) } } } - fun postJoinGroupCode(teamId: Int, code: RequestJoinGroupCodeEntity) { - _joinGroupCode.value = UiState.Loading + fun joinGroupCodeState(teamId: Int, code: RequestJoinGroupCodeEntity) { + _joinGroupCodeState.value = UiState.Loading viewModelScope.launch { runCatching { - postJoinGroupCodeUseCase.invoke(teamId = teamId, code = code) + postJoinGroupCodeUseCase(teamId = teamId, code = code) .collect { joinGroupCode -> - _joinGroupCode.value = UiState.Success(joinGroupCode) + _joinGroupCodeState.value = UiState.Success(joinGroupCode) with(localStorage) { groupId = joinGroupCode.id groupName = joinGroupCode.name } } }.onFailure { - _joinGroupCode.value = UiState.Error(it.message) + _joinGroupCodeState.value = UiState.Error(it.message) } } } From aa1b8f5065ebd6a7c935dc27249b30e873794dd2 Mon Sep 17 00:00:00 2001 From: DoReMinWoo Date: Fri, 12 Jan 2024 16:22:59 +0900 Subject: [PATCH 11/13] =?UTF-8?q?[chore]=20#98=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasource/remote/JoinGroupRemoteDataSource.kt | 2 +- .../remote/JoinGroupRemoteDataSourceImpl.kt | 9 ++++++--- .../org/sopt/pingle/data/interceptor/AuthInterceptor.kt | 2 +- .../pingle/data/repository/JoinGroupRepositoryImpl.kt | 6 +++--- .../org/sopt/pingle/data/service/JoinGroupService.kt | 2 +- .../sopt/pingle/domain/repository/JoinGroupRepository.kt | 2 +- .../pingle/domain/usecase/PostJoinGroupCodeUseCase.kt | 7 +++++-- .../pingle/presentation/ui/joingroup/JoinViewModel.kt | 2 +- 8 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupRemoteDataSource.kt b/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupRemoteDataSource.kt index efe4108f..67ce4a0d 100644 --- a/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupRemoteDataSource.kt +++ b/app/src/main/java/org/sopt/pingle/data/datasource/remote/JoinGroupRemoteDataSource.kt @@ -9,6 +9,6 @@ interface JoinGroupRemoteDataSource { suspend fun getJoinGroupInfo(teamId: Int): BaseResponse suspend fun postJoinGroupCode( teamId: Int, - code: RequestJoinGroupCodeDto + requestJoinGroupCode: RequestJoinGroupCodeDto ): BaseResponse } diff --git a/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt b/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt index 29c1c4e3..3c86e25e 100644 --- a/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt +++ b/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt @@ -1,12 +1,12 @@ package org.sopt.pingle.data.datasourceimpl.remote -import javax.inject.Inject import org.sopt.pingle.data.datasource.remote.JoinGroupRemoteDataSource import org.sopt.pingle.data.model.remote.request.RequestJoinGroupCodeDto import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupCodeDto import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupInfoDto import org.sopt.pingle.data.service.JoinGroupService import org.sopt.pingle.util.base.BaseResponse +import javax.inject.Inject class JoinGroupRemoteDataSourceImpl @Inject constructor( private val joinGroupService: JoinGroupService @@ -16,7 +16,10 @@ class JoinGroupRemoteDataSourceImpl @Inject constructor( override suspend fun postJoinGroupCode( teamId: Int, - code: RequestJoinGroupCodeDto + requestJoinGroupCode: RequestJoinGroupCodeDto ): BaseResponse = - joinGroupService.postJoinGroupCode(teamId = teamId, code = code) + joinGroupService.postJoinGroupCode( + teamId = teamId, + requestJoinGroupCode = requestJoinGroupCode + ) } diff --git a/app/src/main/java/org/sopt/pingle/data/interceptor/AuthInterceptor.kt b/app/src/main/java/org/sopt/pingle/data/interceptor/AuthInterceptor.kt index 338bc6b8..aed8ddad 100644 --- a/app/src/main/java/org/sopt/pingle/data/interceptor/AuthInterceptor.kt +++ b/app/src/main/java/org/sopt/pingle/data/interceptor/AuthInterceptor.kt @@ -1,10 +1,10 @@ package org.sopt.pingle.data.interceptor -import javax.inject.Inject import okhttp3.Interceptor import okhttp3.Request import okhttp3.Response import org.sopt.pingle.data.datasource.local.PingleLocalDataSource +import javax.inject.Inject class AuthInterceptor @Inject constructor( private val localStorage: PingleLocalDataSource diff --git a/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt b/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt index 1dfe8c53..d613d49e 100644 --- a/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt +++ b/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt @@ -1,6 +1,5 @@ package org.sopt.pingle.data.repository -import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import org.sopt.pingle.data.datasource.remote.JoinGroupRemoteDataSource @@ -9,6 +8,7 @@ import org.sopt.pingle.domain.model.JoinGroupInfoEntity import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity import org.sopt.pingle.domain.model.ResponseJoinGroupCodeEntity import org.sopt.pingle.domain.repository.JoinGroupRepository +import javax.inject.Inject class JoinGroupRepositoryImpl @Inject constructor( private val joinGroupRemoteDataSource: JoinGroupRemoteDataSource @@ -22,12 +22,12 @@ class JoinGroupRepositoryImpl @Inject constructor( override fun postJoinGroupCode( teamId: Int, - code: RequestJoinGroupCodeEntity + requestJoinGroupCode: RequestJoinGroupCodeEntity ): Flow = flow { val result = runCatching { joinGroupRemoteDataSource.postJoinGroupCode( teamId = teamId, - code = code.toRequestJoinGroupCode() + requestJoinGroupCode = requestJoinGroupCode.toRequestJoinGroupCode() ).data.toResponseJoinGroupCode() } emit(result.getOrThrow()) diff --git a/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt b/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt index 202b94a0..0dcf2f4f 100644 --- a/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt +++ b/app/src/main/java/org/sopt/pingle/data/service/JoinGroupService.kt @@ -18,7 +18,7 @@ interface JoinGroupService { @POST("$VERSION/$TEAMS/{$TEAM_ID}/$REGISTER") suspend fun postJoinGroupCode( @Path("$TEAM_ID") teamId: Int, - @Body requestJoinGroupCodeDto: RequestJoinGroupCodeDto + @Body requestJoinGroupCode: RequestJoinGroupCodeDto ): BaseResponse companion object { diff --git a/app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupRepository.kt b/app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupRepository.kt index a20b8a64..364054a9 100644 --- a/app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupRepository.kt +++ b/app/src/main/java/org/sopt/pingle/domain/repository/JoinGroupRepository.kt @@ -9,6 +9,6 @@ interface JoinGroupRepository { fun getJoinGroupInfo(teamId: Int): Flow fun postJoinGroupCode( teamId: Int, - code: RequestJoinGroupCodeEntity + requestJoinGroupCode: RequestJoinGroupCodeEntity ): Flow } diff --git a/app/src/main/java/org/sopt/pingle/domain/usecase/PostJoinGroupCodeUseCase.kt b/app/src/main/java/org/sopt/pingle/domain/usecase/PostJoinGroupCodeUseCase.kt index ff19814e..ebcf449e 100644 --- a/app/src/main/java/org/sopt/pingle/domain/usecase/PostJoinGroupCodeUseCase.kt +++ b/app/src/main/java/org/sopt/pingle/domain/usecase/PostJoinGroupCodeUseCase.kt @@ -10,7 +10,10 @@ class PostJoinGroupCodeUseCase( ) { operator fun invoke( teamId: Int, - code: RequestJoinGroupCodeEntity + requestJoinGroupCode: RequestJoinGroupCodeEntity ): Flow = - joinGroupRepository.postJoinGroupCode(teamId = teamId, code = code) + joinGroupRepository.postJoinGroupCode( + teamId = teamId, + requestJoinGroupCode = requestJoinGroupCode + ) } diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt index 9790b9bd..ad155603 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt @@ -90,7 +90,7 @@ class JoinViewModel @Inject constructor( _joinGroupCodeState.value = UiState.Loading viewModelScope.launch { runCatching { - postJoinGroupCodeUseCase(teamId = teamId, code = code) + postJoinGroupCodeUseCase(teamId = teamId, requestJoinGroupCode = code) .collect { joinGroupCode -> _joinGroupCodeState.value = UiState.Success(joinGroupCode) with(localStorage) { From bbc194895acb22da6def70af7a4b4f2200a96264 Mon Sep 17 00:00:00 2001 From: DoReMinWoo Date: Fri, 12 Jan 2024 16:23:26 +0900 Subject: [PATCH 12/13] =?UTF-8?q?[chore]=20#98=20ktlint=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt | 2 +- .../java/org/sopt/pingle/data/interceptor/AuthInterceptor.kt | 2 +- .../org/sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt b/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt index 3c86e25e..3bc8ab12 100644 --- a/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt +++ b/app/src/main/java/org/sopt/pingle/data/datasourceimpl/remote/JoinGroupRemoteDataSourceImpl.kt @@ -1,12 +1,12 @@ package org.sopt.pingle.data.datasourceimpl.remote +import javax.inject.Inject import org.sopt.pingle.data.datasource.remote.JoinGroupRemoteDataSource import org.sopt.pingle.data.model.remote.request.RequestJoinGroupCodeDto import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupCodeDto import org.sopt.pingle.data.model.remote.response.ResponseJoinGroupInfoDto import org.sopt.pingle.data.service.JoinGroupService import org.sopt.pingle.util.base.BaseResponse -import javax.inject.Inject class JoinGroupRemoteDataSourceImpl @Inject constructor( private val joinGroupService: JoinGroupService diff --git a/app/src/main/java/org/sopt/pingle/data/interceptor/AuthInterceptor.kt b/app/src/main/java/org/sopt/pingle/data/interceptor/AuthInterceptor.kt index aed8ddad..338bc6b8 100644 --- a/app/src/main/java/org/sopt/pingle/data/interceptor/AuthInterceptor.kt +++ b/app/src/main/java/org/sopt/pingle/data/interceptor/AuthInterceptor.kt @@ -1,10 +1,10 @@ package org.sopt.pingle.data.interceptor +import javax.inject.Inject import okhttp3.Interceptor import okhttp3.Request import okhttp3.Response import org.sopt.pingle.data.datasource.local.PingleLocalDataSource -import javax.inject.Inject class AuthInterceptor @Inject constructor( private val localStorage: PingleLocalDataSource diff --git a/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt b/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt index d613d49e..5beb558f 100644 --- a/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt +++ b/app/src/main/java/org/sopt/pingle/data/repository/JoinGroupRepositoryImpl.kt @@ -1,5 +1,6 @@ package org.sopt.pingle.data.repository +import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import org.sopt.pingle.data.datasource.remote.JoinGroupRemoteDataSource @@ -8,7 +9,6 @@ import org.sopt.pingle.domain.model.JoinGroupInfoEntity import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity import org.sopt.pingle.domain.model.ResponseJoinGroupCodeEntity import org.sopt.pingle.domain.repository.JoinGroupRepository -import javax.inject.Inject class JoinGroupRepositoryImpl @Inject constructor( private val joinGroupRemoteDataSource: JoinGroupRemoteDataSource From 7677a515ba130fd27b7c8e1d529e001af3060a77 Mon Sep 17 00:00:00 2001 From: DoReMinWoo Date: Fri, 12 Jan 2024 16:29:44 +0900 Subject: [PATCH 13/13] =?UTF-8?q?[chore]=20#98=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt index ad155603..cab14b76 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/joingroup/JoinViewModel.kt @@ -77,7 +77,7 @@ class JoinViewModel @Inject constructor( viewModelScope.launch { _joinGroupInfoState.value = UiState.Loading runCatching { - getJoinGroupInfoUseCase.invoke(teamId = teamId).collect { joinGroupInfo -> + getJoinGroupInfoUseCase(teamId = teamId).collect { joinGroupInfo -> _joinGroupInfoState.value = UiState.Success(joinGroupInfo) } }.onFailure {