Skip to content
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/#141] 서버 점검중 노티 API 구현 #142

Merged
merged 7 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kr.genti.data.dto.request.ReportRequestDto
import kr.genti.data.dto.response.GenerateStatusDto
import kr.genti.data.dto.response.OpenchatDto
import kr.genti.data.dto.response.PicturePagedListDto
import kr.genti.data.dto.response.ServerAvailableDto

interface GenerateDataSource {
suspend fun getGenerateStatus(): BaseResponse<GenerateStatusDto>
Expand All @@ -30,4 +31,6 @@ interface GenerateDataSource {
suspend fun getOpenchatData(): BaseResponse<OpenchatDto>

suspend fun getIsUserVerified(): BaseResponse<Boolean>

suspend fun getIsServerAvailable(): BaseResponse<ServerAvailableDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kr.genti.data.dto.request.ReportRequestDto
import kr.genti.data.dto.response.GenerateStatusDto
import kr.genti.data.dto.response.OpenchatDto
import kr.genti.data.dto.response.PicturePagedListDto
import kr.genti.data.dto.response.ServerAvailableDto
import kr.genti.data.service.GenerateService
import javax.inject.Inject

Expand Down Expand Up @@ -39,4 +40,6 @@ data class GenerateDataSourceImpl
override suspend fun getOpenchatData(): BaseResponse<OpenchatDto> = generateService.getOpenchatData()

override suspend fun getIsUserVerified(): BaseResponse<Boolean> = generateService.getIsUserVerified()

override suspend fun getIsServerAvailable(): BaseResponse<ServerAvailableDto> = generateService.getIsServerAvailable()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package kr.genti.data.dto.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kr.genti.domain.entity.response.ServerAvailableModel

@Serializable
data class ServerAvailableDto(
@SerialName("status")
val status: Boolean,
@SerialName("message")
val message: String?,
) {
fun toModel() = ServerAvailableModel(status, message)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kr.genti.domain.entity.request.ReportRequestModel
import kr.genti.domain.entity.response.GenerateStatusModel
import kr.genti.domain.entity.response.OpenchatModel
import kr.genti.domain.entity.response.PicturePagedListModel
import kr.genti.domain.entity.response.ServerAvailableModel
import kr.genti.domain.repository.GenerateRepository
import javax.inject.Inject

Expand Down Expand Up @@ -68,4 +69,9 @@ class GenerateRepositoryImpl
runCatching {
generateDataSource.getIsUserVerified().response
}

override suspend fun getIsServerAvailable(): Result<ServerAvailableModel> =
runCatching {
generateDataSource.getIsServerAvailable().response.toModel()
}
}
4 changes: 4 additions & 0 deletions data/src/main/java/kr/genti/data/service/GenerateService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kr.genti.data.dto.request.ReportRequestDto
import kr.genti.data.dto.response.GenerateStatusDto
import kr.genti.data.dto.response.OpenchatDto
import kr.genti.data.dto.response.PicturePagedListDto
import kr.genti.data.dto.response.ServerAvailableDto
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
Expand Down Expand Up @@ -49,4 +50,7 @@ interface GenerateService {

@GET("api/v1/user-verification")
suspend fun getIsUserVerified(): BaseResponse<Boolean>

@GET("api/v1/maintenance")
suspend fun getIsServerAvailable(): BaseResponse<ServerAvailableDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package kr.genti.domain.entity.response

data class ServerAvailableModel(
val status: Boolean,
val message: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kr.genti.domain.entity.request.ReportRequestModel
import kr.genti.domain.entity.response.GenerateStatusModel
import kr.genti.domain.entity.response.OpenchatModel
import kr.genti.domain.entity.response.PicturePagedListModel
import kr.genti.domain.entity.response.ServerAvailableModel

interface GenerateRepository {
suspend fun getGenerateStatus(): Result<GenerateStatusModel>
Expand All @@ -29,4 +30,6 @@ interface GenerateRepository {
suspend fun getOpenchatData(): Result<OpenchatModel>

suspend fun getIsUserVerified(): Result<Boolean>

suspend fun getIsServerAvailable(): Result<ServerAvailableModel>
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import kr.genti.core.extension.setOnSingleClickListener
import kr.genti.core.extension.stringOf
import kr.genti.core.extension.toast
import kr.genti.presentation.R
import kr.genti.presentation.databinding.DialogWaitingErrorBinding
import kr.genti.presentation.databinding.DialogCreateErrorBinding

class CreateErrorDialog : BaseDialog<DialogWaitingErrorBinding>(R.layout.dialog_waiting_error) {
class CreateErrorDialog : BaseDialog<DialogCreateErrorBinding>(R.layout.dialog_create_error) {
private val viewModel by activityViewModels<MainViewModel>()

override fun onStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import kr.genti.core.extension.setOnSingleClickListener
import kr.genti.core.extension.stringOf
import kr.genti.core.extension.toast
import kr.genti.presentation.R
import kr.genti.presentation.databinding.DialogMainFinishedBinding
import kr.genti.presentation.databinding.DialogCreateFinishedBinding
import kr.genti.presentation.generate.finished.FinishedActivity

class CreateFinishedDialog : BaseDialog<DialogMainFinishedBinding>(R.layout.dialog_main_finished) {
class CreateFinishedDialog : BaseDialog<DialogCreateFinishedBinding>(R.layout.dialog_create_finished) {
private val viewModel by activityViewModels<MainViewModel>()

override fun onStart() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package kr.genti.presentation.main

import android.os.Bundle
import android.view.View
import android.view.WindowManager
import kr.genti.core.base.BaseDialog
import kr.genti.core.extension.setOnSingleClickListener
import kr.genti.presentation.R
import kr.genti.presentation.databinding.DialogCreateUnableBinding

class CreateUnableDialog : BaseDialog<DialogCreateUnableBinding>(R.layout.dialog_create_unable) {
override fun onStart() {
super.onStart()
dialog?.window?.apply {
setLayout(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
)
setBackgroundDrawableResource(R.color.transparent)
}
}

override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
) {
super.onViewCreated(view, savedInstanceState)

initCloseBtnListener()
setBodyText()
}

private fun initCloseBtnListener() {
binding.btnClose.setOnSingleClickListener { dismiss() }
binding.btnReturn.setOnSingleClickListener { dismiss() }
}

private fun setBodyText() {
binding.tvLogoutSubtitle.text = arguments?.getString(ARG_BODY)
binding.tvLogoutSubtitle.invalidate()
}

companion object {
private const val ARG_BODY = "ARG_BODY"

@JvmStatic
fun newInstance(body: String): CreateUnableDialog =
CreateUnableDialog().apply {
arguments =
Bundle().apply {
putString(ARG_BODY, body)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(R.layout.activity_main) {

private var createFinishedDialog: CreateFinishedDialog? = null
private var createErrorDialog: CreateErrorDialog? = null
private var createUnableDialog: CreateUnableDialog? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -49,6 +50,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(R.layout.activity_main) {
observeStatusResult()
observeNotificationState()
observeResetResult()
observeServerAvailableState()
observeUserVerifyState()
}

Expand Down Expand Up @@ -112,7 +114,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(R.layout.activity_main) {
private fun navigateByGenerateStatus() {
when (viewModel.currentStatus) {
GenerateStatus.NEW_REQUEST_AVAILABLE -> {
viewModel.getIsUserVerifiedFromServer()
viewModel.getIsServerAvailable()
}

GenerateStatus.AWAIT_USER_VERIFICATION -> {
Expand Down Expand Up @@ -199,6 +201,27 @@ class MainActivity : BaseActivity<ActivityMainBinding>(R.layout.activity_main) {
}.launchIn(lifecycleScope)
}

private fun observeServerAvailableState() {
viewModel.serverAvailableState
.flowWithLifecycle(lifecycle)
.onEach { state ->
when (state) {
is UiState.Success -> {
if (state.data.status) {
viewModel.getIsUserVerifiedFromServer()
} else {
createUnableDialog = CreateUnableDialog.newInstance(state.data.message.orEmpty())
createUnableDialog?.show(supportFragmentManager, DIALOG_UNABLE)
}
}

is UiState.Failure -> toast(stringOf(R.string.error_msg))
else -> return@onEach
}
viewModel.resetIsUserVerified()
}.launchIn(lifecycleScope)
}

private fun observeUserVerifyState() {
viewModel.userVerifyState
.flowWithLifecycle(lifecycle)
Expand Down Expand Up @@ -236,13 +259,16 @@ class MainActivity : BaseActivity<ActivityMainBinding>(R.layout.activity_main) {

override fun onDestroy() {
super.onDestroy()

createFinishedDialog = null
createErrorDialog = null
createUnableDialog = null
}

companion object {
private const val DIALOG_FINISHED = "DIALOG_FINISHED"
private const val DIALOG_ERROR = "DIALOG_ERROR"
private const val DIALOG_UNABLE = "DIALOG_UNABLE"

const val TYPE_SUCCESS = "SUCCESS"
const val TYPE_CANCELED = "CANCELED"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import kr.genti.core.state.UiState
import kr.genti.domain.entity.response.GenerateStatusModel
import kr.genti.domain.entity.response.ServerAvailableModel
import kr.genti.domain.enums.GenerateStatus
import kr.genti.domain.repository.GenerateRepository
import javax.inject.Inject
Expand All @@ -29,6 +30,10 @@ class MainViewModel
private val _notificationState = MutableStateFlow(GenerateStatus.EMPTY)
val notificationState: StateFlow<GenerateStatus> = _notificationState

private val _serverAvailableState =
MutableStateFlow<UiState<ServerAvailableModel>>(UiState.Empty)
val serverAvailableState: StateFlow<UiState<ServerAvailableModel>> = _serverAvailableState

private val _userVerifyState = MutableStateFlow<UiState<Boolean>>(UiState.Empty)
val userVerifyState: StateFlow<UiState<Boolean>> = _userVerifyState

Expand Down Expand Up @@ -73,6 +78,19 @@ class MainViewModel

fun checkNewPictureInitialized() = ::newPicture.isInitialized

fun getIsServerAvailable() {
_serverAvailableState.value = UiState.Loading
viewModelScope.launch {
generateRepository
.getIsServerAvailable()
.onSuccess {
_serverAvailableState.value = UiState.Success(it)
}.onFailure {
_serverAvailableState.value = UiState.Failure(it.message.orEmpty())
}
}
}

fun getIsUserVerifiedFromServer() {
_userVerifyState.value = UiState.Loading
viewModelScope.launch {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="14dp"/>
<solid android:color="@color/white" />
<solid android:color="@color/background_white" />
</shape>
18 changes: 10 additions & 8 deletions presentation/src/main/res/layout/activity_verify.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:gravity="center"
android:textSize="22dp"
android:lineSpacingMultiplier="1.1"
android:text="@string/verify_before_tv_title"
android:textColor="@color/white"
Expand All @@ -65,7 +66,7 @@
android:gravity="center"
android:text="@string/verify_before_tv_subtitle"
android:textColor="#99FFFFFF"
android:textSize="13sp"
android:textSize="13dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_before_verify_title" />
Expand All @@ -78,7 +79,7 @@
android:gravity="center"
android:text="@string/verify_before_tv_baby"
android:textColor="#4DFFFFFF"
android:textSize="13sp"
android:textSize="13dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_before_verify_subtitle" />
Expand Down Expand Up @@ -116,7 +117,7 @@
android:paddingVertical="14dp"
android:text="@string/verify_before_btn_photo"
android:textColor="#0D2D2B"
android:textSize="16sp"
android:textSize="16dp"
app:layout_constraintBottom_toTopOf="@id/tv_before_verify_warning"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Expand All @@ -130,7 +131,7 @@
android:gravity="center"
android:text="@string/verify_before_tv_warning"
android:textColor="#4DFFFFFF"
android:textSize="12sp"
android:textSize="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Expand All @@ -153,6 +154,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:textSize="22dp"
android:gravity="center"
android:lineSpacingMultiplier="1.1"
android:text="@string/verify_after_tv_title"
Expand All @@ -170,7 +172,7 @@
android:gravity="center"
android:text="@string/verify_after_tv_subtitle"
android:textColor="#99FFFFFF"
android:textSize="13sp"
android:textSize="13dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_after_verify_title" />
Expand Down Expand Up @@ -208,7 +210,7 @@
android:gravity="center"
android:text="@string/verify_after_tv_guide"
android:textColor="@color/green_new"
android:textSize="13sp"
android:textSize="13dp"
app:layout_constraintBottom_toBottomOf="@id/iv_photo_taken"
app:layout_constraintEnd_toEndOf="@id/iv_photo_taken"
app:layout_constraintStart_toStartOf="@id/iv_photo_taken" />
Expand All @@ -225,7 +227,7 @@
android:paddingVertical="14dp"
android:text="@string/verify_after_btn_retake"
android:textColor="#0D2D2B"
android:textSize="16sp"
android:textSize="16dp"
app:layout_constraintBottom_toTopOf="@id/btn_verify"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Expand All @@ -242,7 +244,7 @@
android:paddingVertical="14dp"
android:text="@string/verify_after_btn_verify"
android:textColor="#0D2D2B"
android:textSize="16sp"
android:textSize="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Expand Down
Loading
Loading