Skip to content

Commit

Permalink
Merge branch 'develop' into feat-more-api-connection
Browse files Browse the repository at this point in the history
  • Loading branch information
jihyunniiii committed Jan 12, 2024
2 parents 9e5ec39 + d21cc7d commit 5e894ce
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 81 deletions.
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
tools:targetApi="31">
<activity
android:name=".presentation.ui.splash.SplashActivity"
android:theme="@style/Theme.Pingle.Splash"
android:exported="true"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" >
android:theme="@style/Theme.Pingle.Splash"
tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down Expand Up @@ -72,7 +72,7 @@
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".presentation.ui.joingroup.JoinGroupSearchActivity"
android:exported="false"
android:exported="true"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ 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.data.model.remote.response.ResponseJoinGroupSearchDto
import org.sopt.pingle.util.base.BaseResponse

interface JoinGroupRemoteDataSource {
suspend fun getJoinGroupSearch(teamName: String): BaseResponse<List<ResponseJoinGroupSearchDto>>
suspend fun getJoinGroupInfo(teamId: Int): BaseResponse<ResponseJoinGroupInfoDto>
suspend fun postJoinGroupCode(
teamId: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ 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.model.remote.response.ResponseJoinGroupSearchDto
import org.sopt.pingle.data.service.JoinGroupService
import org.sopt.pingle.util.base.BaseResponse

class JoinGroupRemoteDataSourceImpl @Inject constructor(
private val joinGroupService: JoinGroupService
) : JoinGroupRemoteDataSource {
override suspend fun getJoinGroupSearch(teamName: String): BaseResponse<List<ResponseJoinGroupSearchDto>> =
joinGroupService.getJoinGroupSearch(teamName = teamName)

override suspend fun getJoinGroupInfo(teamId: Int): BaseResponse<ResponseJoinGroupInfoDto> =
joinGroupService.getJoinGroupInfo(teamId = teamId)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
package org.sopt.pingle.data.model.remote.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.sopt.pingle.domain.model.JoinGroupSearchEntity

@Serializable
data class ResponseJoinGroupSearchDto(
@SerialName("code")
val code: Int,
@SerialName("code")
val message: String,
@SerialName("code")
val data: List<Data>
@SerialName("id")
val id: Int,
@SerialName("name")
val name: String,
@SerialName("keyword")
val keyword: String
) {
data class Data(
@SerialName("code")
val id: Int,
@SerialName("code")
val name: String,
@SerialName("code")
val keyword: String
) {
fun toJoinGroupSearchEntity() = JoinGroupSearchEntity(
id = this.id,
keyword = this.keyword,
name = this.name
)
}
fun toJoinGroupSearchEntity() = JoinGroupSearchEntity(
id = this.id,
keyword = this.keyword,
name = this.name
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@ 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.JoinGroupSearchEntity
import org.sopt.pingle.domain.model.RequestJoinGroupCodeEntity
import org.sopt.pingle.domain.model.ResponseJoinGroupCodeEntity
import org.sopt.pingle.domain.repository.JoinGroupRepository

class JoinGroupRepositoryImpl @Inject constructor(
private val joinGroupRemoteDataSource: JoinGroupRemoteDataSource
) : JoinGroupRepository {
override fun getJoinGroupSearch(teamName: String): Flow<List<JoinGroupSearchEntity>> = flow {
val result = runCatching {
joinGroupRemoteDataSource.getJoinGroupSearch(teamName = teamName).data.map { joinGroupSearch ->
joinGroupSearch.toJoinGroupSearchEntity()
}
}
emit(result.getOrThrow())
}

override fun getJoinGroupInfo(teamId: Int): Flow<JoinGroupInfoEntity> = flow {
val result = runCatching {
joinGroupRemoteDataSource.getJoinGroupInfo(teamId = teamId).data.toJoinGroupCodeEntity()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ 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.data.model.remote.response.ResponseJoinGroupSearchDto
import org.sopt.pingle.util.base.BaseResponse
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

interface JoinGroupService {
@GET("$VERSION/$TEAMS")
suspend fun getJoinGroupSearch(
@Query("$NAME") teamName: String
): BaseResponse<List<ResponseJoinGroupSearchDto>>

@GET("$VERSION/$TEAMS/{$TEAM_ID}")
suspend fun getJoinGroupInfo(
@Path("$TEAM_ID") teamId: Int
Expand All @@ -24,6 +31,7 @@ interface JoinGroupService {
companion object {
const val VERSION = "v1"
const val TEAMS = "teams"
const val NAME = "name"
const val TEAM_ID = "teamId"
const val REGISTER = "register"
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/org/sopt/pingle/di/UseCaseModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.sopt.pingle.domain.repository.PlanMeetingRepository
import org.sopt.pingle.domain.repository.PlanRepository
import org.sopt.pingle.domain.usecase.GetDummyUserListUseCase
import org.sopt.pingle.domain.usecase.GetJoinGroupInfoUseCase
import org.sopt.pingle.domain.usecase.GetJoinGroupSearchUseCase
import org.sopt.pingle.domain.usecase.GetPinListWithoutFilteringUseCase
import org.sopt.pingle.domain.usecase.GetPingleListUseCase
import org.sopt.pingle.domain.usecase.GetPlanLocationListUseCase
Expand Down Expand Up @@ -67,6 +68,11 @@ class UseCaseModule {
fun providesPostPlanMeetingUseCase(planMeetingRepository: PlanMeetingRepository): PostPlanMeetingUseCase =
PostPlanMeetingUseCase(planMeetingRepository = planMeetingRepository)

@Provides
@Singleton
fun providesGetJoinGroupSearchUseCase(joinGroupRepository: JoinGroupRepository): GetJoinGroupSearchUseCase =
GetJoinGroupSearchUseCase(joinGroupRepository = joinGroupRepository)

@Provides
@Singleton
fun providesGetJoinGroupInfoUseCase(joinGroupRepository: JoinGroupRepository): GetJoinGroupInfoUseCase =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package org.sopt.pingle.domain.repository

import kotlinx.coroutines.flow.Flow
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

interface JoinGroupRepository {
fun getJoinGroupSearch(teamName: String): Flow<List<JoinGroupSearchEntity>>
fun getJoinGroupInfo(teamId: Int): Flow<JoinGroupInfoEntity>
fun postJoinGroupCode(
teamId: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sopt.pingle.domain.usecase

import kotlinx.coroutines.flow.Flow
import org.sopt.pingle.domain.model.JoinGroupSearchEntity
import org.sopt.pingle.domain.repository.JoinGroupRepository

class GetJoinGroupSearchUseCase(
private val joinGroupRepository: JoinGroupRepository
) {
operator fun invoke(teamName: String): Flow<List<JoinGroupSearchEntity>> =
joinGroupRepository.getJoinGroupSearch(teamName = teamName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import timber.log.Timber
class JoinGroupCodeActivity :
BindingActivity<ActivityJoinGroupCodeBinding>(R.layout.activity_join_group_code) {
private val viewModel by viewModels<JoinViewModel>()
private var teamId = -1

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -32,13 +33,14 @@ class JoinGroupCodeActivity :
}

private fun initLayout() {
viewModel.joinGroupInfoState(TEAM_ID)
teamId = intent.getIntExtra(TEAM_ID, -1)
viewModel.joinGroupInfoState(teamId)
}

private fun addListeners() {
binding.btnJoinGroupCodeNext.setOnClickListener {
viewModel.joinGroupCodeState(
TEAM_ID,
teamId,
RequestJoinGroupCodeEntity(viewModel.joinGroupCodeEditText.value.toString())
)
}
Expand Down Expand Up @@ -109,8 +111,8 @@ class JoinGroupCodeActivity :
}

companion object {
const val TEAM_ID = "teamId"
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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package org.sopt.pingle.presentation.ui.joingroup
import android.content.Intent
import android.os.Bundle
import android.view.KeyEvent
import android.view.View
import androidx.activity.viewModels
import androidx.core.view.isVisible
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
Expand All @@ -15,19 +16,23 @@ import org.sopt.pingle.presentation.ui.onboarding.OnBoardingActivity
import org.sopt.pingle.util.base.BindingActivity
import org.sopt.pingle.util.context.hideKeyboard
import org.sopt.pingle.util.context.navigateToWebView
import org.sopt.pingle.util.view.UiState
import timber.log.Timber

@AndroidEntryPoint
class JoinGroupSearchActivity :
BindingActivity<ActivityJoinGroupSearchBinding>(R.layout.activity_join_group_search) {
private val viewModel by viewModels<JoinViewModel>()
private lateinit var joinGroupSearchAdapter: JoinGroupSearchAdapter
private var teamId = -1

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.joinViewModel = viewModel

initLayout()
addListeners()
addObservers()
collectData()
}

private fun initLayout() {
Expand All @@ -36,22 +41,26 @@ class JoinGroupSearchActivity :
}

private fun addListeners() {
binding.includeJoinGroupSearchTopbar.ivAllTopbarArrowWithTitleArrowLeft.setOnClickListener {
finish()
}

binding.root.setOnClickListener {
hideKeyboard(binding.etJoinGroupSearch)
}

binding.ivJoinGroupSearchIcon.setOnClickListener {
// TODO 서버통신 함수 호출
viewModel.joinGroupSearchState(binding.etJoinGroupSearch.text.toString())
hideKeyboard(binding.etJoinGroupSearch)
}

binding.etJoinGroupSearch.setOnKeyListener { v, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_DOWN) {
// TODO 서버통신 함수 호출
viewModel.joinGroupSearchState(binding.etJoinGroupSearch.text.toString())
hideKeyboard(binding.etJoinGroupSearch)
return@setOnKeyListener true
}
true
false
}

binding.tvJoinGroupSearchCreate.setOnClickListener {
Expand All @@ -61,22 +70,36 @@ class JoinGroupSearchActivity :
binding.btnJoinGroupCodeNext.setOnClickListener {
navigateToJoinGroupCode()
}

binding.includeJoinGroupSearchTopbar.ivAllTopbarArrowWithTitleArrowLeft.setOnClickListener {
finish()
}
}

private fun addObservers() {
viewModel.joinGroupSearchData.flowWithLifecycle(lifecycle).onEach { joinGroupSearchList ->
// TODO 서버통신 시 옵저빙 체크
joinGroupSearchAdapter.submitList(joinGroupSearchList)

binding.tvJoinGroupSearchEmpty.isVisible = joinGroupSearchList.isEmpty()
private fun collectData() {
viewModel.joinGroupSearchState.flowWithLifecycle(lifecycle).onEach { uiState ->
when (uiState) {
is UiState.Success -> {
joinGroupSearchAdapter.submitList(uiState.data)
joinGroupSearchAdapter.currentList
binding.tvJoinGroupSearchEmpty.visibility = View.INVISIBLE
}

is UiState.Error -> Timber.tag(JoinGroupCodeActivity.JOIN_GROUP_CODE_ACTIVITY)
.d(uiState.message)

is UiState.Loading -> Timber.tag(JoinGroupCodeActivity.JOIN_GROUP_CODE_ACTIVITY).d(
JoinGroupCodeActivity.LOADING
)

is UiState.Empty -> {
joinGroupSearchAdapter.submitList(null)
binding.tvJoinGroupSearchEmpty.visibility = View.VISIBLE
}
}
}.launchIn(lifecycleScope)

viewModel.selectedJoinGroup.flowWithLifecycle(lifecycle).onEach { selectedJoinGroup ->
binding.btnJoinGroupCodeNext.isEnabled = selectedJoinGroup != null
if (selectedJoinGroup != null) {
teamId = selectedJoinGroup.id
}
}.launchIn(lifecycleScope)
}

Expand All @@ -86,6 +109,7 @@ class JoinGroupSearchActivity :

private fun navigateToJoinGroupCode() {
Intent(this, JoinGroupCodeActivity::class.java).apply {
putExtra(TEAM_ID, teamId)
startActivity(this)
}
}
Expand All @@ -94,4 +118,8 @@ class JoinGroupSearchActivity :
binding.rvJoinGroupSearch.adapter = null
super.onDestroy()
}

companion object {
const val TEAM_ID = "teamId"
}
}
Loading

0 comments on commit 5e894ce

Please sign in to comment.