-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT/#77] 초대 코드 검증 API #82
Changes from 11 commits
75c7ee0
3512c7c
bccf9f0
e73da87
2d4b428
6d804ef
97e2714
a961e65
9423802
e7f32c7
16cb5b7
e537087
5120489
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.going.data.datasource; | ||
|
||
import com.going.data.dto.BaseResponse | ||
import com.going.data.dto.request.EnterTripRequestDto | ||
import com.going.data.dto.response.EnterTripResponseDto | ||
|
||
interface EnterTripDataSource { | ||
suspend fun postEnterTrip( | ||
code: EnterTripRequestDto, | ||
): BaseResponse<EnterTripResponseDto> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.going.data.datasourceImpl | ||
|
||
import com.going.data.datasource.EnterTripDataSource | ||
import com.going.data.dto.BaseResponse | ||
import com.going.data.dto.request.EnterTripRequestDto | ||
import com.going.data.dto.response.EnterTripResponseDto | ||
import com.going.data.service.EnterTripService | ||
import javax.inject.Inject | ||
|
||
class EnterTripDataSourceImpl @Inject constructor( | ||
private val enterTripService: EnterTripService, | ||
) : EnterTripDataSource { | ||
override suspend fun postEnterTrip( | ||
code: EnterTripRequestDto | ||
): BaseResponse<EnterTripResponseDto> = | ||
enterTripService.postEnterTrip(code) | ||
|
||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 공백...ㅎㅎㅎ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.going.data.dto.request | ||
|
||
import com.going.domain.entity.request.RequestEnterTripModel | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class EnterTripRequestDto( | ||
@SerialName("code") | ||
val code: String, | ||
) | ||
|
||
fun RequestEnterTripModel.toEnterTripRequestDto(): EnterTripRequestDto = | ||
EnterTripRequestDto(code) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.going.data.dto.response | ||
|
||
import com.going.domain.entity.response.EnterTripModel | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class EnterTripResponseDto( | ||
@SerialName("tripId") | ||
val tripId: Long, | ||
@SerialName("title") | ||
val title: String, | ||
@SerialName("startDate") | ||
val startDate: String, | ||
@SerialName("endDate") | ||
val endDate: String, | ||
@SerialName("day") | ||
val day: Int, | ||
) { | ||
fun toEnterTripModel() = | ||
EnterTripModel(tripId, title, startDate, endDate, day) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.going.data.repositoryImpl | ||
|
||
import com.going.data.datasource.EnterTripDataSource | ||
import com.going.data.dto.request.toEnterTripRequestDto | ||
import com.going.domain.entity.request.RequestEnterTripModel | ||
import com.going.domain.entity.response.EnterTripModel | ||
import com.going.domain.repository.EnterTripRepository | ||
import javax.inject.Inject | ||
|
||
class EnterTripRepositoryImpl @Inject constructor( | ||
private val enterTripDataSource: EnterTripDataSource, | ||
) : EnterTripRepository { | ||
|
||
override suspend fun postEnterTrip( | ||
requestEnterTripModel: RequestEnterTripModel | ||
): Result<EnterTripModel?> = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? 없애도 돌릴 수 있을 것 같아요 ~ |
||
runCatching { | ||
enterTripDataSource.postEnterTrip( | ||
requestEnterTripModel.toEnterTripRequestDto(), | ||
).data?.toEnterTripModel() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.going.data.service | ||
|
||
import com.going.data.dto.BaseResponse | ||
import com.going.data.dto.request.EnterTripRequestDto | ||
import com.going.data.dto.response.EnterTripResponseDto | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface EnterTripService { | ||
@POST("/api/trips/verify") | ||
suspend fun postEnterTrip( | ||
@Body body: EnterTripRequestDto, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 통일성을 위해서 request로 갑시당 ~ |
||
): BaseResponse<EnterTripResponseDto> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.going.domain.entity.request | ||
|
||
data class RequestEnterTripModel( | ||
val code: String | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 진짜 사소할 수 있는 네이밍 통일인데, ~RequestModel, ~Model, ~RequestDto, ~ResponseDto 로 갑시다 ! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.going.domain.entity.response | ||
|
||
data class EnterTripModel( | ||
val tripId: Long, | ||
val title: String, | ||
val startDate: String, | ||
val endDate: String, | ||
val day: Int | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.going.domain.repository | ||
|
||
import com.going.domain.entity.request.RequestEnterTripModel | ||
import com.going.domain.entity.response.EnterTripModel | ||
|
||
interface EnterTripRepository { | ||
|
||
suspend fun postEnterTrip( | ||
requestEnterTripModel: RequestEnterTripModel | ||
): Result<EnterTripModel?> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 같이 ? 빼주세요 ~ |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,27 +2,37 @@ package com.going.presentation.enter.entertrip | |
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.util.Log | ||
import android.widget.TextView | ||
import androidx.activity.viewModels | ||
import androidx.core.content.res.ResourcesCompat | ||
import androidx.lifecycle.flowWithLifecycle | ||
import androidx.lifecycle.lifecycleScope | ||
import com.going.domain.entity.CodeState | ||
import com.going.presentation.R | ||
import com.going.presentation.databinding.ActivityEnterTripBinding | ||
import com.going.presentation.enter.invitefinish.InviteFinishActivity | ||
import com.going.presentation.starttrip.StartTripSplashActivity | ||
import com.going.ui.base.BaseActivity | ||
import com.going.ui.extension.UiState | ||
import com.going.ui.extension.setOnSingleClickListener | ||
import com.going.ui.extension.toast | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
|
||
@AndroidEntryPoint | ||
class EnterTripActivity : BaseActivity<ActivityEnterTripBinding>(R.layout.activity_enter_trip) { | ||
private val viewModel by viewModels<EnterTripViewModel>() | ||
|
||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
initBackBtnClickListener() | ||
initBindingViewModel() | ||
observeIsCodeAvailable() | ||
initNextBtnClickListener() | ||
observeEnterTripState() | ||
|
||
|
||
} | ||
|
@@ -76,9 +86,36 @@ class EnterTripActivity : BaseActivity<ActivityEnterTripBinding>(R.layout.activi | |
counter.setTextColor(getColor(color)) | ||
} | ||
|
||
|
||
private fun observeEnterTripState() { | ||
viewModel.tripState.flowWithLifecycle(lifecycle).onEach { state -> | ||
when (state) { | ||
is UiState.Success -> { | ||
|
||
Intent(this, InviteFinishActivity::class.java).apply { | ||
putExtra("title", state.data.title) | ||
putExtra("start", state.data.startDate) | ||
putExtra("end", state.data.endDate) | ||
putExtra("day", state.data.day) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 엑스트라를 인텐트로 옮기는 과정에서는 키값을 한 곳에서 보관해주시는 것이 좋습니다! 예시 :
|
||
Log.d("day1", state.data.day.toString()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 로그 ! |
||
startActivity(this) | ||
} | ||
} | ||
|
||
is UiState.Failure -> { | ||
toast(getString(R.string.server_error)) | ||
} | ||
|
||
is UiState.Loading -> return@onEach | ||
|
||
is UiState.Empty -> return@onEach | ||
} | ||
}.launchIn(lifecycleScope) | ||
} | ||
|
||
private fun initNextBtnClickListener() { | ||
binding.btnEnterTripNext.setOnSingleClickListener { | ||
//다음 뷰로 이동 | ||
viewModel.checkInviteCodeFromServer() | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,25 @@ package com.going.presentation.enter.entertrip | |
|
||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.going.domain.entity.CodeState | ||
import com.going.domain.entity.request.RequestEnterTripModel | ||
import com.going.domain.entity.response.EnterTripModel | ||
import com.going.domain.repository.EnterTripRepository | ||
import com.going.ui.extension.UiState | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.launch | ||
import java.util.regex.Pattern | ||
import javax.inject.Inject | ||
|
||
class EnterTripViewModel : ViewModel() { | ||
@HiltViewModel | ||
class EnterTripViewModel @Inject constructor( | ||
private val enterTripRepository: EnterTripRepository | ||
) : ViewModel() { | ||
private val _tripState = MutableStateFlow<UiState<EnterTripModel>>(UiState.Empty) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 줄바꿈하면 예쁠듯 ㅋㅋ |
||
val tripState: StateFlow<UiState<EnterTripModel>> = _tripState | ||
|
||
val inviteCode = MutableLiveData<String>() | ||
var codeLength = MutableLiveData(0) | ||
|
@@ -31,6 +46,18 @@ class EnterTripViewModel : ViewModel() { | |
isCheckEnterAvailable.value = isCodeAvailable.value == CodeState.Success | ||
} | ||
|
||
fun checkInviteCodeFromServer() { | ||
_tripState.value = UiState.Loading | ||
viewModelScope.launch { | ||
enterTripRepository.postEnterTrip( | ||
RequestEnterTripModel(inviteCode.value ?: "") | ||
).onSuccess { result -> | ||
_tripState.value = result?.let { UiState.Success(it) } ?: UiState.Failure("no") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앞에 애들에서 ?를 제외해서 보내게 된다면, 뷰모델에서 null값에 대해서 예외처리를 진행하지 않고도 편하게 사용 가능합니다~ |
||
}.onFailure { | ||
_tripState.value = UiState.Failure(it.message.orEmpty()) | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
private const val ENG_NUM_PATTERN = "^[a-z0-9]*$" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code 라고 값만 작성하시면, 서비스에서 서버통신을 진행할 때 requestDto가 아니라 Path나 Query같은 파라미터 값으로 혼동될 수 있기 때문에 파라미터 값을 이왕이면 request로 작성하는 것이 더 좋을 듯 합니다